Skip to content

Commit

Permalink
Check system tx method hashes in CI (#447)
Browse files Browse the repository at this point in the history
* Check system tx method hashes in CI
  • Loading branch information
kpp authored Apr 26, 2024
1 parent 2b106e7 commit d4a0ef2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ jobs:
exit 1
fi
sys_tx_keccak:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Check system tx against artifacts ABI
run: python crates/evm/src/evm/system_contracts/test/check_sys_hashes.py

check_no_std:
runs-on: ubicloud-standard-4
if: github.event.pull_request.draft == false
Expand Down
42 changes: 42 additions & 0 deletions crates/evm/src/evm/system_contracts/test/check_sys_hashes.py
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)

0 comments on commit d4a0ef2

Please sign in to comment.