Repository navigation
Expand file tree
/
Copy pathcheck_bytecode.sh
More file actions
executable file
·51 lines (51 loc) · 2.1 KB
/
Copy pathcheck_bytecode.sh
File metadata and controls
executable file
·51 lines (51 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
# Compiles each contract whose `*.build.json` names the Fe commit `fe.pin` names, with the `fe`
# of a checkout at that commit, and compares the bytes with the contract's pinned `creation.hex`
# and `runtime.hex`, ignoring a trailing newline. Fails on any difference, and if no contract
# names that commit: the certificates are about the pinned bytecode, so it must be what the
# pinned compiler makes.
#
# The contract Fe compiles is the build record's `compiler.feContract`, or its `contract` when it
# has none: `contract` is also the name EquiVM's scaffold gives the contract's files, and the two
# differ where the Fe contract has another name (`FeDeposit` is Fe's `DepositContract`).
#
# Usage: scripts/check_bytecode.sh <fe checkout>
set -eu
root=$(cd "$(dirname "$0")/.." && pwd -P)
fe=$(cd "$1" && pwd -P)
rev=$(sed -n 's/^rev=//p' "$root/fe.pin")
(cd "$fe" && cargo build --release --locked -p fe)
out=$(mktemp -d)
status=0
checked=0
for json in "$root"/FeProofs/*/*.build.json; do
dir=$(dirname "$json")
# shellcheck disable=SC2046 # three words
set -- $(python3 -c 'import json, sys
c = json.load(open(sys.argv[1]))
print(c["compiler"].get("feContract", c["contract"]), c["compiler"]["commit"], c["compiler"]["optimize"])' "$json")
contract=$1 commit=$2 optimize=$3
case $rev in "$commit"*) ;; *) continue ;; esac
if [ -f "$dir/fe.toml" ]; then
set -- "$dir"
else
set -- "$dir"/*.fe --standalone
fi
"$fe/target/release/fe" build "$@" --contract "$contract" -O "$optimize" \
--out-dir "$out/$contract" --emit bytecode,runtime-bytecode > /dev/null
for pair in "$contract.bin creation.hex" "$contract.runtime.bin runtime.hex"; do
# shellcheck disable=SC2086 # two words
set -- $pair
if [ "$(cat "$out/$contract/$1")" != "$(cat "$dir/$2")" ]; then
echo "error: ${dir#"$root"/}/$2 is not the $1 that Fe $rev compiles."
status=1
fi
done
checked=$((checked + 1))
done
if [ "$checked" -eq 0 ]; then
echo "error: no *.build.json names the Fe commit fe.pin names ($rev)."
exit 1
fi
echo "contracts whose pinned bytecode the pinned Fe compiles: $checked"
exit $status