Skip to content

Commit

Permalink
fix: more robust SMT parsing (#733)
Browse files Browse the repository at this point in the history
* mark: 0xaatif/smt-parse-tweaking

* robustness
  • Loading branch information
0xaatif authored Oct 21, 2024
1 parent f8c5f9c commit 8681cd7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 3 additions & 0 deletions trace_decoder/src/type2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ fn visit(
address,
value,
}) => {
ensure!(address.len() == Address::len_bytes());
let address = Address::from_slice(&address);
let collated = leaves.entry(address).or_default();
ensure!(value.len() <= 32);
let value = U256::from_big_endian(&value);
macro_rules! ensure {
($expr:expr) => {
Expand All @@ -195,6 +197,7 @@ fn visit(
collated.code = Some(value)
}
SmtLeafType::Storage(slot) => {
ensure!(slot.len() <= 32);
let clobbered = collated.storage.insert(U256::from_big_endian(&slot), value);
ensure!(clobbered.is_none())
}
Expand Down
4 changes: 0 additions & 4 deletions trace_decoder/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,13 @@ pub enum Instruction {
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/705
// `address` and `value` should be fixed length fields
pub struct SmtLeaf {
pub node_type: SmtLeafType,
pub address: NonEmpty<Vec<u8>>,
pub value: NonEmpty<Vec<u8>>,
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// TODO(0xaatif): https://github.com/0xPolygonZero/zk_evm/issues/705
// `Storage` should contain a fixed length field
pub enum SmtLeafType {
Balance,
Nonce,
Expand Down

0 comments on commit 8681cd7

Please sign in to comment.