-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vlayer-xyz/hash_mismatch_assertion_message
Hash mismatch assertion messages and CI
- Loading branch information
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: nargo test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Nargo | ||
uses: noir-lang/[email protected] | ||
with: | ||
toolchain: 0.24.0 | ||
|
||
- name: Run nargo test | ||
run: nargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::{TrieProof, MAX_TRIE_NODE_LENGTH}; | ||
|
||
// Test data for { blockNumber: 4605172n, address: '0xc7af99fe5513eb6710e6d5f44f9989da40f27f26', storageKeys: ['0x0000000000000000000000000000000000000000000000000000000000000000'] } | ||
global key = [0; 32]; | ||
global proof = [ | ||
248, 145, 128, 128, 160, 242, 226, 219, 153, 145, 216, 146, 196, 177, 110, 8, 236, 110, 245, 27, 30, 110, 130, 166, 5, 250, 128, 246, 172, 40, 49, 223, 164, 207, 142, 243, 255, 128, 160, 226, 125, 126, 238, 165, 20, 178, 4, 144, 145, 3, 17, 100, 3, 5, 45, 148, 46, 118, 242, 188, 70, 192, 127, 61, 48, 105, 148, 15, 81, 129, 121, 128, 128, 128, 160, 7, 27, 1, 31, 219, 212, 173, 125, 30, 111, 151, 98, 190, 77, 26, 136, 223, 253, 230, 20, 166, 189, 57, 155, 243, 181, 186, 216, 244, 18, 73, 181, 128, 128, 160, 208, 164, 119, 86, 185, 235, 172, 90, 175, 221, 26, 105, 98, 126, 17, 180, 180, 254, 100, 143, 228, 195, 178, 176, 201, 61, 242, 180, 27, 125, 241, 222, 128, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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0xba, 0x52, 0xc7, 0x57, 0x64, 0xd6, 0xf5, 0x94, 0x73, 0x5d, 0xc7, 0x35, 0xbe, 0x7f, 0x18, 0x30, 0xcd, 0xf5, 0x8d, 0xdf | ||
]; | ||
global storage_root = [ | ||
125, 195, 164, 218, 176, 85, 143, 71, 255, 31, 212, 187, 163, 127, 253, 114, 116, 63, 178, 142, 180, 220, 161, 96, 6, 227, 190, 95, 53, 18, 223, 84 | ||
]; | ||
|
||
#[test] | ||
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="Middle node hash does not match the hash extracted from the preceding node")] | ||
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="Terminal node hash does not match the hash extracted from the preceding node")] | ||
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; | ||
|
||
let trie_proof = TrieProof { key, proof: proof_with_modified_teminal_node, depth, value }; | ||
let _ = trie_proof.verify_storage_root(storage_root); | ||
} |