diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..aa77653 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Build + run: cargo build --release + + format-and-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Check formatting + run: cargo fmt --all --check + + - name: Run clippy + run: cargo clippy --all-targets --all-features --workspace -- -D warnings diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6ff174c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2865 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "alloy-eip2124" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "741bdd7499908b3aa0b159bba11e71c8cddd009a2c2eb7a06e825f1ec87900a5" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "crc", + "serde", + "thiserror", +] + +[[package]] +name = "alloy-eip2930" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b82752a889170df67bbb36d42ca63c531eb16274f0d7299ae2a680facba17bd" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "serde", +] + +[[package]] +name = "alloy-eip7702" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d4769c6ffddca380b0070d71c8b7f30bed375543fe76bb2f74ec0acf4b7cd16" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "k256", + "serde", + "thiserror", +] + +[[package]] +name = "alloy-eips" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac7f1c9a1ccc7f3e03c36976455751a6166a4f0d2d2c530c3f87dfe7d0cdc836" +dependencies = [ + "alloy-eip2124", + "alloy-eip2930", + "alloy-eip7702", + "alloy-primitives", + "alloy-rlp", + "alloy-serde", + "auto_impl", + "c-kzg", + "derive_more", + "either", + "serde", + "serde_with", + "sha2", + "thiserror", +] + +[[package]] +name = "alloy-primitives" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b77f7d5e60ad8ae6bd2200b8097919712a07a6db622a4b201e7ead6166f02e5" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more", + "foldhash", + "hashbrown 0.16.0", + "indexmap 2.11.4", + "itoa", + "k256", + "keccak-asm", + "paste", + "proptest", + "rand 0.9.2", + "ruint", + "rustc-hash", + "serde", + "sha3", + "tiny-keccak", +] + +[[package]] +name = "alloy-rlp" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f70d83b765fdc080dbcd4f4db70d8d23fe4761f2f02ebfa9146b833900634b4" +dependencies = [ + "alloy-rlp-derive", + "arrayvec", + "bytes", +] + +[[package]] +name = "alloy-rlp-derive" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64b728d511962dda67c1bc7ea7c03736ec275ed2cf4c35d9585298ac9ccf3b73" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "alloy-serde" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5413814be7a22fbc81e0f04a2401fcc3eb25e56fd53b04683e8acecc6e1fe01b" +dependencies = [ + "alloy-primitives", + "serde", + "serde_json", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "ark-bls12-381" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df4dcc01ff89867cd86b0da835f23c3f02738353aaee7dde7495af71363b8d5" +dependencies = [ + "ark-ec", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", +] + +[[package]] +name = "ark-bn254" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d69eab57e8d2663efa5c63135b2af4f396d66424f88954c21104125ab6b3e6bc" +dependencies = [ + "ark-ec", + "ark-ff 0.5.0", + "ark-r1cs-std", + "ark-std 0.5.0", +] + +[[package]] +name = "ark-ec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d68f2d516162846c1238e755a7c4d131b892b70cc70c471a8e3ca3ed818fce" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-poly", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.5", + "itertools 0.13.0", + "num-bigint", + "num-integer", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm 0.3.0", + "ark-ff-macros 0.3.0", + "ark-serialize 0.3.0", + "ark-std 0.3.0", + "derivative", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.3.3", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.4.1", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a177aba0ed1e0fbb62aa9f6d0502e9b46dad8c2eab04c14258a1212d2557ea70" +dependencies = [ + "ark-ff-asm 0.5.0", + "ark-ff-macros 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "educe", + "itertools 0.13.0", + "num-bigint", + "num-traits", + "paste", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-asm" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" +dependencies = [ + "quote", + "syn 2.0.106", +] + +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint", + "num-traits", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09be120733ee33f7693ceaa202ca41accd5653b779563608f1234f78ae07c4b3" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "ark-poly" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579305839da207f02b89cd1679e50e67b4331e2f9294a57693e5051b7703fe27" +dependencies = [ + "ahash", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "ark-std 0.5.0", + "educe", + "fnv", + "hashbrown 0.15.5", +] + +[[package]] +name = "ark-r1cs-std" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941551ef1df4c7a401de7068758db6503598e6f01850bdb2cfdb614a1f9dbea1" +dependencies = [ + "ark-ec", + "ark-ff 0.5.0", + "ark-relations", + "ark-std 0.5.0", + "educe", + "num-bigint", + "num-integer", + "num-traits", + "tracing", +] + +[[package]] +name = "ark-relations" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec46ddc93e7af44bcab5230937635b06fb5744464dd6a7e7b083e80ebd274384" +dependencies = [ + "ark-ff 0.5.0", + "ark-std 0.5.0", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-std 0.3.0", + "digest 0.9.0", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f4d068aaf107ebcd7dfb52bc748f8030e0fc930ac8e360146ca54c1203088f7" +dependencies = [ + "ark-serialize-derive", + "ark-std 0.5.0", + "arrayvec", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "ark-std" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246a225cc6131e9ee4f24619af0f19d67761fff15d7ccc22e42b80846e69449a" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "aurora-engine-modexp" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "518bc5745a6264b5fd7b09dffb9667e400ee9e2bbe18555fac75e1fe9afa0df9" +dependencies = [ + "hex", + "num", +] + +[[package]] +name = "auto_impl" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdcb70bdbc4d478427380519163274ac86e52916e10f0a8889adf0f96d3fee7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" + +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + +[[package]] +name = "bitcoin-io" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf" + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative", +] + +[[package]] +name = "bitflags" +version = "2.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +dependencies = [ + "serde", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "serde", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blst" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcdb4c7013139a150f9fc55d123186dbfaba0d912817466282c73ac49e71fb45" +dependencies = [ + "cc", + "glob", + "threadpool", + "zeroize", +] + +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + +[[package]] +name = "byte-slice-cast" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +dependencies = [ + "serde", +] + +[[package]] +name = "c-kzg" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e00bf4b112b07b505472dbefd19e37e53307e2bfed5a79e0cc161d58ccd0e687" +dependencies = [ + "blst", + "cc", + "glob", + "hex", + "libc", + "once_cell", + "serde", +] + +[[package]] +name = "cc" +version = "1.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" + +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "const-hex" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6407bff74dea37e0fa3dc1c1c974e5d46405f0c987bf9997a0762adce71eda6" +dependencies = [ + "cfg-if", + "cpufeatures", + "proptest", + "serde_core", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "const_format" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.106", +] + +[[package]] +name = "darling_macro" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071" +dependencies = [ + "powerfmt", + "serde_core", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive-where" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef941ded77d15ca19b40374869ac6000af1c9f2a4c0f3d4c70926287e6364a8f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", + "unicode-xid", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "educe" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7bc049e1bd8cdeb31b68bbd586a9464ecf9f3944af3958a7a9d0f8b9799417" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "enum-ordinalize" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea0dcfa4e54eeb516fe454635a95753ddd39acda650ce703031c6973e315dd5" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.1", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "fastrlp" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139834ddba373bbdd213dffe02c8d110508dcf1726c2be27e8d1f7d7e1856418" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", +] + +[[package]] +name = "fastrlp" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce8dba4714ef14b8274c371879b175aa55b16b30f269663f19d576f380018dc4" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", +] + +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand 0.8.5", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.7+wasi-0.2.4", +] + +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "gmp-mpfr-sys" +version = "1.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60f8970a75c006bb2f8ae79c6768a116dd215fa8346a87aed99bf9d82ca43394" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", +] + +[[package]] +name = "hashbrown" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" +dependencies = [ + "foldhash", + "serde", +] + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" +dependencies = [ + "equivalent", + "hashbrown 0.16.0", + "serde", + "serde_core", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "k256" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "keccak-asm" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "505d1856a39b200489082f90d897c3f07c455563880bc5952e38eabf731c83b6" +dependencies = [ + "digest 0.10.7", + "sha3-asm", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.176" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" + +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_enum" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + +[[package]] +name = "parity-scale-codec" +version = "3.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799781ae679d79a948e13d4824a40970bfa500058d245760dd857301059810fa" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "const_format", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "rustversion", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34b4653168b563151153c9e4c08ebed57fb8262bebfa79711552fa983c623e7a" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pest" +version = "2.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e0a3a33733faeaf8651dfee72dd0f388f0c8e5ad496a3478fa5a922f49cfa8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "phf" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" +dependencies = [ + "phf_macros", + "phf_shared", + "serde", +] + +[[package]] +name = "phf_generator" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737" +dependencies = [ + "fastrand", + "phf_shared", +] + +[[package]] +name = "phf_macros" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb0be07becd10686a0bb407298fb425360a5c44a663774406340c59a22de4ce" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags", + "lazy_static", + "num-traits", + "rand 0.9.2", + "rand_chacha 0.9.0", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", + "serde", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.16", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.3", + "serde", +] + +[[package]] +name = "rand_xorshift" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core 0.9.3", +] + +[[package]] +name = "ref-cast" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "regex-syntax" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" + +[[package]] +name = "revm" +version = "31.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb67a5223602113cae59a305acde2d9936bc18f2478dda879a6124b267cebfb6" +dependencies = [ + "revm-bytecode", + "revm-context", + "revm-context-interface", + "revm-database", + "revm-database-interface", + "revm-handler", + "revm-inspector", + "revm-interpreter", + "revm-precompile", + "revm-primitives", + "revm-state", +] + +[[package]] +name = "revm-bytecode" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2c6b5e6e8dd1e28a4a60e5f46615d4ef0809111c9e63208e55b5c7058200fb0" +dependencies = [ + "bitvec", + "phf", + "revm-primitives", + "serde", +] + +[[package]] +name = "revm-context" +version = "11.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92850e150f4f99d46c05a20ad0cd09286a7ad4ee21866fffb87101de6e602231" +dependencies = [ + "bitvec", + "cfg-if", + "derive-where", + "revm-bytecode", + "revm-context-interface", + "revm-database-interface", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-context-interface" +version = "12.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6d701e2c2347d65216b066489ab22a0a8e1f7b2568256110d73a7d5eff3385c" +dependencies = [ + "alloy-eip2930", + "alloy-eip7702", + "auto_impl", + "either", + "revm-database-interface", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-database" +version = "9.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "980d8d6bba78c5dd35b83abbb6585b0b902eb25ea4448ed7bfba6283b0337191" +dependencies = [ + "alloy-eips", + "revm-bytecode", + "revm-database-interface", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-database-interface" +version = "8.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cce03e3780287b07abe58faf4a7f5d8be7e81321f93ccf3343c8f7755602bae" +dependencies = [ + "auto_impl", + "either", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-handler" +version = "12.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45418ed95cfdf0cb19effdbb7633cf2144cab7fb0e6ffd6b0eb9117a50adff6" +dependencies = [ + "auto_impl", + "derive-where", + "revm-bytecode", + "revm-context", + "revm-context-interface", + "revm-database-interface", + "revm-interpreter", + "revm-precompile", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-inspector" +version = "12.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c99801eac7da06cc112df2244bd5a64024f4ef21240e923b26e73c4b4a0e5da6" +dependencies = [ + "auto_impl", + "either", + "revm-context", + "revm-database-interface", + "revm-handler", + "revm-interpreter", + "revm-primitives", + "revm-state", + "serde", + "serde_json", +] + +[[package]] +name = "revm-interpreter" +version = "29.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22789ce92c5808c70185e3bc49732f987dc6fd907f77828c8d3470b2299c9c65" +dependencies = [ + "revm-bytecode", + "revm-context-interface", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-precompile" +version = "29.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "968b124028960201abf6d6bf8e223f15fadebb4307df6b7dc9244a0aab5d2d05" +dependencies = [ + "ark-bls12-381", + "ark-bn254", + "ark-ec", + "ark-ff 0.5.0", + "ark-serialize 0.5.0", + "arrayref", + "aurora-engine-modexp", + "blst", + "c-kzg", + "cfg-if", + "k256", + "p256", + "revm-primitives", + "ripemd", + "rug", + "secp256k1", + "sha2", +] + +[[package]] +name = "revm-primitives" +version = "21.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e161db429d465c09ba9cbff0df49e31049fe6b549e28eb0b7bd642fcbd4412" +dependencies = [ + "alloy-primitives", + "num_enum", + "once_cell", + "serde", +] + +[[package]] +name = "revm-state" +version = "8.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d8be953b7e374dbdea0773cf360debed8df394ea8d82a8b240a6b5da37592fc" +dependencies = [ + "bitflags", + "revm-bytecode", + "revm-primitives", + "serde", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "rustc-hex", +] + +[[package]] +name = "rug" +version = "1.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58ad2e973fe3c3214251a840a621812a4f40468da814b1a3d6947d433c2af11f" +dependencies = [ + "az", + "gmp-mpfr-sys", + "libc", + "libm", +] + +[[package]] +name = "ruint" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68df0380e5c9d20ce49534f292a36a7514ae21350726efe1865bdb1fa91d278" +dependencies = [ + "alloy-rlp", + "ark-ff 0.3.0", + "ark-ff 0.4.2", + "ark-ff 0.5.0", + "bytes", + "fastrlp 0.3.1", + "fastrlp 0.4.0", + "num-bigint", + "num-integer", + "num-traits", + "parity-scale-codec", + "primitive-types", + "proptest", + "rand 0.8.5", + "rand 0.9.2", + "rlp", + "ruint-macro", + "serde_core", + "valuable", + "zeroize", +] + +[[package]] +name = "ruint-macro" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver 1.0.27", +] + +[[package]] +name = "rustix" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.1", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "secp256k1" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3c81b43dc2d8877c216a3fccf76677ee1ebccd429566d3e67447290d0c42b2" +dependencies = [ + "bitcoin_hashes", + "rand 0.9.2", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb913707158fadaf0d8702c2db0e857de66eb003ccfdda5924b5f5ac98efb38" +dependencies = [ + "cc", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "semver-parser" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9900206b54a3527fdc7b8a938bffd94a568bac4f4aa8113b209df75a09c0dec2" +dependencies = [ + "pest", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "indexmap 2.11.4", + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "serde_with" +version = "3.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c522100790450cf78eeac1507263d0a350d4d5b30df0c8e1fe051a10c22b376e" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.11.4", + "schemars 0.9.0", + "schemars 1.0.4", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327ada00f7d64abaac1e55a6911e90cf665aa051b9a561c7006c157f4633135e" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "sha3-asm" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28efc5e327c837aa837c59eae585fc250715ef939ac32881bcc11677cd02d46" +dependencies = [ + "cc", + "cfg-if", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" +dependencies = [ + "fastrand", + "getrandom 0.3.3", + "once_cell", + "rustix", + "windows-sys 0.61.1", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "time" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "toml_datetime" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f1085dec27c2b6632b04c80b3bb1b4300d6495d1e129693bdda7d91e72eec1" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.23.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3effe7c0e86fdff4f69cdd2ccc1b96f933e24811c5441d44904e8683e27184b" +dependencies = [ + "indexmap 2.11.4", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cf893c33be71572e0e9aa6dd15e6677937abd686b066eac3f8cd3531688a627" +dependencies = [ + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "tracing-core" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "tracing-core", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasi" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn 2.0.106", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.62.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6844ee5416b285084d3d3fffd743b925a6c9385455f64f6d4fa3031c4c2749a9" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edb307e42a74fb6de9bf3a02d9712678b22399c87e6fa869d6dfcd8c1b7754e0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "windows-interface" +version = "0.59.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0abd1ddbc6964ac14db11c7213d6532ef34bd9aa042c2e5935f59d7908b46a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "windows-link" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" + +[[package]] +name = "windows-result" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7084dcc306f89883455a206237404d3eaf961e5bd7e0f312f7c91f57eb44167f" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7218c655a553b0bed4426cf54b20d7ba363ef543b52d515b3e48d7fd55318dda" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f109e41dd4a3c848907eb83d5a42ea98b3769495597450cf6d153507b166f0f" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.53.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d42b7b7f66d2a06854650af09cfdf8713e427a439c97ad65a6375318033ac4b" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "winnow" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zerocopy" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "zksync-os-revm" +version = "0.1.0" +dependencies = [ + "auto_impl", + "revm", + "serde", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..cd69960 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "zksync-os-revm" +authors = ["The Matter Labs Team "] +homepage = "https://zksync.io/" +repository = "https://github.com/matter-labs/zksync-os-revm" +version = "0.1.0" +edition = "2024" +license = "MIT OR Apache-2.0" +keywords = ["blockchain", "zksync"] +categories = ["cryptography"] + +[dependencies] +revm = { version = "=31.0.2", features = ["optional_balance_check"] } +auto_impl = "1.3.0" +serde = { version = "1", features = ["derive"] } + diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..2bb9ad2 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..8a4966f --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Matter Labs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index a4f3cdd..8ae7e80 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ -# zksync-os-revm -REVM extension with ZKsync OS compatibility +# ZKsync OS REVM + +This repo contains the custom EVM implementation compatible with the ZKsync OS execution environment based on REVM. In addition to standard EVM functionality, it supports ZKsync OS extensions: +- ZKsync L1 -> L2 transactions +- ZKsync upgrade transaction +- ZKsync OS hooks + - Deployer + - L2 -> L1 messenger + - L2 Base token + +This code can be used as an alternative implementation of ZKsync OS, but its primary use for now is the consistency checker in the ZKsync OS server. The ZKsync OS server executes transactions in its native environment and then re-executes the transactions on this variant of REVM. + +### Gas override & transaction force failing + +One of the specific features implemented for the consistency checker is gas override. The transaction may provide a `gas_used`. This value will be used as the amount of gas used by the transaction instead of vanilla EVM. This is needed because ZKsync OS has a concept of double accounting, and when a transaction uses a lot of native resources, the user is charged more gas at the end of the transaction. + +The other feature is force transaction failing. When the transaction has the `force_fail` flag set to `true`, REVM assumes the transaction will fail and skips execution while bumping the nonce and charging fees. This is needed for simpler re-execution in the main ZKsync OS node. diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..5c62bd7 --- /dev/null +++ b/src/api.rs @@ -0,0 +1,9 @@ +//! API types. + +pub mod builder; +pub mod default_ctx; +pub mod exec; + +pub use builder::ZkBuilder; +pub use default_ctx::DefaultZk; +pub use exec::{ZkContextTr, ZkError}; diff --git a/src/api/builder.rs b/src/api/builder.rs new file mode 100644 index 0000000..dcf83ab --- /dev/null +++ b/src/api/builder.rs @@ -0,0 +1,51 @@ +//! Builder trait [`ZkBuilder`] used to build [`ZKsyncEvm`]. +use crate::{ZkSpecId, evm::ZKsyncEvm, precompiles::ZKsyncPrecompiles, transaction::ZkTxTr}; +use revm::{ + Context, Database, + context::{Cfg, ContextTr}, + context_interface::{Block, JournalTr}, + handler::instructions::EthInstructions, + interpreter::interpreter::EthInterpreter, + state::EvmState, +}; + +/// Type alias for default ZKsyncEvm +pub type DefaultZKsyncEvm = + ZKsyncEvm, ZKsyncPrecompiles>; + +/// Trait that allows for ZKsyncEvm to be built. +pub trait ZkBuilder: Sized { + /// Type of the context. + type Context: ContextTr; + + /// Build the ZKsync OS EVM. + fn build_zk(self) -> DefaultZKsyncEvm; + + /// Build the ZKsync OS EVM with an inspector. + fn build_zk_with_inspector( + self, + inspector: INSP, + ) -> DefaultZKsyncEvm; +} + +impl ZkBuilder for Context +where + BLOCK: Block, + TX: ZkTxTr, + CFG: Cfg, + DB: Database, + JOURNAL: JournalTr, +{ + type Context = Self; + + fn build_zk(self) -> DefaultZKsyncEvm { + ZKsyncEvm::new(self, ()) + } + + fn build_zk_with_inspector( + self, + inspector: INSP, + ) -> DefaultZKsyncEvm { + ZKsyncEvm::new(self, inspector) + } +} diff --git a/src/api/default_ctx.rs b/src/api/default_ctx.rs new file mode 100644 index 0000000..949e083 --- /dev/null +++ b/src/api/default_ctx.rs @@ -0,0 +1,45 @@ +//! Contains trait [`DefaultZk`] used to create a default context. +use crate::{ZKsyncTx, ZkSpecId}; +use revm::{ + Context, Journal, MainContext, + context::{BlockEnv, CfgEnv, TxEnv}, + database_interface::EmptyDB, +}; + +/// Type alias for the default context type of the ZKsyncEvm. +pub type ZkContext = Context, CfgEnv, DB, Journal>; + +/// Trait that allows for a default context to be created. +pub trait DefaultZk { + /// Create a default context. + fn default() -> ZkContext; +} + +impl DefaultZk for ZkContext { + fn default() -> Self { + Context::mainnet() + .with_tx(ZKsyncTx::builder().build_fill()) + .with_cfg(CfgEnv::new_with_spec(ZkSpecId::AtlasV2)) + } +} + +#[cfg(test)] +mod test { + use super::*; + use crate::api::builder::ZkBuilder; + use revm::{ + ExecuteEvm, + inspector::{InspectEvm, NoOpInspector}, + }; + + #[test] + fn default_run_zk() { + let ctx = Context::default(); + // convert to ZKsync OS context + let mut evm = ctx.build_zk_with_inspector(NoOpInspector {}); + // execute + let _ = evm.transact(ZKsyncTx::builder().build_fill()); + // inspect + let _ = evm.inspect_one_tx(ZKsyncTx::builder().build_fill()); + } +} diff --git a/src/api/exec.rs b/src/api/exec.rs new file mode 100644 index 0000000..7678459 --- /dev/null +++ b/src/api/exec.rs @@ -0,0 +1,156 @@ +//! Implementation of the [`ExecuteEvm`] trait for the [`ZKsyncEvm`]. +use crate::{ZKsyncTxError, ZkSpecId, evm::ZKsyncEvm, handler::ZKsyncHandler, transaction::ZkTxTr}; +use revm::{ + DatabaseCommit, ExecuteCommitEvm, ExecuteEvm, + context::{ContextSetters, result::ExecResultAndState}, + context_interface::{ + Cfg, ContextTr, Database, JournalTr, + result::{EVMError, ExecutionResult, HaltReason}, + }, + handler::{ + EthFrame, Handler, PrecompileProvider, SystemCallTx, instructions::EthInstructions, + system_call::SystemCallEvm, + }, + inspector::{ + InspectCommitEvm, InspectEvm, InspectSystemCallEvm, Inspector, InspectorHandler, JournalExt, + }, + interpreter::{InterpreterResult, interpreter::EthInterpreter}, + primitives::{Address, Bytes}, + state::EvmState, +}; + +/// Type alias for ZKsync OS context +pub trait ZkContextTr: + ContextTr, Tx: ZkTxTr, Cfg: Cfg> +{ +} + +impl ZkContextTr for T where + T: ContextTr, Tx: ZkTxTr, Cfg: Cfg> +{ +} + +/// Type alias for the error type of the ZKsyncEvm. +pub type ZkError = EVMError<<::Db as Database>::Error, ZKsyncTxError>; + +impl ExecuteEvm + for ZKsyncEvm, PRECOMPILE> +where + CTX: ZkContextTr + ContextSetters, + PRECOMPILE: PrecompileProvider, +{ + type Tx = ::Tx; + type Block = ::Block; + type State = EvmState; + type Error = ZkError; + type ExecutionResult = ExecutionResult; + + fn set_block(&mut self, block: Self::Block) { + self.0.ctx.set_block(block); + } + + fn transact_one(&mut self, tx: Self::Tx) -> Result { + self.0.ctx.set_tx(tx); + let mut h = ZKsyncHandler::<_, _, EthFrame>::new(); + h.run(self) + } + + fn finalize(&mut self) -> Self::State { + self.0.ctx.journal_mut().finalize() + } + + fn replay( + &mut self, + ) -> Result, Self::Error> { + let mut h = ZKsyncHandler::<_, _, EthFrame>::new(); + h.run(self).map(|result| { + let state = self.finalize(); + ExecResultAndState::new(result, state) + }) + } +} + +impl ExecuteCommitEvm + for ZKsyncEvm, PRECOMPILE> +where + CTX: ZkContextTr + ContextSetters, + PRECOMPILE: PrecompileProvider, +{ + fn commit(&mut self, state: Self::State) { + self.0.ctx.db_mut().commit(state); + } +} + +impl InspectEvm + for ZKsyncEvm, PRECOMPILE> +where + CTX: ZkContextTr + ContextSetters, + INSP: Inspector, + PRECOMPILE: PrecompileProvider, +{ + type Inspector = INSP; + + fn set_inspector(&mut self, inspector: Self::Inspector) { + self.0.inspector = inspector; + } + + fn inspect_one_tx(&mut self, tx: Self::Tx) -> Result { + self.0.ctx.set_tx(tx); + let mut h = ZKsyncHandler::<_, _, EthFrame>::new(); + h.inspect_run(self) + } +} + +impl InspectCommitEvm + for ZKsyncEvm, PRECOMPILE> +where + CTX: ZkContextTr + ContextSetters, + INSP: Inspector, + PRECOMPILE: PrecompileProvider, +{ +} + +impl SystemCallEvm + for ZKsyncEvm, PRECOMPILE> +where + CTX: ZkContextTr + ContextSetters, + PRECOMPILE: PrecompileProvider, +{ + fn system_call_one_with_caller( + &mut self, + caller: Address, + system_contract_address: Address, + data: Bytes, + ) -> Result { + self.0.ctx.set_tx(CTX::Tx::new_system_tx_with_caller( + caller, + system_contract_address, + data, + )); + let mut h = ZKsyncHandler::<_, _, EthFrame>::new(); + h.run_system_call(self) + } +} + +impl InspectSystemCallEvm + for ZKsyncEvm, PRECOMPILE> +where + CTX: ZkContextTr + ContextSetters, + INSP: Inspector, + PRECOMPILE: PrecompileProvider, +{ + fn inspect_one_system_call_with_caller( + &mut self, + caller: Address, + system_contract_address: Address, + data: Bytes, + ) -> Result { + self.0.ctx.set_tx(CTX::Tx::new_system_tx_with_caller( + caller, + system_contract_address, + data, + )); + let mut h = ZKsyncHandler::<_, _, EthFrame>::new(); + h.inspect_run_system_call(self) + } +} diff --git a/src/evm.rs b/src/evm.rs new file mode 100644 index 0000000..964cb8a --- /dev/null +++ b/src/evm.rs @@ -0,0 +1,212 @@ +//! Contains the `[ZKsyncEvm]` type and its implementation of the execution EVM traits. +use crate::{ZkSpecId, precompiles::ZKsyncPrecompiles}; +use revm::{ + Database, Inspector, + context::{Cfg, ContextError, ContextSetters, Evm, FrameStack}, + context_interface::ContextTr, + handler::{ + EthFrame, EvmTr, FrameInitOrResult, ItemOrResult, PrecompileProvider, + evm::FrameTr, + instructions::{EthInstructions, InstructionProvider}, + }, + inspector::{InspectorEvmTr, JournalExt}, + interpreter::{InterpreterResult, interpreter::EthInterpreter}, +}; + +/// ZKsync OS EVM extends the [`Evm`] type with specific types and logic. +#[derive(Debug, Clone)] +pub struct ZKsyncEvm< + CTX, + INSP, + I = EthInstructions, + P = ZKsyncPrecompiles, + F = EthFrame, +>( + /// Inner EVM type. + pub Evm, +); + +impl>, INSP> + ZKsyncEvm, ZKsyncPrecompiles> +{ + /// Create a new ZKsync OS EVM. + pub fn new(ctx: CTX, inspector: INSP) -> Self { + Self(Evm { + precompiles: ZKsyncPrecompiles::new_with_spec(ctx.cfg().spec()), + ctx, + inspector, + instruction: EthInstructions::new_mainnet(), + frame_stack: FrameStack::new(), + }) + } +} + +impl ZKsyncEvm { + /// Consumed self and returns a new Evm type with given Inspector. + pub fn with_inspector(self, inspector: OINSP) -> ZKsyncEvm { + ZKsyncEvm(self.0.with_inspector(inspector)) + } + + /// Consumes self and returns a new Evm type with given Precompiles. + pub fn with_precompiles(self, precompiles: OP) -> ZKsyncEvm { + ZKsyncEvm(self.0.with_precompiles(precompiles)) + } + + /// Consumes self and returns the inner Inspector. + pub fn into_inspector(self) -> INSP { + self.0.into_inspector() + } +} + +impl InspectorEvmTr for ZKsyncEvm +where + CTX: ContextTr + ContextSetters, + I: InstructionProvider, + P: PrecompileProvider, + INSP: Inspector, +{ + type Inspector = INSP; + + fn all_inspector( + &self, + ) -> ( + &Self::Context, + &Self::Instructions, + &Self::Precompiles, + &FrameStack, + &Self::Inspector, + ) { + self.0.all_inspector() + } + + fn all_mut_inspector( + &mut self, + ) -> ( + &mut Self::Context, + &mut Self::Instructions, + &mut Self::Precompiles, + &mut FrameStack, + &mut Self::Inspector, + ) { + self.0.all_mut_inspector() + } + + fn inspector(&mut self) -> &mut Self::Inspector { + &mut self.0.inspector + } + + fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) { + (&mut self.0.ctx, &mut self.0.inspector) + } + + fn ctx_inspector_frame( + &mut self, + ) -> (&mut Self::Context, &mut Self::Inspector, &mut Self::Frame) { + ( + &mut self.0.ctx, + &mut self.0.inspector, + self.0.frame_stack.get(), + ) + } + + fn ctx_inspector_frame_instructions( + &mut self, + ) -> ( + &mut Self::Context, + &mut Self::Inspector, + &mut Self::Frame, + &mut Self::Instructions, + ) { + ( + &mut self.0.ctx, + &mut self.0.inspector, + self.0.frame_stack.get(), + &mut self.0.instruction, + ) + } +} + +impl EvmTr for ZKsyncEvm> +where + CTX: ContextTr, + I: InstructionProvider, + P: PrecompileProvider, +{ + type Context = CTX; + type Instructions = I; + type Precompiles = P; + type Frame = EthFrame; + + fn all( + &self, + ) -> ( + &Self::Context, + &Self::Instructions, + &Self::Precompiles, + &FrameStack, + ) { + self.0.all() + } + + fn all_mut( + &mut self, + ) -> ( + &mut Self::Context, + &mut Self::Instructions, + &mut Self::Precompiles, + &mut FrameStack, + ) { + self.0.all_mut() + } + + fn ctx(&mut self) -> &mut Self::Context { + &mut self.0.ctx + } + + fn ctx_ref(&self) -> &Self::Context { + &self.0.ctx + } + + fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions) { + (&mut self.0.ctx, &mut self.0.instruction) + } + + fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) { + (&mut self.0.ctx, &mut self.0.precompiles) + } + + fn frame_stack(&mut self) -> &mut FrameStack { + &mut self.0.frame_stack + } + + fn frame_init( + &mut self, + frame_input: ::FrameInit, + ) -> Result< + ItemOrResult<&mut Self::Frame, ::FrameResult>, + ContextError<<::Db as Database>::Error>, + > { + self.0.frame_init(frame_input) + } + + fn frame_run( + &mut self, + ) -> Result< + FrameInitOrResult, + ContextError<<::Db as Database>::Error>, + > { + self.0.frame_run() + } + + #[doc = " Returns the result of the frame to the caller. Frame is popped from the frame stack."] + #[doc = " Consumes the frame result or returns it if there is more frames to run."] + fn frame_return_result( + &mut self, + result: ::FrameResult, + ) -> Result< + Option<::FrameResult>, + ContextError<<::Db as Database>::Error>, + > { + self.0.frame_return_result(result) + } +} diff --git a/src/handler.rs b/src/handler.rs new file mode 100644 index 0000000..72eff94 --- /dev/null +++ b/src/handler.rs @@ -0,0 +1,328 @@ +//!Handler related to ZKsync OS chain +use std::boxed::Box; + +use crate::{ + api::exec::ZkContextTr, + transaction::{ZKsyncTxError, ZkTxTr}, +}; +use revm::{ + context::{LocalContextTr, result::InvalidTransaction}, + context_interface::{ + Block, Cfg, ContextTr, JournalTr, Transaction, + context::ContextError, + result::{EVMError, ExecutionResult, FromStringError, HaltReason}, + }, + handler::{ + EthFrame, EvmTr, FrameResult, Handler, MainnetHandler, + evm::FrameTr, + handler::EvmTrError, + post_execution::{self, reimburse_caller}, + pre_execution::validate_account_nonce_and_code, + }, + inspector::{Inspector, InspectorEvmTr, InspectorHandler}, + interpreter::{ + CallOutcome, Gas, InitialAndFloorGas, InstructionResult, InterpreterResult, + interpreter::EthInterpreter, interpreter_action::FrameInit, + }, + primitives::U256, +}; + +/// ZKsync OS handler extends the [`Handler`] with ZKsync OS specific logic. +#[derive(Debug, Clone)] +pub struct ZKsyncHandler { + /// Mainnet handler allows us to use functions from the mainnet handler inside ZKsync OS handler. + /// So we dont duplicate the logic + pub mainnet: MainnetHandler, + /// Phantom data to avoid type inference issues. + pub _phantom: core::marker::PhantomData<(EVM, ERROR, FRAME)>, +} + +impl ZKsyncHandler { + /// Create a new ZKsync OS handler. + pub fn new() -> Self { + Self { + mainnet: MainnetHandler::default(), + _phantom: core::marker::PhantomData, + } + } +} + +impl Default for ZKsyncHandler { + fn default() -> Self { + Self::new() + } +} + +/// Trait to check if the error is a transaction error. +/// +/// Used in cache_error handler to catch deposit transaction that was halted. +pub trait IsTxError { + /// Check if the error is a transaction error. + fn is_tx_error(&self) -> bool; +} + +impl IsTxError for EVMError { + fn is_tx_error(&self) -> bool { + matches!(self, EVMError::Transaction(_)) + } +} + +impl Handler for ZKsyncHandler +where + EVM: EvmTr, + ERROR: EvmTrError + From + FromStringError + IsTxError, + FRAME: FrameTr, +{ + type Evm = EVM; + type Error = ERROR; + type HaltReason = HaltReason; + + fn validate_env(&self, evm: &mut Self::Evm) -> Result<(), Self::Error> { + // Do not perform any additional validation for L1 -> L2 transactions, they are pre-verified on Settlement Layer. + let ctx = evm.ctx(); + let tx = ctx.tx(); + if tx.is_l1_to_l2_tx() { + return Ok(()); + } + + // Do not perform any extra validation for L1 -> L2 transactions, they are pre-verified on L1. + self.mainnet.validate_env(evm) + } + + #[inline] + fn post_execution( + &self, + evm: &mut Self::Evm, + exec_result: &mut FrameResult, + init_and_floor_gas: InitialAndFloorGas, + eip7702_gas_refund: i64, + ) -> Result<(), Self::Error> { + if let Some(gas_used_override) = evm.ctx().tx().gas_used_override() { + let gas_limit = evm.ctx().tx().gas_limit(); + // Just in case use at most `gas_limit` gas to prevent the underflow + let used = gas_used_override.min(gas_limit); + let unused = gas_limit - used; + + // Rewrite the Gas object to match ZKsync OS usage. + let gas = exec_result.gas_mut(); + *gas = Gas::new_spent(gas_limit); + gas.erase_cost(unused); + // IMPORTANT: ignore EVM-native refunds: (do NOT call `gas.record_refund(...)` here) + // self.refund(evm, exec_result, eip7702_gas_refund); // <-- intentionally NOT called + + // Reimburse sender and reward beneficiary using the rewritten Gas. + self.reimburse_caller(evm, exec_result)?; + self.reward_beneficiary(evm, exec_result)?; + } else { + // Vanilla path: keep default EVM accounting + self.refund(evm, exec_result, eip7702_gas_refund); + self.eip7623_check_gas_floor(evm, exec_result, init_and_floor_gas); + self.reimburse_caller(evm, exec_result)?; + self.reward_beneficiary(evm, exec_result)?; + } + + Ok(()) + } + + fn validate_against_state_and_deduct_caller( + &self, + evm: &mut Self::Evm, + ) -> Result<(), Self::Error> { + let ctx = evm.ctx(); + + let basefee = ctx.block().basefee() as u128; + let blob_price = ctx.block().blob_gasprice().unwrap_or_default(); + let is_l1_to_l2_tx = ctx.tx().is_l1_to_l2_tx(); + let is_eip3607_disabled = ctx.cfg().is_eip3607_disabled(); + let is_nonce_check_disabled = ctx.cfg().is_nonce_check_disabled(); + + let mint = ctx.tx().mint().unwrap_or_default(); + + let (tx, journal) = ctx.tx_journal_mut(); + + let mut caller_account = journal.load_account_with_code_mut(tx.caller())?.data; + + if !is_l1_to_l2_tx { + // validates account nonce and code + validate_account_nonce_and_code( + &caller_account.info, + tx.nonce(), + is_eip3607_disabled, + is_nonce_check_disabled, + )?; + } + + let mut new_balance = caller_account.info.balance.saturating_add(U256::from(mint)); + + let max_balance_spending = tx.max_balance_spending()?; + + if !is_l1_to_l2_tx && max_balance_spending > new_balance { + // skip max balance check for deposit transactions. + // this check for deposit was skipped previously in `validate_tx_against_state` function + return Err(InvalidTransaction::LackOfFundForMaxFee { + fee: Box::new(max_balance_spending), + balance: Box::new(new_balance), + } + .into()); + } + + let effective_balance_spending = tx + .effective_balance_spending(basefee, blob_price) + .expect("effective balance is always smaller than max balance so it can't overflow"); + + // subtracting max balance spending with value that is going to be deducted later in the call. + let gas_balance_spending = effective_balance_spending - tx.value(); + + new_balance = new_balance.saturating_sub(gas_balance_spending); + + // Touch account so we know it is changed. + caller_account.touch(); + caller_account.set_balance(new_balance); + + // Bump the nonce for calls. Nonce for CREATE will be bumped in `handle_create`. + if !is_l1_to_l2_tx && tx.kind().is_call() { + caller_account.bump_nonce(); + } + + Ok(()) + } + + fn reimburse_caller( + &self, + evm: &mut Self::Evm, + frame_result: &mut <::Frame as FrameTr>::FrameResult, + ) -> Result<(), Self::Error> { + reimburse_caller(evm.ctx(), frame_result.gas(), U256::ZERO)?; + + let is_l1_to_l2_tx = evm.ctx().tx().is_l1_to_l2_tx(); + if is_l1_to_l2_tx { + let caller = evm.ctx().tx().caller(); + let refund_recipient = evm + .ctx() + .tx() + .refund_recipient() + .expect("Refund recipient is missing for L1 -> L2 tx"); + + let basefee = evm.ctx().block().basefee() as u128; + let effective_gas_price = evm.ctx().tx().effective_gas_price(basefee); + let spent_fee = + U256::from(frame_result.gas().spent()) * U256::from(effective_gas_price); + let mint = evm.ctx().tx().mint().unwrap_or_default(); + let value = evm.ctx().tx().value(); + + // Did the call succeed? + let is_success = frame_result.interpreter_result().result.is_ok(); + + let additional_refund = if is_success { + mint - value - spent_fee + } else { + mint - spent_fee + }; + + // // Return balance of not spend gas. + evm.ctx() + .journal_mut() + .transfer(caller, refund_recipient, additional_refund)?; + } + Ok(()) + } + + fn reward_beneficiary( + &self, + evm: &mut Self::Evm, + frame_result: &mut <::Frame as FrameTr>::FrameResult, + ) -> Result<(), Self::Error> { + let beneficiary = evm.ctx().block().beneficiary(); + let basefee = evm.ctx().block().basefee() as u128; + let effective_gas_price = evm.ctx().tx().effective_gas_price(basefee); + + // reward beneficiary + evm.ctx().journal_mut().balance_incr( + beneficiary, + U256::from(effective_gas_price * frame_result.gas().used() as u128), + )?; + + Ok(()) + } + + fn execution_result( + &mut self, + evm: &mut Self::Evm, + frame_result: <::Frame as FrameTr>::FrameResult, + ) -> Result, Self::Error> { + match core::mem::replace(evm.ctx().error(), Ok(())) { + Err(ContextError::Db(e)) => return Err(e.into()), + Err(ContextError::Custom(e)) => return Err(Self::Error::from_string(e)), + Ok(_) => (), + } + + let exec_result = post_execution::output(evm.ctx(), frame_result); + + evm.ctx().journal_mut().commit_tx(); + evm.ctx().local_mut().clear(); + evm.frame_stack().clear(); + + Ok(exec_result) + } + + fn run_without_catch_error( + &mut self, + evm: &mut Self::Evm, + ) -> Result, Self::Error> { + let init_and_floor_gas = self.validate(evm)?; + let eip7702_refund = self.pre_execution(evm)? as i64; + + // === forced-fail short-circuit === + let mut exec_result = if evm.ctx().tx().force_fail() { + let (tx, journal) = evm.ctx().tx_journal_mut(); + let mut caller_account = journal.load_account_with_code_mut(tx.caller())?.data; + if tx.kind().is_create() { + // Bump the nonce for creates, because usually it is handled in `handle_create`. + // And force faillure doesn't call the actual execution. + caller_account.bump_nonce(); + } + // Synthesize a top-level REVERT frame result (no state changes). + // 1) Make an InterpreterResult with REVERT + returndata. + let ir = InterpreterResult::new( + InstructionResult::Revert, + Default::default(), + Gas::new_spent(0), + ); + // 2) Wrap it as a CallOutcome; memory range is irrelevant here. + let mut fr = FrameResult::Call(CallOutcome::new(ir, 0..0)); + + let gas_limit = evm.ctx().tx().gas_limit(); + let gas_used = evm.ctx().tx().gas_used_override().unwrap_or(gas_limit); + + // 3) Set gas to match your ZK usage now (limit – unused). + let used = gas_used.min(gas_limit); + let unused = gas_limit - used; + let gas = fr.gas_mut(); + *gas = Gas::new_spent(gas_limit); + gas.erase_cost(unused); + + // Ensure gas object is initialized the same way a normal top-level return would do. + // last_frame_result() sets `Gas::new_spent(gas_limit)` and handles "remaining" & refund flags. + self.last_frame_result(evm, &mut fr)?; + + fr + } else { + self.execution(evm, &init_and_floor_gas)? + }; + + self.post_execution(evm, &mut exec_result, init_and_floor_gas, eip7702_refund)?; + self.execution_result(evm, exec_result) + } +} + +impl InspectorHandler for ZKsyncHandler> +where + EVM: InspectorEvmTr< + Context: ZkContextTr, + Frame = EthFrame, + Inspector: Inspector<<::Evm as EvmTr>::Context, EthInterpreter>, + >, + ERROR: EvmTrError + From + FromStringError + IsTxError, +{ + type IT = EthInterpreter; +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c4ca798 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,17 @@ +//! ZKsync OS specific constants, types, and helpers. +#![cfg_attr(not(test), warn(unused_crate_dependencies))] + +pub mod api; +pub mod evm; +pub mod handler; +pub mod precompiles; +pub mod spec; +pub mod transaction; + +pub use api::{ + builder::ZkBuilder, + default_ctx::{DefaultZk, ZkContext}, +}; +pub use evm::ZKsyncEvm; +pub use spec::*; +pub use transaction::{ZKsyncTx, error::ZKsyncTxError}; diff --git a/src/precompiles.rs b/src/precompiles.rs new file mode 100644 index 0000000..e600d98 --- /dev/null +++ b/src/precompiles.rs @@ -0,0 +1,163 @@ +//! Contains ZKsync OS specific precompiles. +use crate::ZkSpecId; +use revm::interpreter::CallInputs; +use revm::{ + context::Cfg, + context_interface::ContextTr, + handler::{EthPrecompiles, PrecompileProvider}, + interpreter::InterpreterResult, + precompile::{Precompiles, bn254, hash, identity, modexp, secp256k1, secp256r1}, + primitives::{Address, OnceLock}, +}; +use std::string::String; +use std::{boxed::Box, collections::HashMap}; + +pub mod calldata_view; +pub(crate) mod utils; +pub mod v1; +pub mod v2; + +use v1::deployer::CONTRACT_DEPLOYER_ADDRESS; +use v1::l1_messenger::L1_MESSENGER_ADDRESS; +use v1::l2_base_token::L2_BASE_TOKEN_ADDRESS; + +type CustomPrecompile = + fn(ctx: &mut CTX, inputs: &CallInputs, is_delegate: bool) -> InterpreterResult; + +/// ZKsync OS precompile provider +#[derive(Debug, Clone)] +pub struct ZKsyncPrecompiles { + /// Inner precompile provider is same as Ethereums. + inner: EthPrecompiles, + // Custom precompiles specific to ZKsync OS. + custom_precompiles: HashMap>, + /// Spec id of the precompile provider. + spec: ZkSpecId, +} + +impl ZKsyncPrecompiles { + /// Create a new precompile provider with the given ZkSpec. + #[inline] + pub fn new_with_spec(spec: ZkSpecId) -> Self { + let precompiles = match spec { + ZkSpecId::AtlasV1 | ZkSpecId::AtlasV2 => { + static INSTANCE: OnceLock = OnceLock::new(); + INSTANCE.get_or_init(|| { + let mut precompiles = Precompiles::default(); + // Generating the list instead of using default Cancun fork, + // because we need to remove Blake2 and Point Evaluation and + // add P256 precompile. + precompiles.extend([ + secp256k1::ECRECOVER, + hash::SHA256, + hash::RIPEMD160, + identity::FUN, + modexp::BERLIN, + bn254::add::ISTANBUL, + bn254::mul::ISTANBUL, + bn254::pair::ISTANBUL, + secp256r1::P256VERIFY, + ]); + precompiles + }) + } + }; + + let custom_precompiles = match spec { + ZkSpecId::AtlasV1 => [ + ( + CONTRACT_DEPLOYER_ADDRESS, + v1::deployer::deployer_precompile_call:: as CustomPrecompile, + ), + ( + L1_MESSENGER_ADDRESS, + v1::l1_messenger::l1_messenger_precompile_call:: as CustomPrecompile, + ), + ( + L2_BASE_TOKEN_ADDRESS, + v1::l2_base_token::l2_base_token_precompile_call:: + as CustomPrecompile, + ), + ] + .into(), + ZkSpecId::AtlasV2 => [ + ( + CONTRACT_DEPLOYER_ADDRESS, + v2::deployer::deployer_precompile_call:: as CustomPrecompile, + ), + ( + L1_MESSENGER_ADDRESS, + v2::l1_messenger::l1_messenger_precompile_call:: as CustomPrecompile, + ), + ( + L2_BASE_TOKEN_ADDRESS, + v2::l2_base_token::l2_base_token_precompile_call:: + as CustomPrecompile, + ), + ] + .into(), + }; + Self { + inner: EthPrecompiles { + precompiles, + spec: spec.into_eth_spec(), + }, + custom_precompiles, + spec, + } + } + + /// Precompiles getter. + #[inline] + pub fn precompiles(&self) -> &'static Precompiles { + self.inner.precompiles + } +} + +impl PrecompileProvider for ZKsyncPrecompiles +where + CTX: ContextTr>, +{ + type Output = InterpreterResult; + + #[inline] + fn set_spec(&mut self, spec: ::Spec) -> bool { + if spec == self.spec { + return false; + } + *self = Self::new_with_spec(spec); + true + } + + #[inline] + fn run( + &mut self, + context: &mut CTX, + inputs: &CallInputs, + ) -> Result, String> { + if let Some(precompile_call) = self.custom_precompiles.get(&inputs.bytecode_address) { + // If the code is loaded from different account it is a delegatecall + let is_delegate = inputs.bytecode_address != inputs.target_address; + + return Ok(Some(precompile_call(context, inputs, is_delegate))); + } + + self.inner.run(context, inputs) + } + + #[inline] + fn warm_addresses(&self) -> Box> { + self.inner.warm_addresses() + } + + #[inline] + fn contains(&self, address: &Address) -> bool { + self.inner.contains(address) + } +} + +impl Default for ZKsyncPrecompiles { + fn default() -> Self { + Self::new_with_spec(ZkSpecId::AtlasV2) + } +} diff --git a/src/precompiles/calldata_view.rs b/src/precompiles/calldata_view.rs new file mode 100644 index 0000000..a77b0d9 --- /dev/null +++ b/src/precompiles/calldata_view.rs @@ -0,0 +1,52 @@ +use revm::{context::LocalContextTr, context_interface::ContextTr, interpreter::CallInput}; + +/// Helper wrapper that lends a stable slice over call input bytes. +/// +/// The REVM interpreter keeps call data in a shared buffer that is reused across frames. +/// When a precompile is invoked we need a borrow of that buffer while we parse the input, +/// but we must also release the borrow before mutating the context (e.g. touching accounts). +/// +/// `CalldataView` encapsulates that pattern: +/// - it either stores a direct reference to the original bytes (when the input was `Bytes`) +/// or holds the `Ref<[u8]>` returned by `shared_memory_buffer_slice`; +/// - callers grab the slice via `as_slice()`, do their parsing, and then drop the wrapper +/// once they are ready to mutate the context. +pub struct CalldataView<'a> { + direct: &'a [u8], + borrow: Option>, +} + +impl<'a> CalldataView<'a> { + pub fn new(ctx: &'a CTX, input: &'a CallInput) -> Self + where + CTX: ContextTr, + { + match input { + CallInput::Bytes(bytes) => Self { + direct: bytes.as_ref(), + borrow: None, + }, + CallInput::SharedBuffer(range) => { + match ctx.local().shared_memory_buffer_slice(range.clone()) { + Some(borrow) => Self { + direct: &[], + borrow: Some(borrow), + }, + None => Self { + direct: &[], + borrow: None, + }, + } + } + } + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + if let Some(ref borrow) = self.borrow { + borrow.as_ref() + } else { + self.direct + } + } +} diff --git a/src/precompiles/utils.rs b/src/precompiles/utils.rs new file mode 100644 index 0000000..58f1d1d --- /dev/null +++ b/src/precompiles/utils.rs @@ -0,0 +1,19 @@ +use revm::{ + interpreter::{Gas, InstructionResult, InterpreterResult}, + primitives::{Address, B256}, +}; + +#[inline(always)] +pub fn b160_to_b256(addr: Address) -> B256 { + let mut out = [0u8; 32]; + out[12..].copy_from_slice(addr.as_slice()); // pad left, store address in low 20 bytes + B256::from(out) +} + +pub fn revert(g: Gas) -> InterpreterResult { + InterpreterResult::new(InstructionResult::Revert, [].into(), g) +} + +pub fn oog_error() -> InterpreterResult { + InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)) +} diff --git a/src/precompiles/v1.rs b/src/precompiles/v1.rs new file mode 100644 index 0000000..78eb1dc --- /dev/null +++ b/src/precompiles/v1.rs @@ -0,0 +1,12 @@ +//! Precompiles V1 +//! +//! Initial precompiles implementation kept only for legacy compatibility. +//! This version is not used by the current system. +//! +//! Please note it does not charge gas correctly, and is *NOT* +//! fully aligned with the ZKsync OS implementation. +//! As a result, the consistency checker may report divergences. +//! However there were no divergance trigger on Stage/Testnet/Mainnet chains. +pub mod deployer; +pub mod l1_messenger; +pub mod l2_base_token; diff --git a/src/precompiles/v1/deployer.rs b/src/precompiles/v1/deployer.rs new file mode 100644 index 0000000..a0a3bfb --- /dev/null +++ b/src/precompiles/v1/deployer.rs @@ -0,0 +1,112 @@ +use crate::precompiles::calldata_view::CalldataView; +use crate::precompiles::utils::{oog_error, revert}; +use revm::interpreter::CallInputs; +use revm::{ + Database, + context::JournalTr, + context_interface::ContextTr, + interpreter::{Gas, InstructionResult, InterpreterResult}, + primitives::{Address, B256, Bytes, U256, address}, + state::Bytecode, +}; + +// setBytecodeDetailsEVM(address,bytes32,uint32,bytes32) - f6eca0b0 +pub const SET_EVM_BYTECODE_DETAILS: &[u8] = &[0xf6, 0xec, 0xa0, 0xb0]; +// Contract Deployer system hook (contract) needed for all envs (force deploy) +pub const CONTRACT_DEPLOYER_ADDRESS: Address = address!("0000000000000000000000000000000000008006"); + +pub const L2_GENESIS_UPGRADE_ADDRESS: Address = + address!("000000000000000000000000000000000000800f"); + +pub const MAX_CODE_SIZE: usize = 0x6000; + +/// Run the deployer precompile. +pub fn deployer_precompile_call( + ctx: &mut CTX, + inputs: &CallInputs, + is_delegate: bool, +) -> InterpreterResult +where + CTX: ContextTr, +{ + let view = CalldataView::new(ctx, &inputs.input); + let mut calldata = view.as_slice(); + let caller = inputs.caller; + let call_value = inputs.value.get(); + let mut gas = Gas::new(inputs.gas_limit); + + // Mirror the same behaviour as on ZKsync OS + if is_delegate || call_value != U256::ZERO { + return revert(gas); + } + + if !gas.record_cost(1) { + return oog_error(); + } + + if calldata.len() < 4 { + return revert(gas); + } + + let mut selector = [0u8; 4]; + selector.copy_from_slice(&calldata[..4]); + match selector { + s if s == SET_EVM_BYTECODE_DETAILS => { + if inputs.is_static { + return revert(gas); + } + + // in future we need to handle regular(not genesis) protocol upgrades + if caller != L2_GENESIS_UPGRADE_ADDRESS { + return revert(gas); + } + + // decoding according to setDeployedCodeEVM(address,bytes) + calldata = &calldata[4..]; + if calldata.len() < 128 { + return revert(gas); + } + + // check that first 12 bytes in address encoding are zero + if calldata[0..12].iter().any(|byte| *byte != 0) { + return revert(gas); + } + let address = Address::from_slice(&calldata[12..32]); + + let bytecode_hash = + B256::from_slice(calldata[32..64].try_into().expect("Always valid")); + + let bytecode_length: u32 = match U256::from_be_slice(&calldata[64..96]).try_into() { + Ok(length) => length, + Err(_) => { + return revert(gas); + } + }; + + let _observable_bytecode_hash = + B256::from_slice(calldata[96..128].try_into().expect("Always valid")); + + // Although this can be called as a part of protocol upgrade, + // we are checking the next invariants, just in case + // EIP-158: reject code of length > 24576. + if bytecode_length as usize > MAX_CODE_SIZE { + return revert(gas); + } + + // finished reading calldata, release borrow before mutating context + drop(view); + + let bytecode = ctx.db_mut().code_by_hash(bytecode_hash).expect( + "The bytecode is expected to be pre-loaded for any deployer precompile call", + ); + + let bytecode_padded = Bytecode::new_legacy(Bytes::copy_from_slice( + &bytecode.original_bytes()[0..bytecode_length as usize], + )); + ctx.journal_mut().touch_account(address); + ctx.journal_mut().set_code(address, bytecode_padded); + InterpreterResult::new(InstructionResult::Return, [].into(), gas) + } + _ => revert(gas), + } +} diff --git a/src/precompiles/v1/l1_messenger.rs b/src/precompiles/v1/l1_messenger.rs new file mode 100644 index 0000000..32f2a60 --- /dev/null +++ b/src/precompiles/v1/l1_messenger.rs @@ -0,0 +1,145 @@ +use std::vec::Vec; + +use crate::precompiles::calldata_view::CalldataView; +use crate::precompiles::utils::revert; +use revm::interpreter::CallInputs; +use revm::{ + context::JournalTr, + context_interface::ContextTr, + interpreter::{Gas, InstructionResult, InterpreterResult}, + primitives::{Address, B256, Bytes, Log, LogData, U256, address, keccak256}, +}; + +// sendToL1(bytes) - 62f84b24 +pub const SEND_TO_L1_SELECTOR: &[u8] = &[0x62, 0xf8, 0x4b, 0x24]; + +const L1_MESSAGE_SENT_TOPIC: [u8; 32] = [ + 0x3a, 0x36, 0xe4, 0x72, 0x91, 0xf4, 0x20, 0x1f, 0xaf, 0x13, 0x7f, 0xab, 0x08, 0x1d, 0x92, 0x29, + 0x5b, 0xce, 0x2d, 0x53, 0xbe, 0x2c, 0x6c, 0xa6, 0x8b, 0xa8, 0x2c, 0x7f, 0xaa, 0x9c, 0xe2, 0x41, +]; + +pub const L1_MESSENGER_ADDRESS: Address = address!("0000000000000000000000000000000000008008"); + +#[inline(always)] +fn b160_to_b256(addr: Address) -> B256 { + let mut out = [0u8; 32]; + out[12..].copy_from_slice(addr.as_slice()); // pad left, store address in low 20 bytes + B256::from(out) +} + +pub(crate) fn send_to_l1_inner( + ctx: &mut CTX, + gas: &mut Gas, + abi_encoded_message: Vec, + caller: Address, +) -> InterpreterResult { + let data = abi_encoded_message.as_slice(); + + let abi_encoded_message_len: u32 = match data.len().try_into() { + Ok(len) => len, + Err(_) => return revert(*gas), + }; + + if abi_encoded_message_len < 32 { + return revert(*gas); + } + + let message_offset: u32 = match U256::from_be_slice(&data[..32]).try_into() { + Ok(offset) => offset, + Err(_) => return revert(*gas), + }; + + if message_offset != 32 { + return revert(*gas); + } + + let length_encoding_end = match message_offset.checked_add(32) { + Some(length_encoding_end) => length_encoding_end, + None => return revert(*gas), + }; + if abi_encoded_message_len < length_encoding_end { + return revert(*gas); + } + + let length: u32 = match U256::from_be_slice( + &data[(length_encoding_end as usize) - 32..length_encoding_end as usize], + ) + .try_into() + { + Ok(length) => length, + Err(_) => return revert(*gas), + }; + + let message_end = match length_encoding_end.checked_add(length) { + Some(message_end) => message_end, + None => return revert(*gas), + }; + if abi_encoded_message_len < message_end { + return revert(*gas); + } + + if !abi_encoded_message_len.is_multiple_of(32) { + return revert(*gas); + } + let message = &data[(length_encoding_end as usize)..message_end as usize]; + + let message_hash = keccak256(message); + let log = Log { + address: L1_MESSENGER_ADDRESS, + data: LogData::new_unchecked( + vec![ + B256::from_slice(&L1_MESSAGE_SENT_TOPIC), + b160_to_b256(caller), + message_hash, + ], + Bytes::from(abi_encoded_message), + ), + }; + ctx.journal_mut().log(log); + + // TODO: save L2 -> L1 message in a context of block + + InterpreterResult::new(InstructionResult::Return, message_hash.into(), *gas) +} + +/// Run the L1 messenger precompile. +pub fn l1_messenger_precompile_call( + ctx: &mut CTX, + inputs: &CallInputs, + is_delegate: bool, +) -> InterpreterResult { + let view = CalldataView::new(ctx, &inputs.input); + let calldata = view.as_slice(); + let caller = inputs.caller; + let call_value = inputs.value.get(); + let mut gas = Gas::new(inputs.gas_limit); + let revert = |g: Gas| InterpreterResult::new(InstructionResult::Revert, [].into(), g); + // Mirror the same behaviour as on ZKsync OS + if is_delegate || call_value != U256::ZERO { + return revert(gas); + } + + if !gas.record_cost(1) { + // Out-of-gas error + return InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)); + } + + // Check after charging the gas + if inputs.is_static { + return revert(gas); + } + + if calldata.len() < 4 { + return revert(gas); + } + let mut selector = [0u8; 4]; + selector.copy_from_slice(&calldata[..4]); + match selector { + s if s == SEND_TO_L1_SELECTOR => { + let call_payload = Vec::from(&calldata[4..]); + drop(view); + send_to_l1_inner(ctx, &mut gas, call_payload, caller) + } + _ => revert(gas), + } +} diff --git a/src/precompiles/v1/l2_base_token.rs b/src/precompiles/v1/l2_base_token.rs new file mode 100644 index 0000000..6b8d6eb --- /dev/null +++ b/src/precompiles/v1/l2_base_token.rs @@ -0,0 +1,188 @@ +use std::vec::Vec; + +use super::l1_messenger::send_to_l1_inner; +use crate::precompiles::calldata_view::CalldataView; +use crate::precompiles::utils::{oog_error, revert}; +use revm::interpreter::CallInputs; +use revm::{ + context::{ContextTr, JournalTr}, + interpreter::{Gas, InterpreterResult}, + primitives::{Address, U256, address}, +}; + +pub const L2_BASE_TOKEN_ADDRESS: Address = address!("000000000000000000000000000000000000800a"); + +// withdraw(address) - 51cff8d9 +pub const WITHDRAW_SELECTOR: &[u8] = &[0x51, 0xcf, 0xf8, 0xd9]; + +// withdrawWithMessage(address,bytes) - 84bc3eb0 +pub const WITHDRAW_WITH_MESSAGE_SELECTOR: &[u8] = &[0x84, 0xbc, 0x3e, 0xb0]; + +// finalizeEthWithdrawal(uint256,uint256,uint16,bytes,bytes32[]) - 6c0960f9 +pub const FINALIZE_ETH_WITHDRAWAL_SELECTOR: &[u8] = &[0x6c, 0x09, 0x60, 0xf9]; + +/// Run the L2 base token precompile. +pub fn l2_base_token_precompile_call( + ctx: &mut CTX, + inputs: &CallInputs, + is_delegate: bool, +) -> InterpreterResult { + let view = CalldataView::new(ctx, &inputs.input); + let calldata = view.as_slice(); + let caller = inputs.caller; + let call_value = inputs.value.get(); + let mut gas = Gas::new(inputs.gas_limit); + // Mirror the same behaviour as on ZKsync OS + if is_delegate { + return revert(gas); + } + + if !gas.record_cost(1) { + return oog_error(); + } + + // Check after charging the gas + if inputs.is_static { + return revert(gas); + } + + if calldata.len() < 4 { + return revert(gas); + } + + let mut selector = [0u8; 4]; + selector.copy_from_slice(&calldata[..4]); + // Calldata length shouldn't be able to overflow u32, due to gas limitations. + let calldata_len: u32 = match calldata.len().try_into() { + Ok(calldata_len) => calldata_len, + Err(_) => { + return revert(gas); + } + }; + match selector { + s if s == WITHDRAW_SELECTOR => { + // following solidity abi for withdraw(address) + if calldata_len < 36 { + return revert(gas); + } + + // Prepare L1 messenger payload while calldata borrow is active. + let mut l1_messenger_calldata = [0u8; 128]; + l1_messenger_calldata[31] = 32; // offset + l1_messenger_calldata[63] = 56; // length + l1_messenger_calldata[64..68].copy_from_slice(FINALIZE_ETH_WITHDRAWAL_SELECTOR); + // check that first 12 bytes in address encoding are zero + if calldata[4..4 + 12].iter().any(|byte| *byte != 0) { + return revert(gas); + } + l1_messenger_calldata[68..88].copy_from_slice(&calldata[(4 + 12)..36]); + l1_messenger_calldata[88..120].copy_from_slice(&call_value.to_be_bytes::<32>()); + + drop(view); + + ctx.journal_mut().touch_account(L2_BASE_TOKEN_ADDRESS); + let mut from_account = ctx + .journal_mut() + .load_account_with_code_mut(L2_BASE_TOKEN_ADDRESS) + .expect("load account"); + let balance_before = from_account.info.balance; + let Some(from_balance_decr) = balance_before.checked_sub(call_value) else { + return revert(gas); + }; + from_account.set_balance(from_balance_decr); + + send_to_l1_inner( + ctx, + &mut gas, + Vec::from(l1_messenger_calldata), + L2_BASE_TOKEN_ADDRESS, + ) + } + s if s == WITHDRAW_WITH_MESSAGE_SELECTOR => { + // following solidity abi for withdrawWithMessage(address,bytes) + if calldata_len < 68 { + return revert(gas); + } + let message_offset: u32 = match U256::from_be_slice(&calldata[36..68]).try_into() { + Ok(offset) => offset, + Err(_) => { + return revert(gas); + } + }; + // length located at 4+message_offset..4+message_offset+32 + // we want to check that 4+message_offset+32 will not overflow u32 + let length_encoding_end = match message_offset.checked_add(36) { + Some(length_encoding_end) => length_encoding_end, + None => { + return revert(gas); + } + }; + if calldata_len < length_encoding_end { + return revert(gas); + } + let length: u32 = match U256::from_be_slice( + &calldata[(length_encoding_end as usize) - 32..length_encoding_end as usize], + ) + .try_into() + { + Ok(length) => length, + Err(_) => { + return revert(gas); + } + }; + // to check that it will not overflow + let message_end = match length_encoding_end.checked_add(length) { + Some(message_end) => message_end, + None => { + return revert(gas); + } + }; + if calldata_len < message_end { + return revert(gas); + } + let additional_data = &calldata[(length_encoding_end as usize)..message_end as usize]; + + // check that first 12 bytes in address encoding are zero + if calldata[4..4 + 12].iter().any(|byte| *byte != 0) { + return revert(gas); + } + + let message_length = 76 + length; + let mut abi_encoded_message_length = 32 + 32 + message_length; + if !abi_encoded_message_length.is_multiple_of(32) { + abi_encoded_message_length += 32 - (abi_encoded_message_length % 32); + } + let mut message = Vec::with_capacity(abi_encoded_message_length as usize); + // Offset and length + message.extend_from_slice(&[0u8; 64]); + message[31] = 32; // offset + message[32..64].copy_from_slice(&U256::from(message_length).to_be_bytes::<32>()); + message.extend_from_slice(FINALIZE_ETH_WITHDRAWAL_SELECTOR); + message.extend_from_slice(&calldata[16..36]); + message.extend_from_slice(&call_value.to_be_bytes::<32>()); + message.extend_from_slice(caller.as_ref()); + message.extend_from_slice(additional_data); + // Populating the rest of the message with zeros to make it a multiple of 32 bytes + message.extend(core::iter::repeat_n( + 0u8, + abi_encoded_message_length as usize - message.len(), + )); + + drop(view); + + ctx.journal_mut().touch_account(L2_BASE_TOKEN_ADDRESS); + let mut from_account = ctx + .journal_mut() + .load_account_with_code_mut(L2_BASE_TOKEN_ADDRESS) + .expect("load account"); + let balance_before = from_account.info.balance; + let Some(from_balance_decr) = balance_before.checked_sub(call_value) else { + return revert(gas); + }; + from_account.set_balance(from_balance_decr); + + send_to_l1_inner(ctx, &mut gas, message, L2_BASE_TOKEN_ADDRESS) + } + _ => revert(gas), + } +} diff --git a/src/precompiles/v2.rs b/src/precompiles/v2.rs new file mode 100644 index 0000000..e0b65bb --- /dev/null +++ b/src/precompiles/v2.rs @@ -0,0 +1,5 @@ +//! Precompiles V2 +pub mod deployer; +pub(crate) mod gas_cost; +pub mod l1_messenger; +pub mod l2_base_token; diff --git a/src/precompiles/v2/deployer.rs b/src/precompiles/v2/deployer.rs new file mode 100644 index 0000000..f29bdc4 --- /dev/null +++ b/src/precompiles/v2/deployer.rs @@ -0,0 +1,136 @@ +use crate::precompiles::utils::{oog_error, revert}; +use crate::precompiles::v2::gas_cost::HOOK_BASE_GAS_COST; +use crate::precompiles::{ + calldata_view::CalldataView, v2::gas_cost::set_bytecode_details_extra_gas, +}; +use revm::interpreter::CallInputs; +use revm::{ + Database, + context::JournalTr, + context_interface::ContextTr, + interpreter::{ + Gas, InstructionResult, InterpreterResult, + gas::{COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST}, + }, + primitives::{Address, B256, Bytes, U256, address}, + state::Bytecode, +}; + +// setBytecodeDetailsEVM(address,bytes32,uint32,bytes32) - f6eca0b0 +pub const SET_EVM_BYTECODE_DETAILS: &[u8] = &[0xf6, 0xec, 0xa0, 0xb0]; +// Contract Deployer system hook (contract) needed for all envs (force deploy) +pub const CONTRACT_DEPLOYER_ADDRESS: Address = address!("0000000000000000000000000000000000008006"); + +pub const L2_GENESIS_UPGRADE_ADDRESS: Address = + address!("000000000000000000000000000000000000800f"); + +pub const MAX_CODE_SIZE: usize = 0x6000; + +/// Run the deployer precompile. +pub fn deployer_precompile_call( + ctx: &mut CTX, + inputs: &CallInputs, + is_delegate: bool, +) -> InterpreterResult { + let view = CalldataView::new(ctx, &inputs.input); + let mut calldata = view.as_slice(); + let caller = inputs.caller; + let call_value = inputs.value.get(); + let mut gas = Gas::new(inputs.gas_limit); + + // Mirror the same behaviour as on ZKsync OS + if is_delegate || call_value != U256::ZERO { + return revert(gas); + } + + // Charge base cost for calling system hook + if !gas.record_cost(HOOK_BASE_GAS_COST) { + return oog_error(); + } + + if calldata.len() < 4 { + return revert(gas); + } + + let mut selector = [0u8; 4]; + selector.copy_from_slice(&calldata[..4]); + match selector { + s if s == SET_EVM_BYTECODE_DETAILS => { + if inputs.is_static { + return revert(gas); + } + + // in future we need to handle regular(not genesis) protocol upgrades + if caller != L2_GENESIS_UPGRADE_ADDRESS { + return revert(gas); + } + + // decoding according to setDeployedCodeEVM(address,bytes) + calldata = &calldata[4..]; + if calldata.len() < 128 { + return revert(gas); + } + + // check that first 12 bytes in address encoding are zero + if calldata[0..12].iter().any(|byte| *byte != 0) { + return revert(gas); + } + let address = Address::from_slice(&calldata[12..32]); + + let bytecode_hash = + B256::from_slice(calldata[32..64].try_into().expect("Always valid")); + + let bytecode_length: u32 = match U256::from_be_slice(&calldata[64..96]).try_into() { + Ok(length) => length, + Err(_) => { + return revert(gas); + } + }; + + let _observable_bytecode_hash = + B256::from_slice(calldata[96..128].try_into().expect("Always valid")); + + // Although this can be called as a part of protocol upgrade, + // we are checking the next invariants, just in case + // EIP-158: reject code of length > 24576. + if bytecode_length as usize > MAX_CODE_SIZE { + return revert(gas); + } + + // finished reading calldata, release borrow before mutating context + drop(view); + + // Charge extra gas for `set_bytecode_details` + let extra_gas = set_bytecode_details_extra_gas(bytecode_length as u64); + if !gas.record_cost(extra_gas) { + return oog_error(); + } + + let bytecode = ctx.db_mut().code_by_hash(bytecode_hash).expect( + "The bytecode is expected to be pre-loaded for any deployer precompile call", + ); + + let bytecode_padded = Bytecode::new_legacy(Bytes::copy_from_slice( + &bytecode.original_bytes()[0..bytecode_length as usize], + )); + let account = ctx + .journal_mut() + .load_account(address) + .expect("load account"); + let gas_for_access = if account.is_cold { + COLD_ACCOUNT_ACCESS_COST + } else { + WARM_STORAGE_READ_COST + }; + // Charge base cost for warm/cold read + if !gas.record_cost(gas_for_access) { + return oog_error(); + } + + ctx.journal_mut().touch_account(address); + ctx.journal_mut().set_code(address, bytecode_padded); + InterpreterResult::new(InstructionResult::Return, [].into(), gas) + } + _ => revert(gas), + } +} diff --git a/src/precompiles/v2/gas_cost.rs b/src/precompiles/v2/gas_cost.rs new file mode 100644 index 0000000..9a821fd --- /dev/null +++ b/src/precompiles/v2/gas_cost.rs @@ -0,0 +1,33 @@ +use revm::interpreter::gas::{KECCAK256, KECCAK256WORD, LOG, LOGDATA, LOGTOPIC}; +use std::ops::Mul; + +use crate::precompiles::v2::l1_messenger::L2_TO_L1_LOG_SERIALIZE_SIZE; + +pub const HOOK_BASE_GAS_COST: u64 = 100; + +/// Gas cost per byte of bytecode for force deployments. +const SET_BYTECODE_DETAILS_EXTRA_GAS_PER_BYTE: u64 = 50; + +pub fn keccak256_gas_cost(len: usize) -> u64 { + let words = len.div_ceil(32); + KECCAK256.saturating_add(KECCAK256WORD.saturating_mul(words as u64)) +} + +pub fn l1_message_gas_cost(message_len: usize) -> u64 { + let hashing_cost = keccak256_gas_cost(L2_TO_L1_LOG_SERIALIZE_SIZE) + + keccak256_gas_cost(64).mul(3) + + 2 * keccak256_gas_cost(message_len); + let log_cost = LOG + LOGDATA * message_len as u64; + hashing_cost + log_cost +} + +pub fn log_gas_cost(topics: u64, data: u64) -> u64 { + let static_cost = LOG; + let topic_cost = LOGTOPIC * topics; + let len_cost = data * LOGDATA; + static_cost + topic_cost + len_cost +} + +pub fn set_bytecode_details_extra_gas(bytecode_len: u64) -> u64 { + SET_BYTECODE_DETAILS_EXTRA_GAS_PER_BYTE * bytecode_len +} diff --git a/src/precompiles/v2/l1_messenger.rs b/src/precompiles/v2/l1_messenger.rs new file mode 100644 index 0000000..6ca4ca1 --- /dev/null +++ b/src/precompiles/v2/l1_messenger.rs @@ -0,0 +1,159 @@ +use std::vec::Vec; + +use crate::precompiles::utils::revert; +use crate::precompiles::v2::gas_cost::{HOOK_BASE_GAS_COST, l1_message_gas_cost, log_gas_cost}; +use crate::precompiles::{calldata_view::CalldataView, utils::b160_to_b256}; +use revm::interpreter::CallInputs; +use revm::{ + context::JournalTr, + context_interface::ContextTr, + interpreter::{Gas, InstructionResult, InterpreterResult}, + primitives::{Address, B256, Bytes, Log, LogData, U256, address, keccak256}, +}; + +// sendToL1(bytes) - 62f84b24 +pub const SEND_TO_L1_SELECTOR: &[u8] = &[0x62, 0xf8, 0x4b, 0x24]; + +const L1_MESSAGE_SENT_TOPIC: [u8; 32] = [ + 0x3a, 0x36, 0xe4, 0x72, 0x91, 0xf4, 0x20, 0x1f, 0xaf, 0x13, 0x7f, 0xab, 0x08, 0x1d, 0x92, 0x29, + 0x5b, 0xce, 0x2d, 0x53, 0xbe, 0x2c, 0x6c, 0xa6, 0x8b, 0xa8, 0x2c, 0x7f, 0xaa, 0x9c, 0xe2, 0x41, +]; + +pub const L1_MESSENGER_ADDRESS: Address = address!("0000000000000000000000000000000000008008"); + +pub const L2_TO_L1_LOG_SERIALIZE_SIZE: usize = 88; + +pub(crate) fn send_to_l1_inner( + ctx: &mut CTX, + gas: &mut Gas, + abi_encoded_message: Vec, + caller: Address, +) -> Result { + let data = abi_encoded_message.as_slice(); + + let abi_encoded_message_len: u32 = match data.len().try_into() { + Ok(len) => len, + Err(_) => return Err(revert(*gas)), + }; + + if abi_encoded_message_len < 32 { + return Err(revert(*gas)); + } + + let message_offset: u32 = match U256::from_be_slice(&data[..32]).try_into() { + Ok(offset) => offset, + Err(_) => return Err(revert(*gas)), + }; + + if message_offset != 32 { + return Err(revert(*gas)); + } + + let length_encoding_end = match message_offset.checked_add(32) { + Some(length_encoding_end) => length_encoding_end, + None => return Err(revert(*gas)), + }; + if abi_encoded_message_len < length_encoding_end { + return Err(revert(*gas)); + } + + let length: u32 = match U256::from_be_slice( + &data[(length_encoding_end as usize) - 32..length_encoding_end as usize], + ) + .try_into() + { + Ok(length) => length, + Err(_) => return Err(revert(*gas)), + }; + + let message_end = match length_encoding_end.checked_add(length) { + Some(message_end) => message_end, + None => return Err(revert(*gas)), + }; + if abi_encoded_message_len < message_end { + return Err(revert(*gas)); + } + + if !abi_encoded_message_len.is_multiple_of(32) { + return Err(revert(*gas)); + } + let message = &data[(length_encoding_end as usize)..message_end as usize]; + + // Charge gas for emitting l1 message and log + let gas_cost = + l1_message_gas_cost(message.len()) + log_gas_cost(3, abi_encoded_message_len as u64); + if !gas.record_cost(gas_cost) { + // Out-of-gas error + return Err(InterpreterResult::new( + InstructionResult::OutOfGas, + [].into(), + Gas::new(0), + )); + } + + let message_hash = keccak256(message); + let log = Log { + address: L1_MESSENGER_ADDRESS, + data: LogData::new_unchecked( + vec![ + B256::from_slice(&L1_MESSAGE_SENT_TOPIC), + b160_to_b256(caller), + message_hash, + ], + Bytes::from(abi_encoded_message), + ), + }; + ctx.journal_mut().log(log); + + // TODO: save L2 -> L1 message in a context of block + + Ok(message_hash) +} + +/// Run the L1 messenger precompile. +pub fn l1_messenger_precompile_call( + ctx: &mut CTX, + inputs: &CallInputs, + is_delegate: bool, +) -> InterpreterResult { + let view = CalldataView::new(ctx, &inputs.input); + let calldata = view.as_slice(); + let caller = inputs.caller; + let call_value = inputs.value.get(); + let mut gas = Gas::new(inputs.gas_limit); + let revert = |g: Gas| InterpreterResult::new(InstructionResult::Revert, [].into(), g); + // Mirror the same behaviour as on ZKsync OS + if is_delegate || call_value != U256::ZERO { + return revert(gas); + } + + // Charge base cost for calling system hook + if !gas.record_cost(HOOK_BASE_GAS_COST) { + // Out-of-gas error + return InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)); + } + + // Check after charging the gas + if inputs.is_static { + return revert(gas); + } + + if calldata.len() < 4 { + return revert(gas); + } + let mut selector = [0u8; 4]; + selector.copy_from_slice(&calldata[..4]); + match selector { + s if s == SEND_TO_L1_SELECTOR => { + let call_payload = Vec::from(&calldata[4..]); + drop(view); + match send_to_l1_inner(ctx, &mut gas, call_payload, caller) { + Ok(message_hash) => { + InterpreterResult::new(InstructionResult::Return, message_hash.into(), gas) + } + Err(interpreter_result) => interpreter_result, + } + } + _ => revert(gas), + } +} diff --git a/src/precompiles/v2/l2_base_token.rs b/src/precompiles/v2/l2_base_token.rs new file mode 100644 index 0000000..1ca488d --- /dev/null +++ b/src/precompiles/v2/l2_base_token.rs @@ -0,0 +1,322 @@ +use std::vec::Vec; + +use super::l1_messenger::send_to_l1_inner; +use crate::precompiles::utils::{oog_error, revert}; +use crate::precompiles::v2::gas_cost::{HOOK_BASE_GAS_COST, log_gas_cost}; +use crate::precompiles::{calldata_view::CalldataView, utils::b160_to_b256}; +use revm::interpreter::CallInputs; +use revm::{ + context::{ContextTr, JournalTr}, + interpreter::{Gas, InstructionResult, InterpreterResult, gas::WARM_STORAGE_READ_COST}, + primitives::{Address, B256, Bytes, Log, LogData, U256, address}, +}; + +pub const L2_BASE_TOKEN_ADDRESS: Address = address!("000000000000000000000000000000000000800a"); + +// withdraw(address) - 51cff8d9 +pub const WITHDRAW_SELECTOR: &[u8] = &[0x51, 0xcf, 0xf8, 0xd9]; + +// withdrawWithMessage(address,bytes) - 84bc3eb0 +pub const WITHDRAW_WITH_MESSAGE_SELECTOR: &[u8] = &[0x84, 0xbc, 0x3e, 0xb0]; + +// finalizeEthWithdrawal(uint256,uint256,uint16,bytes,bytes32[]) - 6c0960f9 +pub const FINALIZE_ETH_WITHDRAWAL_SELECTOR: &[u8] = &[0x6c, 0x09, 0x60, 0xf9]; + +// keccak256("Withdrawal(address,address,uint256)") +const WITHDRAWAL_TOPIC: [u8; 32] = [ + 0x27, 0x17, 0xea, 0xd6, 0xb9, 0x20, 0x0d, 0xd2, 0x35, 0xaa, 0xd4, 0x68, 0xc9, 0x80, 0x9e, 0xa4, + 0x00, 0xfe, 0x33, 0xac, 0x69, 0xb5, 0xbf, 0xaa, 0x6d, 0x3e, 0x90, 0xfc, 0x92, 0x2b, 0x63, 0x98, +]; + +// keccak256("WithdrawalWithMessage(address,address,uint256,bytes)") +const WITHDRAWAL_WITH_MESSAGE_TOPIC: [u8; 32] = [ + 0xc4, 0x05, 0xfe, 0x89, 0x58, 0x41, 0x0b, 0xba, 0xf0, 0xc7, 0x3b, 0x7a, 0x0c, 0x3e, 0x20, 0x85, + 0x9e, 0x86, 0xca, 0x16, 0x8a, 0x4c, 0x9b, 0x0d, 0xef, 0x9c, 0x54, 0xd2, 0x55, 0x5a, 0x30, 0x6b, +]; + +/// Run the L2 base token precompile. +pub fn l2_base_token_precompile_call( + ctx: &mut CTX, + inputs: &CallInputs, + is_delegate: bool, +) -> InterpreterResult { + let view = CalldataView::new(ctx, &inputs.input); + let calldata = view.as_slice(); + let mut gas = Gas::new(inputs.gas_limit); + // Mirror the same behaviour as on ZKsync OS + if is_delegate { + return revert(gas); + } + + // Charge base cost for calling system hook + if !gas.record_cost(HOOK_BASE_GAS_COST) { + return oog_error(); + } + + // Check after charging the gas + if inputs.is_static { + return revert(gas); + } + + if calldata.len() < 4 { + return revert(gas); + } + + let mut selector = [0u8; 4]; + selector.copy_from_slice(&calldata[..4]); + drop(view); + match selector { + s if s == WITHDRAW_SELECTOR => withdraw(ctx, inputs, gas), + s if s == WITHDRAW_WITH_MESSAGE_SELECTOR => withdraw_with_message(ctx, inputs, gas), + _ => revert(gas), + } +} + +/// Handles withdraw(address) calls - burns tokens and sends L1 message +/// Emits Withdrawal event on success +fn withdraw(ctx: &mut CTX, inputs: &CallInputs, mut gas: Gas) -> InterpreterResult { + let revert = |g: Gas| InterpreterResult::new(InstructionResult::Revert, [].into(), g); + + let view = CalldataView::new(ctx, &inputs.input); + let calldata = view.as_slice(); + // Calldata length shouldn't be able to overflow u32, due to gas limitations. + let calldata_len: u32 = match calldata.len().try_into() { + Ok(calldata_len) => calldata_len, + Err(_) => { + return revert(gas); + } + }; + + // following solidity abi for withdraw(address) + if calldata_len < 36 { + return revert(gas); + } + + // Prepare L1 messenger payload while calldata borrow is active. + let mut l1_messenger_calldata = [0u8; 128]; + l1_messenger_calldata[31] = 32; // offset + l1_messenger_calldata[63] = 56; // length + l1_messenger_calldata[64..68].copy_from_slice(FINALIZE_ETH_WITHDRAWAL_SELECTOR); + // check that first 12 bytes in address encoding are zero + if calldata[4..4 + 12].iter().any(|byte| *byte != 0) { + return revert(gas); + } + let l1_receiver = calldata[(4 + 12)..36].to_vec(); + l1_messenger_calldata[68..88].copy_from_slice(&l1_receiver); + l1_messenger_calldata[88..120].copy_from_slice(&inputs.value.get().to_be_bytes::<32>()); + + drop(view); + + // Charge gas for the token burning + if !gas.record_cost(WARM_STORAGE_READ_COST) { + // Out-of-gas error + return InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)); + } + + ctx.journal_mut().touch_account(L2_BASE_TOKEN_ADDRESS); + let mut from_account = ctx + .journal_mut() + .load_account_with_code_mut(L2_BASE_TOKEN_ADDRESS) + .expect("load account"); + let balance_before = from_account.info.balance; + let Some(from_balance_decr) = balance_before.checked_sub(inputs.value.get()) else { + return revert(gas); + }; + from_account.set_balance(from_balance_decr); + + if let Err(interpreter_result) = send_to_l1_inner( + ctx, + &mut gas, + Vec::from(l1_messenger_calldata), + L2_BASE_TOKEN_ADDRESS, + ) { + return interpreter_result; + }; + + let log = Log { + address: L2_BASE_TOKEN_ADDRESS, + data: LogData::new_unchecked( + vec![ + B256::from_slice(&WITHDRAWAL_TOPIC), + b160_to_b256(inputs.caller), // _l2Sender + U256::from_be_slice(&l1_receiver).into(), + ], + inputs.value.get().to_be_bytes::<32>().into(), + ), + }; + ctx.journal_mut().log(log); + + // Charge gas for emitting log + let gas_cost = log_gas_cost(3, 32); + if !gas.record_cost(gas_cost) { + // Out-of-gas error + return InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)); + } + + InterpreterResult::new(InstructionResult::Return, [].into(), gas) +} + +/// Handles withdrawWithMessage(address,bytes) calls - burns tokens and sends L1 message with additional data +/// Emits WithdrawalWithMessage event on success +fn withdraw_with_message( + ctx: &mut CTX, + inputs: &CallInputs, + mut gas: Gas, +) -> InterpreterResult { + let revert = |g: Gas| InterpreterResult::new(InstructionResult::Revert, [].into(), g); + + let view = CalldataView::new(ctx, &inputs.input); + let calldata = view.as_slice(); + + // Calldata length shouldn't be able to overflow u32, due to gas limitations. + let calldata_len: u32 = match calldata.len().try_into() { + Ok(calldata_len) => calldata_len, + Err(_) => { + return revert(gas); + } + }; + + // following solidity abi for withdrawWithMessage(address,bytes) + if calldata_len < 68 { + return revert(gas); + } + let message_offset: u32 = match U256::from_be_slice(&calldata[36..68]).try_into() { + Ok(offset) => offset, + Err(_) => { + return revert(gas); + } + }; + // length located at 4+message_offset..4+message_offset+32 + // we want to check that 4+message_offset+32 will not overflow u32 + let length_encoding_end = match message_offset.checked_add(36) { + Some(length_encoding_end) => length_encoding_end, + None => { + return revert(gas); + } + }; + if calldata_len < length_encoding_end { + return revert(gas); + } + let length: u32 = match U256::from_be_slice( + &calldata[(length_encoding_end as usize) - 32..length_encoding_end as usize], + ) + .try_into() + { + Ok(length) => length, + Err(_) => { + return revert(gas); + } + }; + // to check that it will not overflow + let message_end = match length_encoding_end.checked_add(length) { + Some(message_end) => message_end, + None => { + return revert(gas); + } + }; + if calldata_len < message_end { + return revert(gas); + } + let additional_data = calldata[(length_encoding_end as usize)..message_end as usize].to_vec(); + + // check that first 12 bytes in address encoding are zero + if calldata[4..4 + 12].iter().any(|byte| *byte != 0) { + return revert(gas); + } + + let message_length = 76 + length; + let mut abi_encoded_message_length = 32 + 32 + message_length; + if !abi_encoded_message_length.is_multiple_of(32) { + abi_encoded_message_length += 32 - (abi_encoded_message_length % 32); + } + let mut message = Vec::with_capacity(abi_encoded_message_length as usize); + // Offset and length + message.extend_from_slice(&[0u8; 64]); + message[31] = 32; // offset + message[32..64].copy_from_slice(&U256::from(message_length).to_be_bytes::<32>()); + message.extend_from_slice(FINALIZE_ETH_WITHDRAWAL_SELECTOR); + let l1_receiver = calldata[(4 + 12)..36].to_vec(); + message.extend_from_slice(&l1_receiver); + message.extend_from_slice(&inputs.value.get().to_be_bytes::<32>()); + message.extend_from_slice(inputs.caller.as_ref()); + message.extend_from_slice(&additional_data); + // Populating the rest of the message with zeros to make it a multiple of 32 bytes + message.extend(core::iter::repeat_n( + 0u8, + abi_encoded_message_length as usize - message.len(), + )); + + drop(view); + + // Charge gas for the token burning + if !gas.record_cost(WARM_STORAGE_READ_COST) { + // Out-of-gas error + return InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)); + } + + ctx.journal_mut().touch_account(L2_BASE_TOKEN_ADDRESS); + let mut from_account = ctx + .journal_mut() + .load_account_with_code_mut(L2_BASE_TOKEN_ADDRESS) + .expect("load account"); + let balance_before = from_account.info.balance; + let Some(from_balance_decr) = balance_before.checked_sub(inputs.value.get()) else { + return revert(gas); + }; + from_account.set_balance(from_balance_decr); + if let Err(interpreter_result) = send_to_l1_inner(ctx, &mut gas, message, L2_BASE_TOKEN_ADDRESS) + { + return interpreter_result; + }; + + /* + event WithdrawalWithMessage( + address indexed _l2Sender, + address indexed _l1Receiver, + uint256 _amount, + bytes _additionalData + ); + */ + + // ABI encode event data: _amount (32 bytes) + _additionalData offset (32) + length (32) + data + let abi_encoded_event_length = 32 + 32 + 32 + additional_data.len(); + let abi_encoded_event_length = if !abi_encoded_event_length.is_multiple_of(32) { + abi_encoded_event_length + (32 - (abi_encoded_event_length % 32)) + } else { + abi_encoded_event_length + }; + + let mut event_data = std::vec::Vec::with_capacity(abi_encoded_event_length + 32); + event_data.extend_from_slice(&inputs.value.get().to_be_bytes::<32>()); + event_data.extend_from_slice(&[0u8; 64]); + event_data[63] = 64; // offset + event_data[64..96].copy_from_slice(&U256::from(additional_data.len()).to_be_bytes::<32>()); + event_data.extend_from_slice(&additional_data); + // Populating the rest of the event data with zeros to make it a multiple of 32 bytes + event_data.extend(core::iter::repeat_n( + 0u8, + abi_encoded_event_length - event_data.len(), + )); + + let log = Log { + address: L2_BASE_TOKEN_ADDRESS, + data: LogData::new_unchecked( + vec![ + B256::from_slice(&WITHDRAWAL_WITH_MESSAGE_TOPIC), + b160_to_b256(inputs.caller), // _l2Sender + U256::from_be_slice(&l1_receiver).into(), + ], + Bytes::from(event_data), + ), + }; + ctx.journal_mut().log(log); + + // Charge gas for emitting log + let gas_cost = log_gas_cost(3, abi_encoded_event_length as u64); + if !gas.record_cost(gas_cost) { + // Out-of-gas error + return InterpreterResult::new(InstructionResult::OutOfGas, [].into(), Gas::new(0)); + } + + InterpreterResult::new(InstructionResult::Return, [].into(), gas) +} diff --git a/src/spec.rs b/src/spec.rs new file mode 100644 index 0000000..58e8019 --- /dev/null +++ b/src/spec.rs @@ -0,0 +1,78 @@ +//! Contains the `[ZkSpecId]` type and its implementation. +use core::str::FromStr; +use revm::primitives::hardfork::{SpecId, UnknownHardfork}; + +/// Identifies which EVM variant should be used during execution. +/// Differences between variants may include supported opcodes, +/// available precompiles, and gas-charging rules. +/// +/// Note: The ZKsync OS Server is responsible for mapping its own +/// `ExecutionVersion` to one of these spec IDs. +#[repr(u8)] +#[derive( + Clone, + Copy, + Debug, + Hash, + PartialEq, + Eq, + PartialOrd, + Ord, + Default, + serde::Serialize, + serde::Deserialize, +)] +#[allow(non_camel_case_types)] +pub enum ZkSpecId { + AtlasV1, + #[default] + AtlasV2, +} + +impl ZkSpecId { + /// Converts the [`ZkSpecId`] into a [`SpecId`]. + pub const fn into_eth_spec(self) -> SpecId { + match self { + Self::AtlasV1 | Self::AtlasV2 => SpecId::CANCUN, + } + } + + /// Checks if the [`ZkSpecId`] is enabled in the other [`ZkSpecId`]. + pub const fn is_enabled_in(self, other: ZkSpecId) -> bool { + other as u8 <= self as u8 + } +} + +impl From for SpecId { + fn from(spec: ZkSpecId) -> Self { + spec.into_eth_spec() + } +} + +impl FromStr for ZkSpecId { + type Err = UnknownHardfork; + + fn from_str(s: &str) -> Result { + match s { + name::ATLASV1 => Ok(ZkSpecId::AtlasV1), + name::ATLASV2 => Ok(ZkSpecId::AtlasV2), + _ => Err(UnknownHardfork), + } + } +} + +impl From for &'static str { + fn from(spec_id: ZkSpecId) -> Self { + match spec_id { + ZkSpecId::AtlasV1 => name::ATLASV1, + ZkSpecId::AtlasV2 => name::ATLASV2, + } + } +} + +/// String identifiers for ZKsync OS hardforks +pub mod name { + /// Initial spec name. + pub const ATLASV1: &str = "AtlasV1"; + pub const ATLASV2: &str = "AtlasV2"; +} diff --git a/src/transaction.rs b/src/transaction.rs new file mode 100644 index 0000000..cee3dd2 --- /dev/null +++ b/src/transaction.rs @@ -0,0 +1,7 @@ +//! Contains the `[ZKsyncTx]` type and its implementation. +pub mod abstraction; +pub mod error; +pub mod priority_tx; + +pub use abstraction::{ZKsyncTx, ZkTxTr}; +pub use error::ZKsyncTxError; diff --git a/src/transaction/abstraction.rs b/src/transaction/abstraction.rs new file mode 100644 index 0000000..b81311e --- /dev/null +++ b/src/transaction/abstraction.rs @@ -0,0 +1,321 @@ +//! ZKsync OS transaction abstraction containing the `[ZkTxTr]` trait and corresponding `[ZKsyncTx]` type. +use super::priority_tx::{ + L1_PRIORITY_TRANSACTION_TYPE, L1ToL2TransactionParts, UPGRADE_TRANSACTION_TYPE, +}; +use auto_impl::auto_impl; +use revm::{ + context::{ + TxEnv, + tx::{TxEnvBuildError, TxEnvBuilder}, + }, + context_interface::transaction::Transaction, + handler::SystemCallTx, + primitives::{Address, B256, Bytes, TxKind, U256}, +}; + +/// ZKsync OS Transaction trait. +#[auto_impl(&, &mut, Box, Arc)] +pub trait ZkTxTr: Transaction { + /// Mint of the deposit transaction + fn mint(&self) -> Option; + + fn is_l1_to_l2_tx(&self) -> bool { + self.tx_type() == UPGRADE_TRANSACTION_TYPE || self.tx_type() == L1_PRIORITY_TRANSACTION_TYPE + } + + fn refund_recipient(&self) -> Option
; + + fn gas_used_override(&self) -> Option; + + fn force_fail(&self) -> bool; +} + +/// ZKsync OS transaction. +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct ZKsyncTx { + /// Base transaction fields. + pub base: T, + /// L1 -> L2 transaction parts. + pub l1_to_l2_part: L1ToL2TransactionParts, + /// The gas spent on executing the transaction in the original ZKsync OS environment. + pub gas_used_override: Option, + /// The execution status (success/revert) from the original ZKsync OS environment. + pub force_fail: bool, +} + +impl AsRef for ZKsyncTx { + fn as_ref(&self) -> &T { + &self.base + } +} + +impl ZKsyncTx { + /// Create a new ZKsync OS transaction. + pub fn new(base: T) -> Self { + Self { + base, + l1_to_l2_part: L1ToL2TransactionParts::default(), + gas_used_override: None, + force_fail: false, + } + } +} + +impl ZKsyncTx { + /// Create a new ZKsync OS transaction. + pub fn builder() -> ZKsyncTxBuilder { + ZKsyncTxBuilder::new() + } +} + +impl Default for ZKsyncTx { + fn default() -> Self { + Self { + base: TxEnv::default(), + l1_to_l2_part: L1ToL2TransactionParts::default(), + gas_used_override: None, + force_fail: false, + } + } +} + +impl SystemCallTx for ZKsyncTx { + fn new_system_tx_with_caller( + caller: Address, + system_contract_address: Address, + data: Bytes, + ) -> Self { + ZKsyncTx::new(TX::new_system_tx_with_caller( + caller, + system_contract_address, + data, + )) + } +} + +impl Transaction for ZKsyncTx { + type AccessListItem<'a> + = T::AccessListItem<'a> + where + T: 'a; + type Authorization<'a> + = T::Authorization<'a> + where + T: 'a; + + fn tx_type(&self) -> u8 { + self.base.tx_type() + } + + fn caller(&self) -> Address { + self.base.caller() + } + + fn gas_limit(&self) -> u64 { + self.base.gas_limit() + } + + fn value(&self) -> U256 { + self.base.value() + } + + fn input(&self) -> &Bytes { + self.base.input() + } + + fn nonce(&self) -> u64 { + self.base.nonce() + } + + fn kind(&self) -> TxKind { + self.base.kind() + } + + fn chain_id(&self) -> Option { + self.base.chain_id() + } + + fn access_list(&self) -> Option>> { + self.base.access_list() + } + + fn max_priority_fee_per_gas(&self) -> Option { + self.base.max_priority_fee_per_gas() + } + + fn max_fee_per_gas(&self) -> u128 { + self.base.max_fee_per_gas() + } + + fn gas_price(&self) -> u128 { + self.base.gas_price() + } + + fn blob_versioned_hashes(&self) -> &[B256] { + self.base.blob_versioned_hashes() + } + + fn max_fee_per_blob_gas(&self) -> u128 { + self.base.max_fee_per_blob_gas() + } + + fn effective_gas_price(&self, base_fee: u128) -> u128 { + // L1 to L2 transactions use gas_price directly + if self.is_l1_to_l2_tx() { + return self.gas_price(); + } + self.base.effective_gas_price(base_fee) + } + + fn authorization_list_len(&self) -> usize { + self.base.authorization_list_len() + } + + fn authorization_list(&self) -> impl Iterator> { + self.base.authorization_list() + } +} + +impl ZkTxTr for ZKsyncTx { + fn mint(&self) -> Option { + self.l1_to_l2_part.mint + } + + fn refund_recipient(&self) -> Option
{ + self.l1_to_l2_part.refund_recipient + } + + fn gas_used_override(&self) -> Option { + self.gas_used_override + } + + fn force_fail(&self) -> bool { + self.force_fail + } +} + +/// Builder for constructing [`ZKsyncTx`] instances +#[derive(Default, Debug)] +pub struct ZKsyncTxBuilder { + base: TxEnvBuilder, + l1_to_l2_part: L1ToL2TransactionParts, + gas_used_override: Option, + force_fail: bool, +} + +impl ZKsyncTxBuilder { + /// Create a new builder with default values + pub fn new() -> Self { + Self { + base: TxEnvBuilder::new(), + l1_to_l2_part: L1ToL2TransactionParts::default(), + gas_used_override: None, + force_fail: false, + } + } + + /// Set the base transaction builder based for TxEnvBuilder. + pub fn base(mut self, base: TxEnvBuilder) -> Self { + self.base = base; + self + } + + /// Set the mint of the L1 -> L2 part of the transaction. + pub fn mint(mut self, mint: U256) -> Self { + self.l1_to_l2_part.mint = Some(mint); + self + } + + /// Sets the gas amount spent in the transaction based + /// on the original ZKsync OS execution environment. + pub fn gas_used_override(mut self, gas_used_override: Option) -> Self { + self.gas_used_override = gas_used_override; + self + } + + /// Sets the execution status of the transaction + /// based on the original ZKsync OS execution environment. + pub fn force_fail(mut self, force_fail: bool) -> Self { + self.force_fail = force_fail; + self + } + + /// Set the refund recipient of the L1 -> L2 part of the transaction. + pub fn refund_recipient(mut self, refund_recipient: Option
) -> Self { + self.l1_to_l2_part.refund_recipient = refund_recipient; + self + } + + /// Build the [`ZKsyncTx`] with default values for missing fields. + /// + /// This is useful for testing and debugging where it is not necessary to + /// have full [`ZKsyncTx`] instance. + /// + /// If the source hash is not [`B256::ZERO`], set the transaction type to L1 -> L2 part and remove the enveloped transaction. + pub fn build_fill(self) -> ZKsyncTx { + let base = self.base.build_fill(); + + ZKsyncTx { + base, + l1_to_l2_part: self.l1_to_l2_part, + gas_used_override: self.gas_used_override, + force_fail: self.force_fail, + } + } + + /// Build the [`ZKsyncTx`] instance, return error if the transaction is not valid. + /// + pub fn build(self) -> Result, ZkBuilderror> { + let base = self.base.build()?; + + Ok(ZKsyncTx { + base, + l1_to_l2_part: self.l1_to_l2_part, + gas_used_override: self.gas_used_override, + force_fail: self.force_fail, + }) + } +} + +/// Error type for building [`TxEnv`] +#[derive( + Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] +pub enum ZkBuilderror { + /// Base transaction build error + Base(TxEnvBuildError), +} + +impl From for ZkBuilderror { + fn from(error: TxEnvBuildError) -> Self { + ZkBuilderror::Base(error) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use revm::{context_interface::Transaction, primitives::Address}; + + #[test] + fn test_deposit_transaction_fields() { + let base_tx = TxEnv::builder() + .gas_limit(10) + .gas_price(100) + .gas_priority_fee(Some(5)); + + let zk_tx = ZKsyncTx::builder() + .base(base_tx) + .mint(U256::ZERO) + .build() + .unwrap(); + // Verify transaction type (deposit transactions should have tx_type based on ZkSpecId) + // The tx_type is derived from the transaction structure, not set manually + // Verify common fields access + assert_eq!(zk_tx.gas_limit(), 10); + assert_eq!(zk_tx.kind(), revm::primitives::TxKind::Call(Address::ZERO)); + // Verify gas related calculations - deposit transactions use gas_price for effective gas price + assert_eq!(zk_tx.effective_gas_price(90), 95); + assert_eq!(zk_tx.max_fee_per_gas(), 100); + } +} diff --git a/src/transaction/error.rs b/src/transaction/error.rs new file mode 100644 index 0000000..a6093f5 --- /dev/null +++ b/src/transaction/error.rs @@ -0,0 +1,51 @@ +//! Contains the `[ZKsyncTxError]` type. +use core::fmt::Display; +use revm::context_interface::{ + result::{EVMError, InvalidTransaction}, + transaction::TransactionError, +}; + +/// ZKsync OS transaction validation error. +#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub enum ZKsyncTxError { + /// Base transaction error. + Base(InvalidTransaction), +} + +impl TransactionError for ZKsyncTxError {} + +impl Display for ZKsyncTxError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Base(error) => error.fmt(f), + } + } +} + +impl core::error::Error for ZKsyncTxError {} + +impl From for ZKsyncTxError { + fn from(value: InvalidTransaction) -> Self { + Self::Base(value) + } +} + +impl From for EVMError { + fn from(value: ZKsyncTxError) -> Self { + Self::Transaction(value) + } +} + +#[cfg(test)] +mod test { + use super::*; + use std::string::ToString; + + #[test] + fn test_display_zk_errors() { + assert_eq!( + ZKsyncTxError::Base(InvalidTransaction::NonceTooHigh { tx: 2, state: 1 }).to_string(), + "nonce 2 too high, expected 1" + ); + } +} diff --git a/src/transaction/priority_tx.rs b/src/transaction/priority_tx.rs new file mode 100644 index 0000000..488b11d --- /dev/null +++ b/src/transaction/priority_tx.rs @@ -0,0 +1,24 @@ +//! Contains Deposit transaction parts. +use revm::primitives::{Address, U256}; + +/// Upgrade transaction type. +pub const UPGRADE_TRANSACTION_TYPE: u8 = 0x7E; + +/// Priority transaction type. +pub const L1_PRIORITY_TRANSACTION_TYPE: u8 = 0x7f; + +/// Deposit transaction parts. +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct L1ToL2TransactionParts { + pub mint: Option, + pub refund_recipient: Option
, +} + +impl L1ToL2TransactionParts { + pub fn new(mint: Option, refund_recipient: Option
) -> Self { + Self { + mint, + refund_recipient, + } + } +}