Skip to content

Commit

Permalink
empty keccak
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofneto committed Oct 17, 2023
1 parent fa12c59 commit 6790a2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/data_structures/eth_mpt.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,16 @@ impl MPTImpl of MPTTrait {

if prefix == 0 {
match second.try_into() {
Option::Some(n) => Result::Ok(MPTNode::Extension((first, n, 2, n_nibbles - 1))),
Option::Some(n) => Result::Ok(
MPTNode::Extension((first, n, 2, n_nibbles - 1))
),
Option::None(_) => Result::Err('Invalid next node')
}
} else if prefix == 1 {
match second.try_into() {
Option::Some(n) => Result::Ok(MPTNode::Extension((first, n, 1, n_nibbles))),
Option::Some(n) => Result::Ok(
MPTNode::Extension((first, n, 1, n_nibbles))
),
Option::None(_) => Result::Err('Invalid next node')
}
} else if prefix == 2 {
Expand Down
6 changes: 6 additions & 0 deletions src/hashing/keccak.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use cairo_lib::utils::types::words64::{Words64, bytes_used_u64};
use keccak::cairo_keccak;

const EMPTY_KECCAK: u256 = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;

// @notice Wrapper arround cairo_keccak that format the input for compatibility with EVM
// @param words The input data, as a list of 64-bit little-endian words
// @return The keccak hash of the input, matching the output of the EVM's keccak256 opcode
fn keccak_cairo_words64(words: Words64) -> u256 {
if words.is_empty() {
return EMPTY_KECCAK;
}

let n = words.len();

let mut keccak_input = ArrayTrait::new();
Expand Down

0 comments on commit 6790a2d

Please sign in to comment.