Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ax0 committed Mar 15, 2024
1 parent 6273fb8 commit f599a50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<20, PROOF_LEN, MAX_VALUE_LEN>
/// * `path` - RLP-encoded proof path
/// * `depth` - Depth of proof path
/// * `cur_depth` - Current depth in the proof path
fn verify_internal_node<PROOF_LEN>(extracted_hash: &mut [u8; KEY_LENGTH], key_ptr: &mut u64, key_nibbles: [u8; NIBBLE_LENGTH], path: [u8; PROOF_LEN], depth: u64, cur_depth: u64) {
fn verify_internal_node<PROOF_LEN>(extracted_hash: &mut [u8; KEY_LENGTH], key_ptr: &mut u64, key_nibbles: [u8; NIBBLE_LENGTH], path: [u8; PROOF_LEN], depth: u64, cur_depth: u64)
{
let in_range = (cur_depth as u8) < (depth - 1) as u8; // Range indicator

let cur_depth_or_0 = if (in_range) {cur_depth} else {0}; // Restrict index to range {0, ..., depth - 2}
Expand Down Expand Up @@ -238,7 +239,7 @@ fn assert_subarray<N, M>(subarray: [u8; N], array: [u8; M], len: u64, offset: u6
/// * `node` - RLP-encoded trie node
/// * `hash` - 32-byte hash value
pub fn verify_node_hash<N>(node: [u8; N], hash: [u8; KEY_LENGTH])
-> bool
-> bool
{
// Extract actual length of node
let node_length = { let rlp_header = rlp::decode_len(node); rlp_header.offset + rlp_header.length }; // Determine length of node
Expand Down Expand Up @@ -587,7 +588,8 @@ fn byte_value_test()
}

#[test]
fn verify_internal_node_test() {
fn verify_internal_node_test()
{
let mut extracted_hash = [171, 67, 174, 237, 12, 220, 44, 99, 9, 135, 95, 221, 50, 79, 14, 154, 217, 251, 29, 173, 227, 86, 95, 158, 87, 37, 210, 154, 149, 184, 243, 78];
let mut key_ptr = 1;
let key_nibbles = [2, 8, 10, 2, 1, 15, 10, 15, 8, 12, 7, 15, 10, 11, 5, 7, 4, 7, 1, 10, 2, 10, 4, 1, 3, 8, 7, 15, 9, 11, 0, 13, 0, 14, 10, 11, 2, 2, 9, 4, 5, 7, 12, 5, 0, 2, 4, 11, 13, 6, 12, 15, 11, 7, 2, 13, 13, 7, 11, 11, 10, 2, 15, 14];
Expand Down Expand Up @@ -982,8 +984,7 @@ fn verify_internal_node_test() {
let depth = 8;
let cur_depth = 1;
verify_internal_node(&mut extracted_hash, &mut key_ptr, key_nibbles, path, depth, cur_depth);
assert(extracted_hash == [0xa2, 0xfc, 0x4, 0xa2, 0x1, 0x99, 0xd4, 0x8b, 0xc5, 0xe0, 0x73, 0x27, 0x19, 0x2e, 0xfd, 0x12, 0x73, 0x2, 0xe8, 0x8c, 0x35, 0x48, 0x2c, 0xfa, 0xde, 0xf6, 0xb8, 0x72, 0xcb, 0x25, 0xd5, 0x3f]
);
assert(extracted_hash == [0xa2, 0xfc, 0x4, 0xa2, 0x1, 0x99, 0xd4, 0x8b, 0xc5, 0xe0, 0x73, 0x27, 0x19, 0x2e, 0xfd, 0x12, 0x73, 0x2, 0xe8, 0x8c, 0x35, 0x48, 0x2c, 0xfa, 0xde, 0xf6, 0xb8, 0x72, 0xcb, 0x25, 0xd5, 0x3f]);
}

// Trie proof tests
Expand Down
9 changes: 6 additions & 3 deletions lib/src/test.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ global storage_root = [
];

#[test]
fn test_verify_storage_root_depth_2() {
fn test_verify_storage_root_depth_2()
{
let trie_proof = TrieProof { key, proof, depth, value };
let _ = trie_proof.verify_storage_root(storage_root);
}

#[test(should_fail_with="Internal node hash does not match the hash extracted from the preceding node")]
fn test_assertion_message_for_invalid_storage_root() {
fn test_assertion_message_for_invalid_storage_root()
{
let invalid_storage_root = [0; 32];

let trie_proof = TrieProof { key, proof, depth, value };
let _ = trie_proof.verify_storage_root(invalid_storage_root);
}

#[test(should_fail_with="Leaf node hash does not match the hash extracted from the preceding node")]
fn test_assertion_message_for_invalid_leaf() {
fn test_assertion_message_for_invalid_leaf()
{
let mut proof_with_modified_teminal_node = proof;
proof_with_modified_teminal_node[MAX_TRIE_NODE_LENGTH] += 0x01;

Expand Down

0 comments on commit f599a50

Please sign in to comment.