Skip to content

Commit 0e0aa07

Browse files
committed
resolves CRY-23
1 parent 07ecb08 commit 0e0aa07

File tree

10 files changed

+538
-37
lines changed

10 files changed

+538
-37
lines changed

mp2-v1/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ TEST_BINDINGS_OUT_PATH=$(TEST_CONTRACT_PATH)/out/$(TEST_BINDINGS_FOLDER)
1212

1313
# Generate the integration test contract bindings.
1414
bindings:
15-
rm -rf $(TEST_BINDINGS_MOD_PATH) $(TEST_BINDINGS_OUT_PATH)
1615

1716
# Generate new bindings.
1817
forge install --root $(TEST_CONTRACT_PATH)
19-
forge bind --alloy --module --root $(TEST_CONTRACT_PATH)
20-
21-
# Move the bindings module to the integration test location.
22-
mv -f $(TEST_BINDINGS_OUT_PATH) $(TEST_BINDINGS_MOD_PATH)
18+
forge bind --bindings-path $(TEST_BINDINGS_MOD_PATH) --alloy --module --root $(TEST_CONTRACT_PATH) --extra-output abi --overwrite
2319
cargo fmt
2420

21+
2522
# Declare phony targets
2623
.PHONY: bindings

mp2-v1/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn metadata_digest_mapping(address: &Address, chain_id: u64, extra: Vec<u8>, slo
222222
compute_leaf_mapping_metadata_digest(key_id, value_id, slot)
223223
}
224224

