Skip to content

Commit

Permalink
add precompile gen script
Browse files Browse the repository at this point in the history
  • Loading branch information
mycodecrafting committed Mar 6, 2024
1 parent a1d82ee commit 870b51c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ profile.cov
logs/

tests/spec-tests/

precompile/out/
9 changes: 9 additions & 0 deletions precompile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Writing a Precompile Contract

1. Create Solidity interface in `contracts/interfaces`, e.g, IExampleContract.sol

2. Generate bindings with `./gen.sh`

3. Implement the precompile in Go. The struct should implement the `StatefulPrecompiledContract` interface and methods defined in the Solidity interface.

See NativeMinter as an example implementation
10 changes: 10 additions & 0 deletions precompile/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[profile.default]
fuzz_runs = 1024
evm_version = 'shanghai'
solc_version = '0.8.24'
cache = false
force = false
optimizer = false

[profile.ci]
fuzz_runs = 8192
13 changes: 13 additions & 0 deletions precompile/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
forge build --extra-output-files bin --extra-output-files abi --root .

for dir in ./out/*/
do
NAME=$(basename $dir)
NAME=${NAME%.sol}
NAME_LOWER=$(echo "${NAME:1}" | tr '[:upper:]' '[:lower:]')
abigen --pkg bindings \
--abi ./out/$NAME.sol/$NAME.abi.json \
--bin ./out/$NAME.sol/$NAME.bin \
--out ./bindings/i_${NAME_LOWER}.abigen.go \
--type ${NAME:1}
done

0 comments on commit 870b51c

Please sign in to comment.