-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check system tx method hashes in CI (#447)
* Check system tx method hashes in CI
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
crates/evm/src/evm/system_contracts/test/check_sys_hashes.py
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,42 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os | ||
import json | ||
|
||
# If this script fails: | ||
# - update crates/evm/src/evm/system_contracts/mod.rs accordingly | ||
|
||
test_script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
artifact_dir = test_script_dir + "/../out/" | ||
|
||
|
||
def assert_hash(contract, id, hash, expected_hash): | ||
msg = f"{contract}::{id} must have hash '{expected_hash}', but '{hash}' is set instead." | ||
assert hash == expected_hash, msg | ||
|
||
|
||
sys_contracts = { | ||
"BitcoinLightClient": { | ||
"initializeBlockNumber(uint256)": "1f578333", | ||
"setBlockInfo(bytes32,bytes32)": "0e27bc11", | ||
"getBlockHash(uint256)": "ee82ac5e", | ||
"getWitnessRootByNumber(uint256)": "61b207e2", | ||
} | ||
} | ||
|
||
# for every contract | ||
for contract, exp in sys_contracts.items(): | ||
# open the ABI/artifact file | ||
with open(artifact_dir + f"{contract}.sol/{contract}.json") as f: | ||
abi = json.load(f) | ||
ids = abi["methodIdentifiers"] | ||
|
||
# check that every expected method is present in the ABI | ||
for id in exp: | ||
assert id in ids, f"'{id}' not found in {contract} ABI" | ||
|
||
# check that every method in the ABI has the expected keccak hash | ||
for id, hash in ids.items(): | ||
for exp_id, exp_hash in exp.items(): | ||
if id.startswith(exp_id): | ||
assert_hash(contract, id, hash, exp_hash) |