Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stateful precompiles #42

Open
wants to merge 9 commits into
base: release/1.13
Choose a base branch
from
Prev Previous commit
Next Next commit
add precompile gen script
  • Loading branch information
mycodecrafting committed Mar 6, 2024
commit 870b51c53b311775785d1bbf64a9a687deb6942e
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