diff --git a/src/data_structures/eth_mpt.cairo b/src/data_structures/eth_mpt.cairo index 14dbe9a..01b3a63 100644 --- a/src/data_structures/eth_mpt.cairo +++ b/src/data_structures/eth_mpt.cairo @@ -75,7 +75,8 @@ impl MPTImpl of MPTTrait { // If it's not the last node and more than 9 words, it must be a branch node let (decoded, rlp_byte_len) = if proof_index != proof_len - 1 && node.len() > 9 { let current_nibble = (key / key_pow2) & 0xf; - // Unwrap impossible to fail, as we are masking with 0xf, meaning the result is always a nibble + // Unwrap impossible to fail, as we are masking with 0xf, meaning the result is + // always a nibble match MPTTrait::lazy_rlp_decode_branch_node( node, current_nibble.try_into().unwrap() ) { @@ -107,7 +108,8 @@ impl MPTImpl of MPTTrait { } let current_nibble = (key / key_pow2) & 0xf; - // Unwrap impossible to fail, as we are masking with 0xf, meaning the result is always a nibble + // Unwrap impossible to fail, as we are masking with 0xf, meaning the result is + // always a nibble let current_hash_words = *nibbles.at(current_nibble.try_into().unwrap()); current_hash = if current_hash_words.len() == 0 { @@ -269,7 +271,8 @@ impl MPTImpl of MPTTrait { } else if len == 2 { let (first, first_len) = *l.at(0); let (second, _) = *l.at(1); - // Unwrap impossible to fail, as we are making with 0xff, meaning the result always fits in a byte + // Unwrap impossible to fail, as we are making with 0xff, meaning the result + // always fits in a byte let prefix_byte: Byte = (*first.at(0) & 0xff).try_into().unwrap(); let (prefix, _) = prefix_byte.extract_nibbles(); diff --git a/src/data_structures/mmr/proof.cairo b/src/data_structures/mmr/proof.cairo index e72e082..411eb3e 100644 --- a/src/data_structures/mmr/proof.cairo +++ b/src/data_structures/mmr/proof.cairo @@ -15,7 +15,8 @@ impl ProofImpl of ProofTrait { // @return The root of the subtree fn compute_peak(self: Proof, index: usize, hash: felt252) -> felt252 { // calculate direction array - // direction[i] - whether the i-th node from the root is a left or a right child of its parent + // direction[i] - whether the i-th node from the root is a left or a right child of its + // parent let mut bits = bit_length(index); if self.len() + 1 > bits { bits = self.len() + 1; diff --git a/src/data_structures/tests/test_eth_mpt.cairo b/src/data_structures/tests/test_eth_mpt.cairo index 0777524..e2a4d53 100644 --- a/src/data_structures/tests/test_eth_mpt.cairo +++ b/src/data_structures/tests/test_eth_mpt.cairo @@ -313,6 +313,7 @@ fn test_hash_rlp_node() { #[available_gas(9999999999999)] fn test_full_verify() { //// Account : 0x7b5C526B7F8dfdff278b4a3e045083FBA4028790 | Goerli | Block 9000000 + //// ////"0xf90211a0f09eae4e1e51fdde02a2884e285b8a8a9c72cc7e7cdaeef013714e3499bcd475a0ce33fd7097055e50d64c42759027e41ffb22d5b2a03ee67207dc94b547e40956a04817bf75497b71a78957ff89d05107cbf16ead02f7e68f13cead9e7d24dfcda5a00751841dcd0e21ff273930aa4722cabae7ea4e09d0f4e9f667b57ab68a41652ea047008ee2caeec1839c016d0a8efd2e901091bfae5388fc064db9f14f4bda362da0f952be9637ec6790bcdcf9ae3d4bca607259f26c0731e3cbd2882924c9db5653a061a8882bde126643739fe5f0acc5d234467718c27217f56513fd222009802336a061dbaa68a4290e8cce57166ffc6fd22d081c5893a081082b23668ef6c7d65c81a0ef2e0aea160700e14be7285c8b83535f4d104a74ac8db6c188d84ee48a8a647ca0c00853c7500db3c616d5d7dcd7503c02307045e7670a0749ffdebadc732a9ab4a068050da8f891b57fbeacffe4ba3e41f11c5d6b0ec8553fbb796f46951ecd1445a0762e36c38c548c5ae61da51205ef1dc66390702397becef53c50d969cae7a2ada0abff9de80f8e14979ebbe80ae3e702e61b31b91ea481c0e63a7bde12e866eeb5a017220448de88495fdf81446233768ef9441058e4602ecafc1da85a7cbbf1c16da084351381e6cad5052c82f731e8d19d86193794eccdf274529bed7e67309cca78a0784e83133c0ba8ff0262d0c96dc93f936d97eac46327d32f3c1baceb63934d9d80", ////"0xf90211a0679ec41f2230e1f57eededf17732966880d9835d744ad769a1b246829341a588a09c2941acea1f1461a7d0af3bb9917c16e3a3339556623a6cad6d1f40ee8fc8a8a0211b79624826f8cd651f7a0123356cfef56854adf7285163988ba4eee0e8f964a062a3e341692078b717029cd105b462749386aecc1cb647721cc382872eac4a51a01a9fc7658bcc2948e1123273e83fb66894e64c2e19aa8f3ac546c45ef4b22290a08c5cdf2e341821e9c3163ec52847e33884f4797669607a60a8adafd00edead0ea08b07046b12762a58e03a482d597cca869aaffd85214bbd08c4624325a7cf80c9a0602d16a56550182218f642f56e66b1cf72555c38dac0fd061b8ef113d4653f4aa038fa2d962cfe43eb49f5a7d1787a436e8e3c6858665b1b0703c4e42ad43f962ea03a706c9b0e0757079f96d9df003eae31aafcf7525d6114033ee929c78adc580aa0f8a66bdc97088d4c73429b9ee00d7bcd0589be3462a53e9f5b9876d4b5231e40a04bbcbff81f2c0b65f29724ef71f6d439b6f857ad5fa7b643c1ea5dfc72ee240fa098cd5bf5aea320986616ff7bfc78efdf43091610fb457447058958e68a13e49ba02033016a2ef0512c926211fbec6f9b7398c58ae10116901d086905979649d968a07cf13191df973971dd4592a95c33cc3c248a4e919b8866c7c8ecff44a6e453a2a017010b7ff49cf72fbc13136f189457a2bc09e8c400ca9cb7997ff75bf34637ec80", ////"0xf90211a06c86eef3a8754d952a265132ed86282d34ec24f9f5aa2f085629155798975c2ba02cef7b79076bddfe220fd88ca1a18414683b2f37e8b94cf8c6bdf743cff9d18ca00fe6e40f33bc1b76e34a6c92cdfce9b08f808bca7c6fe85348a7b7e838632a20a0f2f4d7b6fb649794a45288bfbc32274f3031ebc8bbf808146a3104ea27d72e7aa0cf2a353bb32b3b9c004c7586d6723ea5e2ccb99972c84b4b2c90166ca0c3c65ba0753fee595b7a0b80d3574db4e4615a599da7bedfa71bcb9ba214192c6dfb8a4fa0a7e45064974417eeef5556e4fa3533c819cc04825a33f0e244440d4d6a42828ca06cb2eaf789a62824a4a2b730bc4b8ee70e3648fbdf6cd61ea86d234dda67ccc3a0e42e79aeed163de73664c3b4f9451208b22b4874eae6c007b5f0405a64a55050a072f87da9fbd3c727080eef39891888876cdfbc54b732cf4f08ee19d067117d5ba0ce88e695612d636a6f73c2fcc0086e486249a0284cd6b88bf1cc3a7bef84ce9ba0d408599a558fc0ad84aba0bea36e00c1e99ddebf7b74e2f68912563bd5a62522a0154aef7de9275d13e860b11f138a811e6ed97fbf8985c524ccd5c231dbc62180a0282022799ec74b1dc2df4edad584b0b974113a06a857ff72ed17471908d28404a00c4fc7a3f7ded56f4da7093a875bd7c3a6cb35cc6bdf505cb79aee64708640aca0339829e86f4b7a2d68fe0b4707e32016534cdf8a48070a3921a48bcc0fd4b11c80", diff --git a/src/hashing/keccak.cairo b/src/hashing/keccak.cairo index d106bce..dd3a030 100644 --- a/src/hashing/keccak.cairo +++ b/src/hashing/keccak.cairo @@ -6,7 +6,8 @@ const EMPTY_KECCAK: u256 = 0x70A4855D04D8FA7B3B2782CA53B600E5C003C7DCB27D7E923C2 // @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 // @param last_word_bytes Number of bytes in the last word -// @return The little endian keccak hash of the input, matching the output of the EVM's keccak256 opcode +// @return The little endian keccak hash of the input, matching the output of the EVM's keccak256 +// opcode fn keccak_cairo_words64(words: Words64, last_word_bytes: usize) -> u256 { if words.is_empty() { return EMPTY_KECCAK; diff --git a/src/hashing/poseidon.cairo b/src/hashing/poseidon.cairo index 168d542..f069010 100644 --- a/src/hashing/poseidon.cairo +++ b/src/hashing/poseidon.cairo @@ -19,7 +19,9 @@ fn hash_words64(words: Words64) -> felt252 { } } -// Permutation params: https://docs.starknet.io/documentation/architecture_and_concepts/Cryptography/hash-functions/#poseidon_hash +// Permutation params: +// +// https://docs.starknet.io/documentation/architecture_and_concepts/Cryptography/hash-functions/#poseidon_hash impl PoseidonHasher of Hasher { // @inheritdoc Hasher fn hash_single(a: felt252) -> felt252 { diff --git a/src/utils/types/words64.cairo b/src/utils/types/words64.cairo index dd8ef9b..bbeebda 100644 --- a/src/utils/types/words64.cairo +++ b/src/utils/types/words64.cairo @@ -3,8 +3,9 @@ use cairo_lib::utils::bitwise::left_shift; use cairo_lib::utils::math::pow; // @notice Represents a span of 64 bit words -// @dev In many cases it's expected that the words are in little endian, but the overall order is big endian -// Example: 0x34957c6d8a83f9cff74578dea9 is represented as [0xcff9838a6d7c9534, 0xa9de7845f7] +// @dev In many cases it's expected that the words are in little endian, but the overall order is +// big endian Example: 0x34957c6d8a83f9cff74578dea9 is represented as [0xcff9838a6d7c9534, +// 0xa9de7845f7] type Words64 = Span; #[generate_trait] @@ -58,8 +59,8 @@ impl Words64Impl of Words64Trait { } } - // @notice Converts little endian 64 bit words to a little endian u256 using the first 4 64 bits words - // @return The little endian u256 representation of the words + // @notice Converts little endian 64 bit words to a little endian u256 using the first 4 64 bits + // words @return The little endian u256 representation of the words fn as_u256_le(self: Words64) -> Result { let word_pow2 = 0x10000000000000000; // 2 ** 64 @@ -88,10 +89,11 @@ impl Words64Impl of Words64Trait { // @notice Slices 64 bit little endian words from a starting byte and a length // @param start The starting byte - // The starting byte is counted from the left. Example: 0xabcdef -> byte 0 is 0xab, byte 1 is 0xcd... + // The starting byte is counted from the left. Example: 0xabcdef -> byte 0 is 0xab, byte 1 is + // 0xcd... // @param len The number of bytes to slice // @return A span of 64 bit little endian words - // Example: + // Example: // words: [0xabcdef1234567890, 0x7584934785943295, 0x48542576] // start: 5 | len: 17 // output: [0x3295abcdef123456, 0x2576758493478594, 0x54]