Skip to content

Commit 93c80de

Browse files
committed
Update integration test for generic extraction.
1 parent 5ce5ca5 commit 93c80de

34 files changed

+2976
-741
lines changed

mp2-common/src/eth.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use anyhow::{bail, Result};
1212
use eth_trie::{EthTrie, MemoryDB, Trie};
1313
use ethereum_types::H256;
1414
use itertools::Itertools;
15+
use log::debug;
1516
use log::warn;
1617
use rlp::Rlp;
1718
use serde::{Deserialize, Serialize};
@@ -214,6 +215,10 @@ impl StorageSlot {
214215
.checked_add(U256::from(*evm_offset))
215216
.unwrap()
216217
.to_be_bytes();
218+
debug!(
219+
"Storage slot struct: parent_location = {}, evm_offset = {}",
220+
parent_location, evm_offset,
221+
);
217222
B256::from_slice(&location)
218223
}
219224
}
@@ -237,6 +242,9 @@ impl StorageSlot {
237242
}
238243
}
239244
impl ProofQuery {
245+
pub fn new(contract: Address, slot: StorageSlot) -> Self {
246+
Self { contract, slot }
247+
}
240248
pub fn new_simple_slot(address: Address, slot: usize) -> Self {
241249
Self {
242250
contract: address,
@@ -256,8 +264,14 @@ impl ProofQuery {
256264
) -> Result<EIP1186AccountProofResponse> {
257265
// Query the MPT proof with retries.
258266
for i in 0..RETRY_NUM {
267+
let location = self.slot.location();
268+
debug!(
269+
"Querying MPT proof:\n\tslot = {:?}, location = {:?}",
270+
self.slot,
271+
U256::from_be_slice(location.as_slice()),
272+
);
259273
match provider
260-
.get_proof(self.contract, vec![self.slot.location()])
274+
.get_proof(self.contract, vec![location])
261275
.block_id(block.into())
262276
.await
263277
{

mp2-common/src/types.rs

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ impl From<HashOut<F>> for HashOutput {
112112
}
113113
}
114114

115+
impl From<&HashOut<F>> for HashOutput {
116+
fn from(value: &HashOut<F>) -> Self {
117+
value.to_bytes().try_into().unwrap()
118+
}
119+
}
120+
115121
impl From<HashOutput> for HashOut<F> {
116122
fn from(value: HashOutput) -> Self {
117123
Self::from_bytes(&value.0)

mp2-v1/src/api.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
use alloy::primitives::Address;
2222
use anyhow::Result;
2323
use itertools::Itertools;
24+
use log::debug;
2425
use mp2_common::{
2526
digest::Digest,
2627
group_hashing::map_to_curve_point,
@@ -209,7 +210,7 @@ pub enum SlotInputs {
209210
MappingWithLength(Vec<SlotInput>, u8),
210211
}
211212

212-
#[derive(Debug)]
213+
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
213214
pub struct SlotInput {
214215
/// Slot information of the variable
215216
pub(crate) slot: u8,
@@ -338,7 +339,7 @@ fn value_metadata<const MAX_COLUMNS: usize, const MAX_FIELD_PER_EVM: usize>(
338339
}
339340

340341
/// Compute the table information for the value columns.
341-
fn compute_table_info(
342+
pub fn compute_table_info(
342343
inputs: Vec<SlotInput>,
343344
address: &Address,
344345
chain_id: u64,
@@ -438,8 +439,16 @@ pub fn metadata_hash<const MAX_COLUMNS: usize, const MAX_FIELD_PER_EVM: usize>(
438439
chain_id,
439440
extra,
440441
);
442+
// Correspond to the computation of final extraction base circuit.
443+
let value_digest = map_to_curve_point(&value_digest.to_fields());
441444
// add contract digest
442445
let contract_digest = contract_metadata_digest(contract_address);
446+
debug!(
447+
"METADATA_HASH ->\n\tvalues_ext_md = {:?}\n\tcontract_md = {:?}\n\tfinal_ex_md(contract + values_ex) = {:?}",
448+
value_digest.to_weierstrass(),
449+
contract_digest.to_weierstrass(),
450+
(contract_digest + value_digest).to_weierstrass(),
451+
);
443452
// compute final hash
444453
combine_digest_and_block(contract_digest + value_digest)
445454
}

mp2-v1/src/final_extraction/api.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ impl CircuitInput {
202202
Ok(Self::MergeTable(MergeCircuitInput {
203203
base,
204204
is_table_a_multiplier: true,
205-
table_a_dimension: TableDimension::Single,
205+
// TODO: May delete `TableDimension::Single`, we don't compute the wrapping digest for
206+
// single dimension, otherwise the final digest is different with the block tree digest.
207+
table_a_dimension: TableDimension::Compound,
206208
table_b_dimension: TableDimension::Compound,
207209
}))
208210
}

mp2-v1/src/final_extraction/merge_circuit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use mp2_common::{
99
digest::{SplitDigestTarget, TableDimension, TableDimensionWire},
1010
serialization::{deserialize, serialize},
1111
types::CBuilder,
12-
utils::{SliceConnector, ToTargets},
12+
utils::ToTargets,
1313
D, F,
1414
};
1515
use plonky2::{
@@ -19,7 +19,6 @@ use plonky2::{
1919
},
2020
plonk::circuit_builder::CircuitBuilder,
2121
};
22-
use plonky2_ecgfp5::gadgets::curve::CircuitBuilderEcGFp5;
2322
use recursion_framework::circuit_builder::CircuitLogicWires;
2423
use serde::{Deserialize, Serialize};
2524
use verifiable_db::extraction::ExtractionPI;

mp2-v1/src/final_extraction/public_inputs.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use mp2_common::{
66
public_inputs::{PublicInputCommon, PublicInputRange},
77
types::{CBuilder, CURVE_TARGET_LEN},
88
u256::{self, UInt256Target},
9-
utils::{FromFields, FromTargets, ToTargets},
9+
utils::{FromFields, FromTargets, ToTargets, TryIntoBool},
1010
F,
1111
};
1212
use plonky2::iop::target::{BoolTarget, Target};
@@ -110,6 +110,10 @@ impl<'a> PublicInputs<'a, F> {
110110
pub fn block_number(&self) -> u64 {
111111
U256::from_fields(self.bn).to()
112112
}
113+
/// Get the merge flag
114+
pub fn merge_flag(&self) -> bool {
115+
self.merge[0].try_into_bool().unwrap()
116+
}
113117
}
114118

115119
impl<'a, T> PublicInputs<'a, T> {

mp2-v1/src/indexing/row.rs

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ impl<PrimaryIndex: std::fmt::Debug + Clone + Default + PartialEq + Eq> RowPayloa
199199
}
200200
}
201201

202+
pub fn column_value(&self, column_id: ColumnID) -> Option<U256> {
203+
self.cells.get(&column_id).map(|c| c.value)
204+
}
202205
pub fn secondary_index_value(&self) -> U256 {
203206
self.cells
204207
.get(&self.secondary_index_column)

mp2-v1/src/values_extraction/api.rs

+25-24
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,12 @@ mod tests {
899899
}
900900
// Mapping variable
901901
StorageSlot::Mapping(mapping_key, slot) => {
902+
let outer_key_id = test_slot.outer_key_id.unwrap();
902903
let metadata_digest = compute_leaf_mapping_metadata_digest::<
903904
TEST_MAX_COLUMNS,
904905
TEST_MAX_FIELD_PER_EVM,
905906
>(
906-
table_info.clone(), slot as u8, test_slot.outer_key_id
907+
table_info.clone(), slot as u8, outer_key_id
907908
);
908909

909910
let values_digest = compute_leaf_mapping_values_digest::<TEST_MAX_FIELD_PER_EVM>(
@@ -912,14 +913,14 @@ mod tests {
912913
value,
913914
mapping_key.clone(),
914915
evm_word,
915-
test_slot.outer_key_id,
916+
outer_key_id,
916917
);
917918

918919
let circuit_input = CircuitInput::new_mapping_variable_leaf(
919920
node,
920921
slot as u8,
921922
mapping_key,
922-
test_slot.outer_key_id,
923+
outer_key_id,
923924
metadata,
924925
);
925926

@@ -946,27 +947,27 @@ mod tests {
946947
}
947948
// Mapping Struct
948949
StorageSlot::Mapping(mapping_key, slot) => {
949-
let metadata_digest = compute_leaf_mapping_metadata_digest::<
950-
TEST_MAX_COLUMNS,
951-
TEST_MAX_FIELD_PER_EVM,
952-
>(
953-
table_info.clone(), slot as u8, test_slot.outer_key_id
954-
);
950+
let outer_key_id = test_slot.outer_key_id.unwrap();
951+
let metadata_digest =
952+
compute_leaf_mapping_metadata_digest::<
953+
TEST_MAX_COLUMNS,
954+
TEST_MAX_FIELD_PER_EVM,
955+
>(table_info.clone(), slot as u8, outer_key_id);
955956

956957
let values_digest = compute_leaf_mapping_values_digest::<TEST_MAX_FIELD_PER_EVM>(
957958
table_info,
958959
&extracted_column_identifiers,
959960
value,
960961
mapping_key.clone(),
961962
evm_word,
962-
test_slot.outer_key_id,
963+
outer_key_id,
963964
);
964965

965966
let circuit_input = CircuitInput::new_mapping_variable_leaf(
966967
node,
967968
slot as u8,
968969
mapping_key,
969-
test_slot.outer_key_id,
970+
outer_key_id,
970971
metadata,
971972
);
972973

@@ -976,15 +977,15 @@ mod tests {
976977
StorageSlot::Node(StorageSlotNode::Mapping(grand, inner_mapping_key)) => {
977978
match *grand {
978979
StorageSlot::Mapping(outer_mapping_key, slot) => {
979-
let metadata_digest = compute_leaf_mapping_of_mappings_metadata_digest::<
980-
TEST_MAX_COLUMNS,
981-
TEST_MAX_FIELD_PER_EVM,
982-
>(
983-
table_info.clone(),
984-
slot as u8,
985-
test_slot.outer_key_id,
986-
test_slot.inner_key_id,
987-
);
980+
let outer_key_id = test_slot.outer_key_id.unwrap();
981+
let inner_key_id = test_slot.inner_key_id.unwrap();
982+
let metadata_digest =
983+
compute_leaf_mapping_of_mappings_metadata_digest::<
984+
TEST_MAX_COLUMNS,
985+
TEST_MAX_FIELD_PER_EVM,
986+
>(
987+
table_info.clone(), slot as u8, outer_key_id, inner_key_id
988+
);
988989

989990
let values_digest = compute_leaf_mapping_of_mappings_values_digest::<
990991
TEST_MAX_FIELD_PER_EVM,
@@ -995,17 +996,17 @@ mod tests {
995996
evm_word,
996997
outer_mapping_key.clone(),
997998
inner_mapping_key.clone(),
998-
test_slot.outer_key_id,
999-
test_slot.inner_key_id,
999+
outer_key_id,
1000+
inner_key_id,
10001001
);
10011002

10021003
let circuit_input = CircuitInput::new_mapping_of_mappings_leaf(
10031004
node,
10041005
slot as u8,
10051006
outer_mapping_key,
10061007
inner_mapping_key,
1007-
test_slot.outer_key_id,
1008-
test_slot.inner_key_id,
1008+
outer_key_id,
1009+
inner_key_id,
10091010
metadata,
10101011
);
10111012

0 commit comments

Comments
 (0)