Skip to content

Commit 3cffd34

Browse files
committed
Add an integration test.
1 parent d6935f2 commit 3cffd34

File tree

7 files changed

+147
-118
lines changed

7 files changed

+147
-118
lines changed

src/eth.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,19 @@ impl<'a, X> rlp::Encodable for RLPBlock<'a, X> {
163163
s.begin_unbounded_list();
164164
s.append(&self.0.parent_hash);
165165
s.append(&self.0.uncles_hash);
166-
s.append(&self.0.author.unwrap());
166+
s.append(&self.0.author.unwrap_or_default());
167167
s.append(&self.0.state_root);
168168
s.append(&self.0.transactions_root);
169169
s.append(&self.0.receipts_root);
170-
s.append(&self.0.logs_bloom.unwrap());
170+
s.append(&self.0.logs_bloom.unwrap_or_default());
171171
s.append(&self.0.difficulty);
172-
s.append(&self.0.number.unwrap());
172+
s.append(&self.0.number.unwrap_or_default());
173173
s.append(&self.0.gas_limit);
174174
s.append(&self.0.gas_used);
175175
s.append(&self.0.timestamp);
176176
s.append(&self.0.extra_data.to_vec());
177-
s.append(&self.0.mix_hash.unwrap());
178-
s.append(&self.0.nonce.unwrap());
177+
s.append(&self.0.mix_hash.unwrap_or_default());
178+
s.append(&self.0.nonce.unwrap_or_default());
179179
rlp_opt(s, &self.0.base_fee_per_gas);
180180
rlp_opt(s, &self.0.withdrawals_root);
181181
rlp_opt(s, &self.0.blob_gas_used);

src/mpt_sequential.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ pub mod test {
693693
const NODE_LEN: usize = 500;
694694
const VALUE_LEN: usize = 32;
695695
let (proof, key, root, value) = if true {
696-
let (mut trie, key) = generate_random_mpt::<ACTUAL_DEPTH, VALUE_LEN>();
696+
let (mut trie, key) = generate_random_storage_mpt::<ACTUAL_DEPTH, VALUE_LEN>();
697697
let root = trie.root_hash().unwrap();
698698
// root is first so we reverse the order as in circuit we prove the opposite way
699699
let mut proof = trie.get_proof(&key).unwrap();
@@ -792,7 +792,7 @@ pub mod test {
792792
const DEPTH: usize = 4;
793793
const NODE_LEN: usize = 80;
794794
const VALUE_LEN: usize = 32;
795-
let (mut trie, mut key) = generate_random_mpt::<DEPTH, VALUE_LEN>();
795+
let (mut trie, mut key) = generate_random_storage_mpt::<DEPTH, VALUE_LEN>();
796796
let mut proof = trie.get_proof(&key).unwrap();
797797
proof.reverse();
798798
let key_nibbles = bytes_to_nibbles(&key);
@@ -817,7 +817,7 @@ pub mod test {
817817
const NODE_LEN: usize = 500;
818818
const VALUE_LEN: usize = 32;
819819
let (proof, key) = if false {
820-
let (mut trie, key) = generate_random_mpt::<DEPTH, VALUE_LEN>();
820+
let (mut trie, key) = generate_random_storage_mpt::<DEPTH, VALUE_LEN>();
821821
let mut proof = trie.get_proof(&key).unwrap();
822822
proof.reverse();
823823
for (i, node) in proof.iter().enumerate() {
@@ -979,7 +979,7 @@ pub mod test {
979979
const DEPTH: usize = 4;
980980
const NODE_LEN: usize = 80;
981981
const VALUE_LEN: usize = 32;
982-
let (mut trie, key) = generate_random_mpt::<DEPTH, VALUE_LEN>();
982+
let (mut trie, key) = generate_random_storage_mpt::<DEPTH, VALUE_LEN>();
983983
let mut proof = trie.get_proof(&key).unwrap();
984984
proof.reverse();
985985
let key_nibbles = bytes_to_nibbles(&key);
@@ -1057,7 +1057,7 @@ pub mod test {
10571057
const DEPTH: usize = 4;
10581058
const NODE_LEN: usize = 80;
10591059
const VALUE_LEN: usize = 32;
1060-
let (mut trie, mut key) = generate_random_mpt::<DEPTH, VALUE_LEN>();
1060+
let (mut trie, mut key) = generate_random_storage_mpt::<DEPTH, VALUE_LEN>();
10611061
let mut proof = trie.get_proof(&key).unwrap();
10621062
proof.reverse();
10631063
// try with a leaf MPT encoded node first
@@ -1150,7 +1150,7 @@ pub mod test {
11501150
// that key is guaranteed to be of DEPTH length. Each leaves in the trie
11511151
// is of NODE_LEN length.
11521152
// The returned key is RLP encoded
1153-
pub fn generate_random_mpt<const DEPTH: usize, const VALUE_LEN: usize>(
1153+
pub fn generate_random_storage_mpt<const DEPTH: usize, const VALUE_LEN: usize>(
11541154
) -> (EthTrie<MemoryDB>, Vec<u8>) {
11551155
let memdb = Arc::new(MemoryDB::new(true));
11561156
let mut trie = EthTrie::new(Arc::clone(&memdb));

src/rlp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ mod tests {
386386
use crate::array::{Array, Vector, VectorWire};
387387
use crate::keccak::HASH_LEN;
388388
use crate::mpt_sequential::bytes_to_nibbles;
389-
use crate::mpt_sequential::test::generate_random_mpt;
389+
use crate::mpt_sequential::test::generate_random_storage_mpt;
390390
use crate::rlp::{
391391
decode_compact_encoding, decode_fixed_list, decode_header, RlpHeader, RlpList,
392392
MAX_ENC_KEY_LEN, MAX_LEN_BYTES,
@@ -453,7 +453,7 @@ mod tests {
453453
const D: usize = 2;
454454
type C = PoseidonGoldilocksConfig;
455455
type F = <C as GenericConfig<D>>::F;
456-
let (mut trie, key) = generate_random_mpt::<4, 32>();
456+
let (mut trie, key) = generate_random_storage_mpt::<4, 32>();
457457
let mut proof = trie.get_proof(&key).unwrap();
458458
proof.reverse();
459459
let encoded_leaf = proof.first().unwrap();
@@ -863,7 +863,7 @@ mod tests {
863863
run_test_case(tc3);
864864

865865
{
866-
let (mut trie, rlp_key) = generate_random_mpt::<5, 32>();
866+
let (mut trie, rlp_key) = generate_random_storage_mpt::<5, 32>();
867867
let proof = trie.get_proof(&rlp_key).unwrap();
868868
println!(" ------ TEST CASE -----\n");
869869
let leaf_node = proof.last().unwrap().clone();

src/state/block_linking/account_inputs.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use crate::{
66
keccak::{OutputByteHash, OutputHash},
77
mpt_sequential::{
8-
nibbles_to_bytes, Circuit as MPTCircuit, InputWires as MPTInputWires,
9-
OutputWires as MPTOutputWires, PAD_LEN,
8+
Circuit as MPTCircuit, InputWires as MPTInputWires, OutputWires as MPTOutputWires, PAD_LEN,
109
},
1110
utils::{find_index_subvector, keccak256, less_than},
1211
};
@@ -48,9 +47,7 @@ where
4847
// Build the full MPT key as `keccak256(contract_address)` and convert
4948
// it to bytes.
5049
// Check with [ProofQuery::verify_state_proof] for details.
51-
let state_mpt_key = nibbles_to_bytes(&keccak256(&contract_address.0))
52-
.try_into()
53-
.unwrap();
50+
let state_mpt_key = keccak256(&contract_address.0).try_into().unwrap();
5451

5552
// Build the MPT circuit for state Merkle Tree.
5653
let state_mpt_circuit = MPTCircuit::new(state_mpt_key, state_mpt_nodes);
@@ -135,7 +132,7 @@ where
135132
// bits for the range check since any nodes in the MPT proof will not go
136133
// above 544 bytes.
137134
let within_range = less_than(cb, self.storage_root_offset, account_node.real_len, 10);
138-
cb.connect(tt.target, within_range.target);
135+
cb.connect(within_range.target, tt.target);
139136

140137
// Verify the account node includes the storage MPT root hash.
141138
let storage_root_hash = OutputByteHash::from_u32_array(cb, storage_root_hash);

src/state/block_linking/block_inputs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ pub struct BlockInputs {
3535
}
3636

3737
impl BlockInputs {
38-
pub fn new(block: Block<H256>, state_root_hash: &[u8]) -> Self {
38+
pub fn new(block: Block<H256>, state_root_hash: H256) -> Self {
3939
let header_rlp = rlp::encode(&RLPBlock(&block)).to_vec();
4040

4141
// Find the state root hash from block header.
42-
let state_root_offset = find_index_subvector(&header_rlp, state_root_hash).unwrap();
42+
let state_root_offset = find_index_subvector(&header_rlp, &state_root_hash.0).unwrap();
4343

4444
Self {
4545
number: block.number.unwrap().as_u64(),
@@ -126,7 +126,7 @@ impl<const MAX_LEN: usize> BlockInputsWires<MAX_LEN> {
126126

127127
// Verify the offset of state MPT root hash is within range.
128128
let within_range = less_than(cb, self.state_root_offset, self.header_rlp.real_len, 10);
129-
cb.connect(tt.target, within_range.target);
129+
cb.connect(within_range.target, tt.target);
130130

131131
// Verify the block header includes the state MPT root hash.
132132
let state_root_hash = OutputByteHash::from_u32_array(cb, state_root_hash);

0 commit comments

Comments
 (0)