225-
fn combine_digest_and_block(digest: Digest) -> HashOutput {
225+
pub fn combine_digest_and_block(digest: Digest) -> HashOutput {
226226
let block_id = identifier_block_column();
227227
let inputs = digest
228228
.to_fields()

mp2-v1/src/values_extraction/api.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,25 @@ mod tests {
720720
// (the MPT proof for the first node is different).
721721
// Then check that the node above both is a branch.
722722
assert!(receipt_proofs.len() > 3);
723+
let mut receipt_iterator = receipt_proofs.iter().skip(2);
723724
let second_info = &receipt_proofs[1];
724-
let third_info = &receipt_proofs[2];
725+
let mut other_info = receipt_iterator
726+
.next()
727+
.expect("Didn't have enough receipt proofs");
725728

726729
let proof_length_1 = second_info.mpt_proof.len();
727-
let proof_length_2 = third_info.mpt_proof.len();
730+
let mut proof_length_2 = other_info.mpt_proof.len();
728731

729732
let list_one = rlp::decode_list::<Vec<u8>>(&second_info.mpt_proof[proof_length_1 - 2]);
730-
let list_two = rlp::decode_list::<Vec<u8>>(&third_info.mpt_proof[proof_length_2 - 2]);
733+
let mut list_two = rlp::decode_list::<Vec<u8>>(&other_info.mpt_proof[proof_length_2 - 2]);
734+
735+
let mut next_info = receipt_iterator.next();
736+
while list_one != list_two && next_info.is_some() {
737+
other_info = next_info.unwrap();
738+
proof_length_2 = other_info.mpt_proof.len();
739+
list_two = rlp::decode_list::<Vec<u8>>(&other_info.mpt_proof[proof_length_2 - 2]);
740+
next_info = receipt_iterator.next()
741+
}
731742

732743
assert!(list_one == list_two);
733744
assert!(list_one.len() == 17);
@@ -751,7 +762,7 @@ mod tests {
751762
);
752763

753764
println!("Proving leaf 2...");
754-
let leaf_input_2 = CircuitInput::new_receipt_leaf(third_info, query);
765+
let leaf_input_2 = CircuitInput::new_receipt_leaf(other_info, query);
755766
let now = std::time::Instant::now();
756767
let leaf_proof2 = generate_proof(&params, leaf_input_2).unwrap();
757768
println!(

mp2-v1/src/values_extraction/mod.rs

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,26 @@ pub(crate) const BLOCK_ID_DST: &[u8] = b"BLOCK_NUMBER";
3737

3838
/// Prefix used for making a topic column id.
3939
const TOPIC_PREFIX: &[u8] = b"topic";
40+
/// [`TOPIC_PREFIX`] as a [`str`]
41+
const TOPIC_NAME: &str = "topic";
4042

4143
/// Prefix used for making a data column id.
4244
const DATA_PREFIX: &[u8] = b"data";
45+
/// [`DATA_PREFIX`] as a [`str`]
46+
const DATA_NAME: &str = "data";
4347

4448
/// Prefix for transaction index
4549
const TX_INDEX_PREFIX: &[u8] = b"tx index";
4650

4751
/// Prefix for log number
4852
const LOG_NUMBER_PREFIX: &[u8] = b"log number";
53+
/// [`LOG_NUMBER_PREFIX`] as a [`str`]
54+
const LOG_NUMBER_NAME: &str = "log number";
4955

5056
/// Prefix for gas used
51-
const GAS_USED_PREFIX: &[u8] = b" gas used";
57+
const GAS_USED_PREFIX: &[u8] = b"gas used";
58+
/// [`GAS_USED_PREFIX`] as a [`str`]
59+
const GAS_USED_NAME: &str = "gas used";
5260

5361
pub fn identifier_block_column() -> u64 {
5462
let inputs: Vec<F> = BLOCK_ID_DST.to_fields();
@@ -401,3 +409,84 @@ pub fn compute_receipt_leaf_value_digest<const NO_TOPICS: usize, const MAX_DATA:
401409
})
402410
.fold(Digest::NEUTRAL, |acc, p| acc + p)
403411
}
412+
413+
/// Function that computes the column identifiers for the non-indexed columns together with their names as [`String`]s.
414+
pub fn compute_non_indexed_receipt_column_ids<const NO_TOPICS: usize, const MAX_DATA: usize>(
415+
event: &EventLogInfo<NO_TOPICS, MAX_DATA>,
416+
) -> Vec<(String, GFp)> {
417+
let log_number_input = [
418+
event.address.as_slice(),
419+
event.event_signature.as_slice(),
420+
LOG_NUMBER_PREFIX,
421+
]
422+
.concat()
423+
.into_iter()
424+
.map(GFp::from_canonical_u8)
425+
.collect::<Vec<GFp>>();
426+
let log_number_column_id = H::hash_no_pad(&log_number_input).elements[0];
427+
428+
let gas_used_input = [
429+
event.address.as_slice(),
430+
event.event_signature.as_slice(),
431+
GAS_USED_PREFIX,
432+
]
433+
.concat()
434+
.into_iter()
435+
.map(GFp::from_canonical_u8)
436+
.collect::<Vec<GFp>>();
437+
let gas_used_column_id = H::hash_no_pad(&gas_used_input).elements[0];
438+
439+
let topic_ids = event
440+
.topics
441+
.iter()
442+
.enumerate()
443+
.map(|(j, _)| {
444+
let input = [
445+
event.address.as_slice(),
446+
event.event_signature.as_slice(),
447+
TOPIC_PREFIX,
448+
&[j as u8 + 1],
449+
]
450+
.concat()
451+
.into_iter()
452+
.map(GFp::from_canonical_u8)
453+
.collect::<Vec<GFp>>();
454+
(
455+
format!("{}_{}", TOPIC_NAME, j + 1),
456+
H::hash_no_pad(&input).elements[0],
457+
)
458+
})
459+
.collect::<Vec<(String, GFp)>>();
460+
461+
let data_ids = event
462+
.data
463+
.iter()
464+
.enumerate()
465+
.map(|(j, _)| {
466+
let input = [
467+
event.address.as_slice(),
468+
event.event_signature.as_slice(),
469+
DATA_PREFIX,
470+
&[j as u8 + 1],
471+
]
472+
.concat()
473+
.into_iter()
474+
.map(GFp::from_canonical_u8)
475+
.collect::<Vec<GFp>>();
476+
(
477+
format!("{}_{}", DATA_NAME, j + 1),
478+
H::hash_no_pad(&input).elements[0],
479+
)
480+
})
481+
.collect::<Vec<(String, GFp)>>();
482+
483+
[
484+
vec![
485+
(LOG_NUMBER_NAME.to_string(), log_number_column_id),
486+
(GAS_USED_NAME.to_string(), gas_used_column_id),
487+
],
488+
topic_ids,
489+
data_ids,
490+
]
491+
.concat()
492+
}

mp2-v1/store/test_proofs.store

-512 KB
Binary file not shown.

mp2-v1/tests/common/cases/contract.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ use anyhow::Result;
55
use log::info;
66

77
use crate::common::{
8-
bindings::simple::Simple::{self, SimpleInstance},
8+
bindings::{
9+
eventemitter::EventEmitter::{self, EventEmitterInstance},
10+
simple::Simple::{self, SimpleInstance},
11+
},
912
TestContext,
1013
};
1114

12-
use super::indexing::{ContractUpdate, SimpleSingleValue, UpdateSimpleStorage};
15+
use super::indexing::{ContractUpdate, ReceiptUpdate, SimpleSingleValue, UpdateSimpleStorage};
1316

1417
pub struct Contract {
1518
pub address: Address,
@@ -89,3 +92,22 @@ where
8992
})
9093
}
9194
}
95+
96+
pub struct EventContract<T: Transport + Clone> {
97+
pub instance: EventEmitterInstance<T, RootProvider<T, Ethereum>, Ethereum>,
98+
}
99+
100+
impl<T: Transport + Clone> TestContract<T> for EventContract<T> {
101+
type Update = ReceiptUpdate;
102+
type Contract = EventEmitterInstance<T, RootProvider<T, Ethereum>>;
103+
104+
fn new(address: Address, provider: &RootProvider<T>) -> Self {
105+
Self {
106+
instance: EventEmitter::new(address, provider.clone()),
107+
}
108+
}
109+
110+
fn get_instance(&self) -> &Self::Contract {
111+
&self.instance
112+
}
113+
}

0 commit comments

Comments
 (0)