Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type conversions to make it compile with nargo 0.24.0 #19

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<32, PROOF_LEN, MAX_VALUE_LEN>

let key_nibbles: [u8; NIBBLE_LENGTH] = key_as_nibbles(key);

let mut key_ptr = 0;
let mut key_ptr: u64 = 0;

let (value, mut value_length) = byte_value(self.value); // Value to verify together with its byte length

Expand All @@ -81,7 +81,7 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<32, PROOF_LEN, MAX_VALUE_LEN>

let mut node = [0; MAX_TRIE_NODE_LENGTH];

for i in 0..(path.len()/MAX_TRIE_NODE_LENGTH - 1)
for i in 0..(path.len() as u64 / MAX_TRIE_NODE_LENGTH - 1)
{
let in_range = (i as u8) < (depth - 1) as u8; // Range indicator

Expand Down Expand Up @@ -120,7 +120,7 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<32, PROOF_LEN, MAX_VALUE_LEN>
assert((extracted_value_length as u32) <= MAX_STORAGE_VALUE_LENGTH as u32 + 1); // Extracted value be at most 33 bytes with RLP header
key_ptr = terminal_key_ptr;

assert(key_ptr == 2*key.len()); // All of the key has been exhausted.
assert(key_ptr == 2 * key.len() as u64); // All of the key has been exhausted.

// Decode extracted value
let (dec_value_offset, dec_value_len) = rlp::decode0(extracted_value);
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<20, PROOF_LEN, MAX_VALUE_LEN>

let key_nibbles: [u8; NIBBLE_LENGTH] = key_as_nibbles(key);

let mut key_ptr = 0;
let mut key_ptr: u64 = 0;

let (value, mut value_length) = byte_value(self.value); // Value to verify together with its byte length

Expand All @@ -168,7 +168,7 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<20, PROOF_LEN, MAX_VALUE_LEN>

let mut node = [0; MAX_TRIE_NODE_LENGTH];

for i in 0..(path.len()/MAX_TRIE_NODE_LENGTH - 1)
for i in 0..(path.len() as u64 / MAX_TRIE_NODE_LENGTH - 1)
{
let in_range = (i as u8) < (depth - 1) as u8; // Range indicator

Expand Down Expand Up @@ -206,7 +206,7 @@ impl<PROOF_LEN, MAX_VALUE_LEN> TrieProof<20, PROOF_LEN, MAX_VALUE_LEN>
assert((extracted_value_length as u32) <= (MAX_VALUE_LEN as u32)); // Extracted value should fit in a byte array of length MAX_ACCOUNT_STATE_LENGTH.
key_ptr = terminal_key_ptr;

assert(key_ptr == 2*key.len()); // All of the key has been exhausted.
assert(key_ptr == 2 * key.len() as u64); // All of the key has been exhausted.

// No need to decode data, but it ought to be a list.
assert(extracted_value[0] >= 0xc0);
Expand Down Expand Up @@ -237,7 +237,7 @@ pub fn verify_node_hash<N>(node: [u8; N], hash: [u8; KEY_LENGTH])

// Extra safety
let in_range = ((node_length as u32) > (node.len() as u32)) as u64;
let safe_length = in_range*node.len() + (1-in_range)*node_length;
let safe_length = in_range * node.len() as u64 + (1 - in_range) * node_length;

// Compute Keccak256 hash of node
let node_hash = keccak256(node, safe_length as u32);
Expand Down
4 changes: 2 additions & 2 deletions tests/one_level/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dep::trie;

fn main(node: [u8; trie::MAX_TRIE_NODE_LENGTH], key: [u8; trie::KEY_LENGTH], key_offset: Field) {
let _lookup: ([u8; trie::KEY_LENGTH], Field) = trie::resolve_nibble32(trie::key_as_nibbles(key), key_offset, node);
fn main(node: [u8; trie::MAX_TRIE_NODE_LENGTH], key: [u8; trie::KEY_LENGTH], key_offset: u64) {
let _lookup: (u64, [u8; trie::KEY_LENGTH], u64) = trie::resolve_nibble32(trie::key_as_nibbles(key), key_offset, node);
}