From ae908ee23dd883b1f7883f86fa1222370c88915e Mon Sep 17 00:00:00 2001 From: zjkree Date: Tue, 24 Dec 2024 06:32:46 +0100 Subject: [PATCH 01/10] Offchain scaffolding. --- .gitignore | 4 +- flake.nix | 2 + offchain/Cargo.lock | 1729 +++++++++++++++++++ offchain/Cargo.toml | 9 + offchain/src/compiler/ast.rs | 15 + offchain/src/compiler/bytecode_generator.rs | 7 + offchain/src/compiler/bytecode_parser.rs | 7 + offchain/src/compiler/mod.rs | 5 + offchain/src/evm_integration/mod.rs | 1 + offchain/src/evm_integration/revm_runner.rs | 5 + offchain/src/gp/genetic_ops.rs | 10 + offchain/src/gp/mod.rs | 13 + offchain/src/gp/population.rs | 9 + offchain/src/main.rs | 9 + 14 files changed, 1824 insertions(+), 1 deletion(-) create mode 100644 offchain/Cargo.lock create mode 100644 offchain/Cargo.toml create mode 100644 offchain/src/compiler/ast.rs create mode 100644 offchain/src/compiler/bytecode_generator.rs create mode 100644 offchain/src/compiler/bytecode_parser.rs create mode 100644 offchain/src/compiler/mod.rs create mode 100644 offchain/src/evm_integration/mod.rs create mode 100644 offchain/src/evm_integration/revm_runner.rs create mode 100644 offchain/src/gp/genetic_ops.rs create mode 100644 offchain/src/gp/mod.rs create mode 100644 offchain/src/gp/population.rs create mode 100644 offchain/src/main.rs diff --git a/.gitignore b/.gitignore index c46aa2b..e572021 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ onchain/cache/ -onchain/out/ \ No newline at end of file +onchain/out/ + +offchain/target/ \ No newline at end of file diff --git a/flake.nix b/flake.nix index d4ce681..98c11bc 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,8 @@ # ... any other dependencies we need solc + cargo + rustc ]; # Decorative prompt override so we know when we're in a dev shell diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock new file mode 100644 index 0000000..cb08dbb --- /dev/null +++ b/offchain/Cargo.lock @@ -0,0 +1,1729 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "alloy-eip2930" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "serde", +] + +[[package]] +name = "alloy-eip7702" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" +dependencies = [ + "alloy-primitives", + "alloy-rlp", + "derive_more", + "k256", + "serde", +] + +[[package]] +name = "alloy-primitives" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6259a506ab13e1d658796c31e6e39d2e2ee89243bcc505ddc613b35732e0a430" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if", + "const-hex", + "derive_more", + "foldhash", + "hashbrown", + "hex-literal", + "indexmap", + "itoa", + "k256", + "keccak-asm", + "paste", + "proptest", + "rand", + "ruint", + "rustc-hash", + "serde", + "sha3", + "tiny-keccak", +] + +[[package]] +name = "alloy-rlp" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f542548a609dca89fcd72b3b9f355928cf844d4363c5eed9c5273a3dd225e097" +dependencies = [ + "alloy-rlp-derive", + "arrayvec", + "bytes", +] + +[[package]] +name = "alloy-rlp-derive" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a833d97bf8a5f0f878daf2c8451fff7de7f9de38baa5a45d936ec718d81255a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[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", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.4.1", + "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-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-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-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", +] + +[[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.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aef7712851e524f35fbbb74fa6599c5cd8692056a1c36f9ca0d2001b670e7e5" +dependencies = [ + "hex", + "num", +] + +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "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.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4378725facc195f1a538864863f6de233b500a8862747e7f165078a419d5e874" +dependencies = [ + "cc", + "glob", + "threadpool", + "zeroize", +] + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" + +[[package]] +name = "c-kzg" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0307f72feab3300336fb803a57134159f6e20139af1357f36c54cb90d8e8928" +dependencies = [ + "blst", + "cc", + "glob", + "hex", + "libc", + "once_cell", + "serde", +] + +[[package]] +name = "cc" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-hex" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b0485bab839b018a8f1723fc5391819fea5f8f0f32288ef8a735fd096b6160c" +dependencies = [ + "cfg-if", + "cpufeatures", + "hex", + "proptest", + "serde", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "cpufeatures" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[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", + "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 = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[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_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", + "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.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[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 = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[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", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "enumn" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys", +] + +[[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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "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.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + +[[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.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[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 = "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.91", +] + +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + +[[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" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[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-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.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "offchain" +version = "0.1.0" +dependencies = [ + "revm", + "serde", + "serde_json", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "parity-scale-codec" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pest" +version = "2.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[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.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags", + "lazy_static", + "num-traits", + "rand", + "rand_chacha", + "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.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[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", + "rand_core", +] + +[[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", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "revm" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15689a3c6a8d14b647b4666f2e236ef47b5a5133cdfd423f545947986fff7013" +dependencies = [ + "auto_impl", + "cfg-if", + "dyn-clone", + "revm-interpreter", + "revm-precompile", + "serde", + "serde_json", +] + +[[package]] +name = "revm-interpreter" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74e3f11d0fed049a4a10f79820c59113a79b38aed4ebec786a79d5c667bfeb51" +dependencies = [ + "revm-primitives", + "serde", +] + +[[package]] +name = "revm-precompile" +version = "15.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e381060af24b750069a2b2d2c54bba273d84e8f5f9e8026fc9262298e26cc336" +dependencies = [ + "aurora-engine-modexp", + "blst", + "c-kzg", + "cfg-if", + "k256", + "once_cell", + "revm-primitives", + "ripemd", + "secp256k1", + "sha2", + "substrate-bn", +] + +[[package]] +name = "revm-primitives" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3702f132bb484f4f0d0ca4f6fbde3c82cfd745041abbedd6eda67730e1868ef0" +dependencies = [ + "alloy-eip2930", + "alloy-eip7702", + "alloy-primitives", + "auto_impl", + "bitflags", + "bitvec", + "c-kzg", + "cfg-if", + "dyn-clone", + "enumn", + "hex", + "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 = "ruint" +version = "1.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5ef8fb1dd8de3870cb8400d51b4c2023854bbafd5431a3ac7e7317243e22d2f" +dependencies = [ + "alloy-rlp", + "ark-ff 0.3.0", + "ark-ff 0.4.2", + "bytes", + "fastrlp 0.3.1", + "fastrlp 0.4.0", + "num-bigint", + "num-integer", + "num-traits", + "parity-scale-codec", + "primitive-types", + "proptest", + "rand", + "rlp", + "ruint-macro", + "serde", + "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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" + +[[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.24", +] + +[[package]] +name = "rustix" +version = "0.38.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[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.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[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.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" +dependencies = [ + "rand", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +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.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" + +[[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.216" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.216" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "serde_json" +version = "1.0.134" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +dependencies = [ + "indexmap", + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +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", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[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 = "substrate-bn" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b5bbfa79abbae15dd642ea8176a21a635ff3c00059961d1ea27ad04e5b441c" +dependencies = [ + "byteorder", + "crunchy", + "lazy_static", + "rand", + "rustc-hex", +] + +[[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.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" +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.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[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.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[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.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "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.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[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.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +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.91", +] diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml new file mode 100644 index 0000000..a469b76 --- /dev/null +++ b/offchain/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "offchain" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +revm = "18.0.0" \ No newline at end of file diff --git a/offchain/src/compiler/ast.rs b/offchain/src/compiler/ast.rs new file mode 100644 index 0000000..5f2bad2 --- /dev/null +++ b/offchain/src/compiler/ast.rs @@ -0,0 +1,15 @@ +#[derive(Debug, Clone)] +pub enum Expr { + IntLiteral(i32), + Instruction(InstructionKind, Vec), + // You might have a variant for sublists if needed, + // or keep it all in the same structure. +} + +#[derive(Debug, Clone)] +pub enum InstructionKind { + // e.g. Plus, Minus, Mult, etc. + Plus, + Minus, + Mult, +} diff --git a/offchain/src/compiler/bytecode_generator.rs b/offchain/src/compiler/bytecode_generator.rs new file mode 100644 index 0000000..4e09c0e --- /dev/null +++ b/offchain/src/compiler/bytecode_generator.rs @@ -0,0 +1,7 @@ +use super::ast::{Expr, InstructionKind}; + +pub fn ast_to_bytecode(expr: &Expr) -> Vec { + // for now, just a stub + // eventually we produce push3 tokens + vec![] +} diff --git a/offchain/src/compiler/bytecode_parser.rs b/offchain/src/compiler/bytecode_parser.rs new file mode 100644 index 0000000..9ab1e94 --- /dev/null +++ b/offchain/src/compiler/bytecode_parser.rs @@ -0,0 +1,7 @@ +use super::ast::{Expr}; + +pub fn bytecode_to_ast(data: &[u8]) -> Expr { + // parse tokens, produce expr + // stub for now + Expr::IntLiteral(0) +} diff --git a/offchain/src/compiler/mod.rs b/offchain/src/compiler/mod.rs new file mode 100644 index 0000000..2a0c9c4 --- /dev/null +++ b/offchain/src/compiler/mod.rs @@ -0,0 +1,5 @@ +pub mod ast; +pub mod bytecode_generator; +pub mod bytecode_parser; + +// In the future, we'll define or `pub use` them. diff --git a/offchain/src/evm_integration/mod.rs b/offchain/src/evm_integration/mod.rs new file mode 100644 index 0000000..504ad4d --- /dev/null +++ b/offchain/src/evm_integration/mod.rs @@ -0,0 +1 @@ +pub mod revm_runner; diff --git a/offchain/src/evm_integration/revm_runner.rs b/offchain/src/evm_integration/revm_runner.rs new file mode 100644 index 0000000..bf5e021 --- /dev/null +++ b/offchain/src/evm_integration/revm_runner.rs @@ -0,0 +1,5 @@ +pub fn run_in_revm(bytecode: &[u8]) -> Result, String> { + // set up revm, load the code, call push3 + // for now just stub + Ok(vec![]) +} diff --git a/offchain/src/gp/genetic_ops.rs b/offchain/src/gp/genetic_ops.rs new file mode 100644 index 0000000..c86dbbf --- /dev/null +++ b/offchain/src/gp/genetic_ops.rs @@ -0,0 +1,10 @@ +use crate::compiler::ast::{Expr}; + +pub fn crossover(a: &Expr, b: &Expr) -> (Expr, Expr) { + // stub + (a.clone(), b.clone()) +} + +pub fn mutate(expr: &mut Expr) { + // stub +} diff --git a/offchain/src/gp/mod.rs b/offchain/src/gp/mod.rs new file mode 100644 index 0000000..12178cb --- /dev/null +++ b/offchain/src/gp/mod.rs @@ -0,0 +1,13 @@ +pub mod population; +pub mod genetic_ops; +// pub mod fitness; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_dummy() { + assert_eq!(2+2, 4); + } +} diff --git a/offchain/src/gp/population.rs b/offchain/src/gp/population.rs new file mode 100644 index 0000000..fbf9abf --- /dev/null +++ b/offchain/src/gp/population.rs @@ -0,0 +1,9 @@ +#[derive(Debug, Clone)] +pub struct Individual { + pub fitness: f64, + // your Expr or bytecode or both +} + +pub struct Population { + pub individuals: Vec, +} diff --git a/offchain/src/main.rs b/offchain/src/main.rs new file mode 100644 index 0000000..77c0435 --- /dev/null +++ b/offchain/src/main.rs @@ -0,0 +1,9 @@ +mod compiler; +mod gp; +mod evm_integration; + +fn main() { + println!("Welcome to My GP System CLI"); + // e.g., parse arguments, run a small demonstration? + // For now just a stub. +} -- 2.34.1 From 73f3bca65620f655a63d2e63ee3988c36a0021f5 Mon Sep 17 00:00:00 2001 From: zjkree Date: Tue, 24 Dec 2024 07:05:17 +0100 Subject: [PATCH 02/10] Make some progress on ASTs. --- offchain/Cargo.lock | 1 + offchain/Cargo.toml | 3 +- offchain/src/compiler/ast.rs | 109 +++++++++++++++++++- offchain/src/compiler/bytecode_generator.rs | 7 -- offchain/src/compiler/bytecode_parser.rs | 7 -- offchain/src/compiler/mod.rs | 4 - offchain/src/gp/genetic_ops.rs | 16 +-- 7 files changed, 115 insertions(+), 32 deletions(-) delete mode 100644 offchain/src/compiler/bytecode_generator.rs delete mode 100644 offchain/src/compiler/bytecode_parser.rs diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock index cb08dbb..6cdb6aa 100644 --- a/offchain/Cargo.lock +++ b/offchain/Cargo.lock @@ -879,6 +879,7 @@ dependencies = [ name = "offchain" version = "0.1.0" dependencies = [ + "rand", "revm", "serde", "serde_json", diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index a469b76..d10fc94 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -revm = "18.0.0" \ No newline at end of file +revm = "18.0.0" +rand = "0.8" \ No newline at end of file diff --git a/offchain/src/compiler/ast.rs b/offchain/src/compiler/ast.rs index 5f2bad2..65f58cb 100644 --- a/offchain/src/compiler/ast.rs +++ b/offchain/src/compiler/ast.rs @@ -1,15 +1,114 @@ +pub trait Push3Ast { + /// Convert this AST into a bytecode array (Push3 tokens). + fn to_bytecode(&self) -> Vec; + + /// Parse an AST from bytecode (the "decompiler"), if possible. + /// Possibly returns a Result in case of partial/invalid parse. + fn from_bytecode(data: &[u8]) -> Self + where + Self: Sized; + + /// Randomly mutate this AST in-place (GP mutation). + fn mutate(&mut self, rng: &mut impl rand::Rng); + + /// Possibly a "crossover" method, or we do it externally. + // fn crossover(&self, other: &Self, rng: &mut impl rand::Rng) -> Self; + + /// Evaluate the AST with some input(s). + /// Optionally do we want this or do we always run in EVM? + /// We can stub it or do an interpret approach for local test. + fn interpret_locally(&self, inputs: &[i32]) -> Vec; +} + + #[derive(Debug, Clone)] -pub enum Expr { +pub enum TypedAst { IntLiteral(i32), - Instruction(InstructionKind, Vec), - // You might have a variant for sublists if needed, - // or keep it all in the same structure. + Instruction(InstructionKind), } #[derive(Debug, Clone)] pub enum InstructionKind { - // e.g. Plus, Minus, Mult, etc. + Plus(Box, Box), + Minus(Box, Box), + Mult(Box, Box), + Dup, // 0 children + Pop, // 0 children +} + +impl Push3Ast for TypedAst { + fn to_bytecode(&self) -> Vec { + // do typed encoding: + // - for Plus(e1, e2): e1 -> bytecode, e2 -> bytecode, then PLUS opcode + unimplemented!() + } + + fn from_bytecode(data: &[u8]) -> Self { + // parse in a strictly typed manner; might fail or panic + // if the code doesn't line up properly + unimplemented!() + } + + fn mutate(&mut self, rng: &mut impl rand::Rng) { + // e.g. randomly pick a node, replace it with something + // that respects the typed structure + unimplemented!() + } + + fn interpret_locally(&self, inputs: &[i32]) -> Vec { + // do a normal expression evaluation. If a node is "Plus(a,b)", + // interpret (a) + interpret(b). + unimplemented!() + } +} + +#[derive(Debug, Clone)] +pub enum UntypedAst { + /// A single token in a list-based approach, e.g. "Integer literal" + IntLiteral(i32), + + /// "Instruction" might be a simple variant with no children, + /// because the stack-based evaluation decides how many arguments it consumes. + Instruction(OpCode), + + /// A sublist of tokens, e.g. "( 2 3 DUP + )" + Sublist(Vec), +} + +/// Possibly an enum for OpCode: +#[derive(Debug, Clone)] +pub enum OpCode { + Noop, Plus, Minus, Mult, + Dup, + Pop, + // maybe Unknown => treat as no-op +} + +impl Push3Ast for UntypedAst { + fn to_bytecode(&self) -> Vec { + // flatten out sublists vs instructions + unimplemented!() + } + + fn from_bytecode(data: &[u8]) -> Self { + // parse "0x02 => INT_LITERAL => read next 4 bytes" + // instructions might have no subchildren + unimplemented!() + } + + fn mutate(&mut self, rng: &mut impl rand::Rng) { + // can randomly insert unknown tokens, reorder sublists, etc. + // possibly produce "invalid ops => noops" + unimplemented!() + } + + fn interpret_locally(&self, inputs: &[i32]) -> Vec { + // push-based interpretation: + // sublist => interpret each item in sequence + // if an instruction sees insufficient args => no-op + unimplemented!() + } } diff --git a/offchain/src/compiler/bytecode_generator.rs b/offchain/src/compiler/bytecode_generator.rs deleted file mode 100644 index 4e09c0e..0000000 --- a/offchain/src/compiler/bytecode_generator.rs +++ /dev/null @@ -1,7 +0,0 @@ -use super::ast::{Expr, InstructionKind}; - -pub fn ast_to_bytecode(expr: &Expr) -> Vec { - // for now, just a stub - // eventually we produce push3 tokens - vec![] -} diff --git a/offchain/src/compiler/bytecode_parser.rs b/offchain/src/compiler/bytecode_parser.rs deleted file mode 100644 index 9ab1e94..0000000 --- a/offchain/src/compiler/bytecode_parser.rs +++ /dev/null @@ -1,7 +0,0 @@ -use super::ast::{Expr}; - -pub fn bytecode_to_ast(data: &[u8]) -> Expr { - // parse tokens, produce expr - // stub for now - Expr::IntLiteral(0) -} diff --git a/offchain/src/compiler/mod.rs b/offchain/src/compiler/mod.rs index 2a0c9c4..851c0bc 100644 --- a/offchain/src/compiler/mod.rs +++ b/offchain/src/compiler/mod.rs @@ -1,5 +1 @@ pub mod ast; -pub mod bytecode_generator; -pub mod bytecode_parser; - -// In the future, we'll define or `pub use` them. diff --git a/offchain/src/gp/genetic_ops.rs b/offchain/src/gp/genetic_ops.rs index c86dbbf..b5fb028 100644 --- a/offchain/src/gp/genetic_ops.rs +++ b/offchain/src/gp/genetic_ops.rs @@ -1,10 +1,10 @@ -use crate::compiler::ast::{Expr}; +// use crate::compiler::ast::{Expr}; -pub fn crossover(a: &Expr, b: &Expr) -> (Expr, Expr) { - // stub - (a.clone(), b.clone()) -} +// pub fn crossover(a: &Expr, b: &Expr) -> (Expr, Expr) { +// // stub +// (a.clone(), b.clone()) +// } -pub fn mutate(expr: &mut Expr) { - // stub -} +// pub fn mutate(expr: &mut Expr) { +// // stub +// } -- 2.34.1 From b4e723fd2c60e5351eceda9f9b7b3c63ed669fcd Mon Sep 17 00:00:00 2001 From: zjkree Date: Wed, 25 Dec 2024 08:59:48 +0100 Subject: [PATCH 03/10] Minimal working example. Can run programs in CL. --- .envrc | 1 + .gitignore | 4 +- flake.nix | 1 + offchain/Cargo.lock | 2999 ++++++++++++++++++- offchain/Cargo.toml | 12 +- offchain/src/compiler/ast.rs | 556 +++- offchain/src/evm_integration/revm_runner.rs | 5 - offchain/src/main.rs | 179 +- onchain/test/Push3Interpreter.t.sol | 2 +- 9 files changed, 3623 insertions(+), 136 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index e572021..b79784c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ onchain/cache/ onchain/out/ -offchain/target/ \ No newline at end of file +offchain/target/ + +.direnv \ No newline at end of file diff --git a/flake.nix b/flake.nix index 98c11bc..cff4724 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,7 @@ solc cargo rustc + rust-analyzer ]; # Decorative prompt override so we know when we're in a dev shell diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock index 6cdb6aa..d3e9827 100644 --- a/offchain/Cargo.lock +++ b/offchain/Cargo.lock @@ -2,6 +2,51 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "alloy-eip2930" version = "0.1.0" @@ -10,20 +55,17 @@ checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" dependencies = [ "alloy-primitives", "alloy-rlp", - "serde", ] [[package]] name = "alloy-eip7702" -version = "0.4.2" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c986539255fb839d1533c128e190e557e52ff652c9ef62939e233a81dd93f7e" +checksum = "ea59dc42102bc9a1905dc57901edc6dd48b9f38115df86c7d252acba70d71d04" dependencies = [ "alloy-primitives", "alloy-rlp", - "derive_more", "k256", - "serde", ] [[package]] @@ -76,6 +118,12 @@ dependencies = [ "syn 2.0.91", ] +[[package]] +name = "anyhow" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" + [[package]] name = "ark-ff" version = "0.3.0" @@ -106,7 +154,7 @@ dependencies = [ "ark-std 0.4.0", "derivative", "digest 0.10.7", - "itertools", + "itertools 0.10.5", "num-bigint", "num-traits", "paste", @@ -206,6 +254,37 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "async-trait" +version = "0.1.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "async_io_stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" +dependencies = [ + "futures", + "pharos", + "rustc_version 0.4.1", +] + [[package]] name = "aurora-engine-modexp" version = "1.1.0" @@ -233,18 +312,51 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] + [[package]] name = "base16ct" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64ct" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "bit-set" version = "0.5.3" @@ -260,6 +372,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" @@ -299,6 +417,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "sha2", + "tinyvec", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "byte-slice-cast" version = "1.2.2" @@ -316,6 +450,30 @@ name = "bytes" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +dependencies = [ + "serde", +] + +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] [[package]] name = "c-kzg" @@ -332,12 +490,46 @@ dependencies = [ "serde", ] +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.24", + "serde", + "serde_json", + "thiserror 1.0.69", +] + [[package]] name = "cc" version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -347,6 +539,77 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +dependencies = [ + "num-traits", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "coins-bip32" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" +dependencies = [ + "bs58", + "coins-core", + "digest 0.10.7", + "hmac", + "k256", + "serde", + "sha2", + "thiserror 1.0.69", +] + +[[package]] +name = "coins-bip39" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" +dependencies = [ + "bitvec", + "coins-bip32", + "hmac", + "once_cell", + "pbkdf2 0.12.2", + "rand", + "sha2", + "thiserror 1.0.69", +] + +[[package]] +name = "coins-core" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" +dependencies = [ + "base64 0.21.7", + "bech32", + "bs58", + "digest 0.10.7", + "generic-array", + "hex", + "ripemd", + "serde", + "serde_derive", + "sha2", + "sha3", + "thiserror 1.0.69", +] + [[package]] name = "const-hex" version = "1.14.0" @@ -366,6 +629,28 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[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.16" @@ -375,6 +660,40 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crunchy" version = "0.2.2" @@ -403,6 +722,21 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + [[package]] name = "der" version = "0.7.9" @@ -413,6 +747,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derivative" version = "2.2.0" @@ -424,6 +767,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive-where" +version = "1.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + [[package]] name = "derive_more" version = "1.0.0" @@ -467,10 +821,63 @@ dependencies = [ ] [[package]] -name = "dyn-clone" -version = "1.0.17" +name = "dirs" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "ecdsa" @@ -511,6 +918,42 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ena" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d248bdd43ce613d87415282f69b9bb99d947d290b10962dd6c56233312c2ad5" +dependencies = [ + "log", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "enr" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3d8dc56e02f954cac8eb489772c552c473346fc34f67412bb6244fd647f7e4" +dependencies = [ + "base64 0.21.7", + "bytes", + "hex", + "k256", + "log", + "rand", + "rlp", + "serde", + "sha3", + "zeroize", +] + [[package]] name = "enumn" version = "0.1.14" @@ -535,7 +978,335 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.59.0", +] + +[[package]] +name = "eth-keystore" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" +dependencies = [ + "aes", + "ctr", + "digest 0.10.7", + "hex", + "hmac", + "pbkdf2 0.11.0", + "rand", + "scrypt", + "serde", + "serde_json", + "sha2", + "sha3", + "thiserror 1.0.69", + "uuid", +] + +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types", + "hex", + "once_cell", + "regex", + "serde", + "serde_json", + "sha3", + "thiserror 1.0.69", + "uint", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "primitive-types", + "scale-info", + "uint", +] + +[[package]] +name = "ethers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816841ea989f0c69e459af1cf23a6b0033b19a55424a1ea3a30099becdb8dec0" +dependencies = [ + "ethers-addressbook", + "ethers-contract", + "ethers-core", + "ethers-etherscan", + "ethers-middleware", + "ethers-providers", + "ethers-signers", + "ethers-solc", +] + +[[package]] +name = "ethers-addressbook" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5495afd16b4faa556c3bba1f21b98b4983e53c1755022377051a975c3b021759" +dependencies = [ + "ethers-core", + "once_cell", + "serde", + "serde_json", +] + +[[package]] +name = "ethers-contract" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fceafa3578c836eeb874af87abacfb041f92b4da0a78a5edd042564b8ecdaaa" +dependencies = [ + "const-hex", + "ethers-contract-abigen", + "ethers-contract-derive", + "ethers-core", + "ethers-providers", + "futures-util", + "once_cell", + "pin-project", + "serde", + "serde_json", + "thiserror 1.0.69", +] + +[[package]] +name = "ethers-contract-abigen" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04ba01fbc2331a38c429eb95d4a570166781f14290ef9fdb144278a90b5a739b" +dependencies = [ + "Inflector", + "const-hex", + "dunce", + "ethers-core", + "ethers-etherscan", + "eyre", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "reqwest", + "serde", + "serde_json", + "syn 2.0.91", + "toml", + "walkdir", +] + +[[package]] +name = "ethers-contract-derive" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87689dcabc0051cde10caaade298f9e9093d65f6125c14575db3fd8c669a168f" +dependencies = [ + "Inflector", + "const-hex", + "ethers-contract-abigen", + "ethers-core", + "proc-macro2", + "quote", + "serde_json", + "syn 2.0.91", +] + +[[package]] +name = "ethers-core" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d80cc6ad30b14a48ab786523af33b37f28a8623fc06afd55324816ef18fb1f" +dependencies = [ + "arrayvec", + "bytes", + "cargo_metadata", + "chrono", + "const-hex", + "elliptic-curve", + "ethabi", + "generic-array", + "k256", + "num_enum", + "once_cell", + "open-fastrlp", + "rand", + "rlp", + "serde", + "serde_json", + "strum", + "syn 2.0.91", + "tempfile", + "thiserror 1.0.69", + "tiny-keccak", + "unicode-xid", +] + +[[package]] +name = "ethers-etherscan" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79e5973c26d4baf0ce55520bd732314328cabe53193286671b47144145b9649" +dependencies = [ + "chrono", + "ethers-core", + "reqwest", + "semver 1.0.24", + "serde", + "serde_json", + "thiserror 1.0.69", + "tracing", +] + +[[package]] +name = "ethers-middleware" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f9fdf09aec667c099909d91908d5eaf9be1bd0e2500ba4172c1d28bfaa43de" +dependencies = [ + "async-trait", + "auto_impl", + "ethers-contract", + "ethers-core", + "ethers-etherscan", + "ethers-providers", + "ethers-signers", + "futures-channel", + "futures-locks", + "futures-util", + "instant", + "reqwest", + "serde", + "serde_json", + "thiserror 1.0.69", + "tokio", + "tracing", + "tracing-futures", + "url", +] + +[[package]] +name = "ethers-providers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6434c9a33891f1effc9c75472e12666db2fa5a0fec4b29af6221680a6fe83ab2" +dependencies = [ + "async-trait", + "auto_impl", + "base64 0.21.7", + "bytes", + "const-hex", + "enr", + "ethers-core", + "futures-core", + "futures-timer", + "futures-util", + "hashers", + "http", + "instant", + "jsonwebtoken", + "once_cell", + "pin-project", + "reqwest", + "serde", + "serde_json", + "thiserror 1.0.69", + "tokio", + "tokio-tungstenite", + "tracing", + "tracing-futures", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "ws_stream_wasm", +] + +[[package]] +name = "ethers-signers" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228875491c782ad851773b652dd8ecac62cda8571d3bc32a5853644dd26766c2" +dependencies = [ + "async-trait", + "coins-bip32", + "coins-bip39", + "const-hex", + "elliptic-curve", + "eth-keystore", + "ethers-core", + "rand", + "sha2", + "thiserror 1.0.69", + "tracing", +] + +[[package]] +name = "ethers-solc" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66244a771d9163282646dbeffe0e6eca4dda4146b6498644e678ac6089b11edd" +dependencies = [ + "cfg-if", + "const-hex", + "dirs", + "dunce", + "ethers-core", + "glob", + "home", + "md-5", + "num_cpus", + "once_cell", + "path-slash", + "rayon", + "regex", + "semver 1.0.24", + "serde", + "serde_json", + "solang-parser", + "svm-rs", + "thiserror 1.0.69", + "tiny-keccak", + "tokio", + "tracing", + "walkdir", + "yansi", +] + +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", ] [[package]] @@ -588,6 +1359,22 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "flate2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -600,12 +1387,149 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-locks" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" +dependencies = [ + "futures-channel", + "futures-task", +] + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" +dependencies = [ + "gloo-timers", + "send_wrapper 0.4.0", +] + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -628,12 +1552,30 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + [[package]] name = "glob" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "group" version = "0.13.0" @@ -645,6 +1587,25 @@ dependencies = [ "subtle", ] +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.15.2" @@ -654,6 +1615,21 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hashers" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" +dependencies = [ + "fxhash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -681,6 +1657,226 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http", + "hyper", + "rustls", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "impl-codec" version = "0.6.0" @@ -690,6 +1886,24 @@ dependencies = [ "parity-scale-codec", ] +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + [[package]] name = "impl-trait-for-tuples" version = "0.2.3" @@ -701,6 +1915,12 @@ dependencies = [ "syn 2.0.91", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "2.7.0" @@ -711,6 +1931,30 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + [[package]] name = "itertools" version = "0.10.5" @@ -720,12 +1964,54 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "jsonwebtoken" +version = "8.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" +dependencies = [ + "base64 0.21.7", + "pem", + "ring 0.16.20", + "serde", + "serde_json", + "simple_asn1", +] + [[package]] name = "k256" version = "0.13.4" @@ -737,6 +2023,7 @@ dependencies = [ "elliptic-curve", "once_cell", "sha2", + "signature", ] [[package]] @@ -758,13 +2045,43 @@ dependencies = [ "sha3-asm", ] +[[package]] +name = "lalrpop" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cb077ad656299f160924eb2912aa147d7339ea7d69e1b5517326fdcec3c1ca" +dependencies = [ + "ascii-canvas", + "bit-set", + "ena", + "itertools 0.11.0", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", + "walkdir", +] + +[[package]] +name = "lalrpop-util" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" +dependencies = [ + "regex-automata", +] + [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin", + "spin 0.9.8", ] [[package]] @@ -779,18 +2096,92 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest 0.10.7", +] + [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + [[package]] name = "num" version = "0.4.3" @@ -824,6 +2215,12 @@ 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" @@ -875,12 +2272,46 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + [[package]] name = "offchain" version = "0.1.0" dependencies = [ + "anyhow", + "ethers", + "hex", "rand", "revm", + "revm-database", "serde", "serde_json", ] @@ -891,6 +2322,37 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "open-fastrlp" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", + "ethereum-types", + "open-fastrlp-derive", +] + +[[package]] +name = "open-fastrlp-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" +dependencies = [ + "bytes", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -917,12 +2379,89 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + [[package]] name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac", +] + +[[package]] +name = "pem" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +dependencies = [ + "base64 0.13.1", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pest" version = "2.7.15" @@ -930,10 +2469,113 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror", + "thiserror 2.0.9", "ucd-trie", ] +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "pharos" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" +dependencies = [ + "futures", + "rustc_version 0.4.1", +] + +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared 0.11.2", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared 0.11.2", + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkcs8" version = "0.10.2" @@ -944,6 +2586,18 @@ dependencies = [ "spki", ] +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[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.20" @@ -953,6 +2607,22 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "prettyplease" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn 2.0.91", +] + [[package]] name = "primitive-types" version = "0.12.2" @@ -961,6 +2631,9 @@ checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", "uint", ] @@ -990,7 +2663,7 @@ checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bit-set", "bit-vec", - "bitflags", + "bitflags 2.6.0", "lazy_static", "num-traits", "rand", @@ -1062,6 +2735,69 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" +dependencies = [ + "bitflags 2.6.0", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror 1.0.69", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.8.5" @@ -1069,35 +2805,168 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] -name = "revm" -version = "18.0.0" +name = "reqwest" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15689a3c6a8d14b647b4666f2e236ef47b5a5133cdfd423f545947986fff7013" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ - "auto_impl", - "cfg-if", - "dyn-clone", - "revm-interpreter", - "revm-precompile", + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", "serde", "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + +[[package]] +name = "revm" +version = "14.0.1" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "revm-bytecode", + "revm-context", + "revm-context-interface", + "revm-database-interface", + "revm-handler", + "revm-handler-interface", + "revm-interpreter", + "revm-precompile", + "revm-primitives", + "revm-specification", + "revm-state", +] + +[[package]] +name = "revm-bytecode" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "bitvec", + "revm-primitives", + "revm-specification", +] + +[[package]] +name = "revm-context" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "cfg-if", + "derive-where", + "revm-bytecode", + "revm-context-interface", + "revm-database-interface", + "revm-interpreter", + "revm-primitives", + "revm-specification", + "revm-state", +] + +[[package]] +name = "revm-context-interface" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "auto_impl", + "revm-database-interface", + "revm-primitives", + "revm-specification", + "revm-state", + "serde", +] + +[[package]] +name = "revm-database" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "auto_impl", + "revm-bytecode", + "revm-context-interface", + "revm-database-interface", + "revm-primitives", + "revm-state", + "serde", +] + +[[package]] +name = "revm-database-interface" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "auto_impl", + "revm-primitives", + "revm-state", +] + +[[package]] +name = "revm-handler" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "revm-bytecode", + "revm-context-interface", + "revm-handler-interface", + "revm-interpreter", + "revm-precompile", + "revm-primitives", + "revm-specification", + "revm-state", + "serde", +] + +[[package]] +name = "revm-handler-interface" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "revm-interpreter", + "revm-primitives", ] [[package]] name = "revm-interpreter" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74e3f11d0fed049a4a10f79820c59113a79b38aed4ebec786a79d5c667bfeb51" +version = "10.0.1" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" dependencies = [ + "revm-bytecode", + "revm-context-interface", "revm-primitives", + "revm-specification", "serde", ] [[package]] name = "revm-precompile" -version = "15.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e381060af24b750069a2b2d2c54bba273d84e8f5f9e8026fc9262298e26cc336" +version = "11.0.1" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" dependencies = [ "aurora-engine-modexp", "blst", @@ -1105,7 +2974,9 @@ dependencies = [ "cfg-if", "k256", "once_cell", + "revm-context-interface", "revm-primitives", + "revm-specification", "ripemd", "secp256k1", "sha2", @@ -1114,22 +2985,33 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3702f132bb484f4f0d0ca4f6fbde3c82cfd745041abbedd6eda67730e1868ef0" +version = "9.0.1" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "alloy-primitives", +] + +[[package]] +name = "revm-specification" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" dependencies = [ "alloy-eip2930", "alloy-eip7702", "alloy-primitives", - "auto_impl", - "bitflags", - "bitvec", - "c-kzg", - "cfg-if", - "dyn-clone", "enumn", - "hex", - "serde", + "revm-primitives", +] + +[[package]] +name = "revm-state" +version = "1.0.0" +source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" +dependencies = [ + "bitflags 2.6.0", + "revm-bytecode", + "revm-primitives", + "revm-specification", ] [[package]] @@ -1142,6 +3024,36 @@ dependencies = [ "subtle", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + [[package]] name = "ripemd" version = "0.1.3" @@ -1158,9 +3070,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ "bytes", + "rlp-derive", "rustc-hex", ] +[[package]] +name = "rlp-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "ruint" version = "1.12.4" @@ -1193,6 +3117,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + [[package]] name = "rustc-hash" version = "2.1.0" @@ -1229,13 +3159,50 @@ version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ - "bitflags", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.59.0", ] +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring 0.17.8", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "rusty-fork" version = "0.3.0" @@ -1254,6 +3221,76 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scale-info" +version = "2.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346a3b32eba2640d17a9cb5927056b08f3de90f65b72fe09402c2ad07d684d0b" +dependencies = [ + "cfg-if", + "derive_more", + "parity-scale-codec", + "scale-info-derive", +] + +[[package]] +name = "scale-info-derive" +version = "2.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6630024bf739e2179b91fb424b28898baf819414262c5d376677dbff1fe7ebf" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac", + "pbkdf2 0.11.0", + "salsa20", + "sha2", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + [[package]] name = "sec1" version = "0.7.3" @@ -1301,6 +3338,9 @@ name = "semver" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" +dependencies = [ + "serde", +] [[package]] name = "semver-parser" @@ -1311,6 +3351,18 @@ dependencies = [ "pest", ] +[[package]] +name = "send_wrapper" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" + +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" version = "1.0.216" @@ -1337,13 +3389,44 @@ version = "1.0.134" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" dependencies = [ - "indexmap", "itoa", "memchr", "ryu", "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1391,6 +3474,69 @@ dependencies = [ "rand_core", ] +[[package]] +name = "simple_asn1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror 1.0.69", + "time", +] + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "solang-parser" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c425ce1c59f4b154717592f0bdf4715c3a1d55058883622d3157e1f0908a5b26" +dependencies = [ + "itertools 0.11.0", + "lalrpop", + "lalrpop-util", + "phf", + "thiserror 1.0.69", + "unicode-xid", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -1407,12 +3553,53 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", +] + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.91", +] + [[package]] name = "substrate-bn" version = "0.6.0" @@ -1432,6 +3619,26 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "svm-rs" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11297baafe5fa0c99d5722458eac6a5e25c01eb1b8e5cd137f54079093daa7a4" +dependencies = [ + "dirs", + "fs2", + "hex", + "once_cell", + "reqwest", + "semver 1.0.24", + "serde", + "serde_json", + "sha2", + "thiserror 1.0.69", + "url", + "zip", +] + [[package]] name = "syn" version = "1.0.109" @@ -1454,6 +3661,44 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" @@ -1470,7 +3715,27 @@ dependencies = [ "fastrand", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.59.0", +] + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", ] [[package]] @@ -1479,7 +3744,18 @@ version = "2.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.9", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", ] [[package]] @@ -1502,6 +3778,37 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -1511,11 +3818,104 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "022db8904dfa342efe721985167e9fcd16c29b226db4397ed752a761cfce81e8" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +dependencies = [ + "futures-util", + "log", + "rustls", + "tokio", + "tokio-rustls", + "tungstenite", + "webpki-roots", +] + +[[package]] +name = "tokio-util" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -1524,10 +3924,85 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[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.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "rustls", + "sha1", + "thiserror 1.0.69", + "url", + "utf-8", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1570,6 +4045,57 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "valuable" version = "0.1.0" @@ -1591,19 +4117,185 @@ dependencies = [ "libc", ] +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn 2.0.91", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" + +[[package]] +name = "web-sys" +version = "0.3.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -1612,28 +4304,46 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1646,24 +4356,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -1679,6 +4413,47 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "ws_stream_wasm" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" +dependencies = [ + "async_io_stream", + "futures", + "js-sys", + "log", + "pharos", + "rustc_version 0.4.1", + "send_wrapper 0.6.0", + "thiserror 1.0.69", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "wyz" version = "0.5.1" @@ -1688,6 +4463,36 @@ dependencies = [ "tap", ] +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -1709,6 +4514,27 @@ dependencies = [ "syn 2.0.91", ] +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" @@ -1728,3 +4554,74 @@ dependencies = [ "quote", "syn 2.0.91", ] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.91", +] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2 0.11.0", + "sha1", + "time", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index d10fc94..fffccda 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -6,5 +6,13 @@ edition = "2021" [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -revm = "18.0.0" -rand = "0.8" \ No newline at end of file +rand = "0.8" +hex = "0.4" +# ethers = { version = "2.0", features = ["abi"] } +anyhow = "1.0" +revm = { git = "https://github.com/bluealloy/revm.git", rev = "03ea24bd9550e93b08f343e0b410725557c1adb4", features = ["std"] } +database = { git = "https://github.com/bluealloy/revm.git", rev = "03ea24bd9550e93b08f343e0b410725557c1adb4", package = "revm-database" } +ethers = "2.0" + + + diff --git a/offchain/src/compiler/ast.rs b/offchain/src/compiler/ast.rs index 65f58cb..a8929d7 100644 --- a/offchain/src/compiler/ast.rs +++ b/offchain/src/compiler/ast.rs @@ -1,25 +1,340 @@ +// pub trait Push3Ast { +// /// Convert this AST into a bytecode array (Push3 tokens). +// fn to_bytecode(&self) -> Vec; + +// // Parse an AST from bytecode (the "decompiler"), if possible. +// // Possibly returns a Result in case of partial/invalid parse. +// // fn from_bytecode(data: &[u8]) -> Self +// // where +// // Self: Sized; + +// // Randomly mutate this AST in-place (GP mutation). +// // fn mutate(&mut self, rng: &mut impl rand::Rng); + +// // Possibly a "crossover" method, or we do it externally. +// // fn crossover(&self, other: &Self, rng: &mut impl rand::Rng) -> Self; + +// // Evaluate the AST with some input(s). +// // Optionally do we want this or do we always run in EVM? +// // We can stub it or do an interpret approach for local test. +// // fn interpret_locally(&self, inputs: &[i32]) -> Vec; +// } + + +// #[derive(Debug, Clone)] +// pub enum TypedAst { +// IntLiteral(i32), +// Instruction(InstructionKind), +// } + +// #[derive(Debug, Clone)] +// pub enum InstructionKind { +// Plus(Box, Box), +// Minus(Box, Box), +// Mult(Box, Box), +// Dup, // 0 children +// Pop, // 0 children +// } + +// impl Push3Ast for TypedAst { +// fn to_bytecode(&self) -> Vec { +// // do typed encoding: +// // - for Plus(e1, e2): e1 -> bytecode, e2 -> bytecode, then PLUS opcode +// unimplemented!() +// } + +// // fn from_bytecode(data: &[u8]) -> Self { +// // // parse in a strictly typed manner; might fail or panic +// // // if the code doesn't line up properly +// // unimplemented!() +// // } + +// // fn mutate(&mut self, rng: &mut impl rand::Rng) { +// // // e.g. randomly pick a node, replace it with something +// // // that respects the typed structure +// // unimplemented!() +// // } + +// // fn interpret_locally(&self, inputs: &[i32]) -> Vec { +// // // do a normal expression evaluation. If a node is "Plus(a,b)", +// // // interpret (a) + interpret(b). +// // unimplemented!() +// // } +// } + +// #[derive(Debug, Clone)] +// pub enum UntypedAst { +// /// A single token in a list-based approach, e.g. "Integer literal" +// IntLiteral(i32), + +// /// "Instruction" might be a simple variant with no children, +// /// because the stack-based evaluation decides how many arguments it consumes. +// Instruction(OpCode), + +// /// A sublist of tokens, e.g. "( 2 3 DUP + )" +// Sublist(Vec), +// } + +// /// Possibly an enum for OpCode: +// #[derive(Debug, Clone)] +// pub enum OpCode { +// Noop, +// Plus, +// Minus, +// Mult, +// Dup, +// Pop, +// // maybe Unknown => treat as no-op +// } + +// // impl Push3Ast for UntypedAst { +// // fn to_bytecode(&self) -> Vec { +// // // flatten out sublists vs instructions +// // unimplemented!() +// // } + +// // // fn from_bytecode(data: &[u8]) -> Self { +// // // // parse "0x02 => INT_LITERAL => read next 4 bytes" +// // // // instructions might have no subchildren +// // // unimplemented!() +// // // } + +// // // fn mutate(&mut self, rng: &mut impl rand::Rng) { +// // // // can randomly insert unknown tokens, reorder sublists, etc. +// // // // possibly produce "invalid ops => noops" +// // // unimplemented!() +// // // } + +// // // fn interpret_locally(&self, inputs: &[i32]) -> Vec { +// // // // push-based interpretation: +// // // // sublist => interpret each item in sequence +// // // // if an instruction sees insufficient args => no-op +// // // unimplemented!() +// // // } +// // } + +// use crate::compiler::ast::Push3Ast; + +// /// An untyped AST node, matching your Push3 structure. +// #[derive(Debug, Clone)] +// pub enum UntypedAst { +// /// A single integer literal. +// IntLiteral(i32), +// /// A single push instruction (no subchildren). +// Instruction(OpCode), +// /// A sublist of items, each of which is another UntypedAst. +// Sublist(Vec), +// } + +// /// Your Push3 opcodes in an untyped form. +// #[derive(Debug, Clone)] +// pub enum OpCode { +// Noop, +// Plus, +// Minus, +// Mult, +// Dup, +// Pop, +// } + +// /// Implementation of `Push3Ast` for `UntypedAst`. +// /// +// /// This will produce **bytecode** compatible with your Solidity `Push3Interpreter`: +// /// +// /// - `0x00` => NOOP +// /// - `0x01` => INTEGER_PLUS +// /// - `0x02` => INT_LITERAL => next 4 bytes (little-endian i32) +// /// - `0x03` => SUBLIST => next 2 bytes (big-endian `u16` length), then the sublist contents +// /// - `0x04` => INTEGER_MINUS +// /// - `0x05` => INTEGER_MULT +// /// - `0x06` => INTEGER_DUP +// /// - `0x07` => INTEGER_POP +// /// +// /// In the Solidity parser, `SUBLIST (0x03)` consumes two bytes to determine +// /// how many bytes of tokens to read in that sublist. +// impl Push3Ast for UntypedAst { +// /// Convert this untyped AST into a flattened push3 bytecode sequence. +// fn to_bytecode(&self) -> Vec { +// match self { +// UntypedAst::IntLiteral(val) => { +// // 0x02 followed by 4 bytes of i32 (little-endian) +// let mut bytes = Vec::with_capacity(1 + 4); +// bytes.push(0x02); +// bytes.extend_from_slice(&val.to_le_bytes()); +// bytes +// } +// UntypedAst::Instruction(op) => { +// // Single opcode byte +// let opcode_byte = match op { +// OpCode::Noop => 0x00, +// OpCode::Plus => 0x01, +// OpCode::Minus => 0x04, +// OpCode::Mult => 0x05, +// OpCode::Dup => 0x06, +// OpCode::Pop => 0x07, +// }; +// vec![opcode_byte] +// } +// UntypedAst::Sublist(children) => { +// // 0x03 => SUBLIST +// // Then 2 bytes for length (big-endian u16), +// // Then the concatenated bytecode for all children. +// let mut payload = Vec::new(); +// for child in children { +// let child_bytes = child.to_bytecode(); +// payload.extend_from_slice(&child_bytes); +// } +// let sub_len = payload.len() as u16; // assume it fits in 65535 +// let mut bytes = Vec::with_capacity(1 + 2 + payload.len()); +// bytes.push(0x03); +// // Store the sublist length as big-endian, because readUint16 in solidity +// // does `val = uint16(word >> 240)` (effectively big-endian). +// bytes.extend_from_slice(&sub_len.to_be_bytes()); +// // Then the actual sublist payload +// bytes.extend_from_slice(&payload); +// bytes +// } +// } +// } +// } + + +// #[derive(Debug, Clone, PartialEq)] +// pub enum SExpr { +// Atom(String), // e.g. "3", "DUP", "+" +// List(Vec), // e.g. (3 5 +) +// } + +// fn tokenize(s: &str) -> Vec { +// let mut tokens = Vec::new(); +// let mut current = String::new(); + +// for c in s.chars() { +// match c { +// '(' | ')' => { +// // If we were building up an atom, push it first +// if !current.trim().is_empty() { +// tokens.push(current.trim().to_string()); +// } +// current.clear(); +// // Then push the single-char token +// tokens.push(c.to_string()); +// } +// ' ' | '\t' | '\n' | '\r' => { +// // Whitespace => if we have an atom, finish it +// if !current.trim().is_empty() { +// tokens.push(current.trim().to_string()); +// current.clear(); +// } +// } +// _ => { +// // Part of an atom +// current.push(c); +// } +// } +// } + +// // If something is left in 'current' at the end +// if !current.trim().is_empty() { +// tokens.push(current.trim().to_string()); +// } + +// tokens +// } + + +// fn parse_sexpr(tokens: &[String], pos: &mut usize) -> Result { +// // If we’re out of tokens, error +// if *pos >= tokens.len() { +// return Err("Unexpected end of tokens".into()); +// } + +// let token = &tokens[*pos]; +// match token.as_str() { +// "(" => { +// // Parse a list +// *pos += 1; // consume '(' +// let mut list_items = Vec::new(); + +// while *pos < tokens.len() && tokens[*pos] != ")" { +// let expr = parse_sexpr(tokens, pos)?; +// list_items.push(expr); +// } + +// if *pos >= tokens.len() { +// return Err("Missing closing parenthesis".into()); +// } +// // consume ")" +// *pos += 1; +// Ok(SExpr::List(list_items)) +// } +// ")" => { +// // Should never parse_sexpr starting with ')' +// Err("Unexpected ')'".into()) +// } +// _ => { +// // Atom +// let atom_str = token.clone(); +// *pos += 1; +// Ok(SExpr::Atom(atom_str)) +// } +// } +// } + +// /// Parse an entire string into a single top-level `SExpr`. +// fn parse_string_to_sexpr(s: &str) -> Result { +// let tokens = tokenize(s); +// let mut pos = 0; +// let expr = parse_sexpr(&tokens, &mut pos)?; + +// // If there's leftover tokens, optionally check +// if pos < tokens.len() { +// return Err(format!("Extra tokens after parse: {:?}", &tokens[pos..])); +// } + +// Ok(expr) +// } + +// fn sexpr_to_untyped(expr: &SExpr) -> Result { +// match expr { +// SExpr::Atom(text) => { +// // 1) try to parse as i32 +// if let Ok(val) = text.parse::() { +// Ok(UntypedAst::IntLiteral(val)) +// } else { +// // 2) otherwise parse as OpCode symbol +// match text.to_uppercase().as_str() { +// "+" => Ok(UntypedAst::Instruction(OpCode::Plus)), +// "-" => Ok(UntypedAst::Instruction(OpCode::Minus)), +// "*" => Ok(UntypedAst::Instruction(OpCode::Mult)), +// "DUP" => Ok(UntypedAst::Instruction(OpCode::Dup)), +// "POP" => Ok(UntypedAst::Instruction(OpCode::Pop)), +// // more opcodes ... +// _ => Ok(UntypedAst::Instruction(OpCode::Noop)) +// } +// } +// } +// SExpr::List(list) => { +// // parse each child into UntypedAst +// let mut result = Vec::new(); +// for child in list { +// result.push(sexpr_to_untyped(child)?); +// } +// Ok(UntypedAst::Sublist(result)) +// } +// } +// } + +// src/compiler/ast.rs + pub trait Push3Ast { /// Convert this AST into a bytecode array (Push3 tokens). fn to_bytecode(&self) -> Vec; - - /// Parse an AST from bytecode (the "decompiler"), if possible. - /// Possibly returns a Result in case of partial/invalid parse. - fn from_bytecode(data: &[u8]) -> Self - where - Self: Sized; - - /// Randomly mutate this AST in-place (GP mutation). - fn mutate(&mut self, rng: &mut impl rand::Rng); - - /// Possibly a "crossover" method, or we do it externally. - // fn crossover(&self, other: &Self, rng: &mut impl rand::Rng) -> Self; - - /// Evaluate the AST with some input(s). - /// Optionally do we want this or do we always run in EVM? - /// We can stub it or do an interpret approach for local test. - fn interpret_locally(&self, inputs: &[i32]) -> Vec; } +/* -------------------------------------------- + 1) TypedAst stubs (optional) +-------------------------------------------- */ #[derive(Debug, Clone)] pub enum TypedAst { @@ -32,50 +347,28 @@ pub enum InstructionKind { Plus(Box, Box), Minus(Box, Box), Mult(Box, Box), - Dup, // 0 children - Pop, // 0 children + Dup, + Pop, } +// Example stub; not fully implemented impl Push3Ast for TypedAst { fn to_bytecode(&self) -> Vec { - // do typed encoding: - // - for Plus(e1, e2): e1 -> bytecode, e2 -> bytecode, then PLUS opcode - unimplemented!() - } - - fn from_bytecode(data: &[u8]) -> Self { - // parse in a strictly typed manner; might fail or panic - // if the code doesn't line up properly - unimplemented!() - } - - fn mutate(&mut self, rng: &mut impl rand::Rng) { - // e.g. randomly pick a node, replace it with something - // that respects the typed structure - unimplemented!() - } - - fn interpret_locally(&self, inputs: &[i32]) -> Vec { - // do a normal expression evaluation. If a node is "Plus(a,b)", - // interpret (a) + interpret(b). - unimplemented!() + unimplemented!("TypedAst::to_bytecode not yet implemented"); } } +/* -------------------------------------------- + 2) UntypedAst + OpCode +-------------------------------------------- */ + #[derive(Debug, Clone)] pub enum UntypedAst { - /// A single token in a list-based approach, e.g. "Integer literal" IntLiteral(i32), - - /// "Instruction" might be a simple variant with no children, - /// because the stack-based evaluation decides how many arguments it consumes. - Instruction(OpCode), - - /// A sublist of tokens, e.g. "( 2 3 DUP + )" + Instruction(OpCode), Sublist(Vec), } -/// Possibly an enum for OpCode: #[derive(Debug, Clone)] pub enum OpCode { Noop, @@ -84,31 +377,154 @@ pub enum OpCode { Mult, Dup, Pop, - // maybe Unknown => treat as no-op } +/// Implementation of `Push3Ast` for `UntypedAst`. +/// Matches the Solidity-based Push3Interpreter token IDs. impl Push3Ast for UntypedAst { fn to_bytecode(&self) -> Vec { - // flatten out sublists vs instructions - unimplemented!() - } - - fn from_bytecode(data: &[u8]) -> Self { - // parse "0x02 => INT_LITERAL => read next 4 bytes" - // instructions might have no subchildren - unimplemented!() - } - - fn mutate(&mut self, rng: &mut impl rand::Rng) { - // can randomly insert unknown tokens, reorder sublists, etc. - // possibly produce "invalid ops => noops" - unimplemented!() - } - - fn interpret_locally(&self, inputs: &[i32]) -> Vec { - // push-based interpretation: - // sublist => interpret each item in sequence - // if an instruction sees insufficient args => no-op - unimplemented!() + match self { + UntypedAst::IntLiteral(val) => { + // 0x02 => INT_LITERAL => next 4 bytes (little-endian i32) + let mut bytes = Vec::with_capacity(1 + 4); + bytes.push(0x02); + bytes.extend_from_slice(&val.to_be_bytes()); + bytes + } + UntypedAst::Instruction(op) => { + let opcode_byte = match op { + OpCode::Noop => 0x00, + OpCode::Plus => 0x01, + OpCode::Minus => 0x04, + OpCode::Mult => 0x05, + OpCode::Dup => 0x06, + OpCode::Pop => 0x07, + }; + vec![opcode_byte] + } + UntypedAst::Sublist(children) => { + // 0x03 => SUBLIST => next 2 bytes = big-endian length, then sub-payload + let mut payload = Vec::new(); + for child in children { + payload.extend(child.to_bytecode()); + } + let sub_len = payload.len() as u16; + let mut bytes = Vec::with_capacity(1 + 2 + payload.len()); + bytes.push(0x03); + bytes.extend_from_slice(&sub_len.to_be_bytes()); // big-endian + bytes.extend_from_slice(&payload); + bytes + } + } + } +} + +/* -------------------------------------------- + 3) S-expression parsing helpers +-------------------------------------------- */ +#[derive(Debug, Clone, PartialEq)] +pub enum SExpr { + Atom(String), + List(Vec), +} + +pub fn tokenize(s: &str) -> Vec { + let mut tokens = Vec::new(); + let mut current = String::new(); + + for c in s.chars() { + match c { + '(' | ')' => { + if !current.trim().is_empty() { + tokens.push(current.trim().to_string()); + } + current.clear(); + tokens.push(c.to_string()); + } + ' ' | '\t' | '\n' | '\r' => { + if !current.trim().is_empty() { + tokens.push(current.trim().to_string()); + current.clear(); + } + } + _ => { + current.push(c); + } + } + } + + if !current.trim().is_empty() { + tokens.push(current.trim().to_string()); + } + + tokens +} + +fn parse_sexpr_internal(tokens: &[String], pos: &mut usize) -> Result { + if *pos >= tokens.len() { + return Err("Unexpected end of tokens".into()); + } + + let token = &tokens[*pos]; + match token.as_str() { + "(" => { + *pos += 1; // consume '(' + let mut items = Vec::new(); + while *pos < tokens.len() && tokens[*pos] != ")" { + let expr = parse_sexpr_internal(tokens, pos)?; + items.push(expr); + } + if *pos >= tokens.len() { + return Err("Missing closing parenthesis".into()); + } + *pos += 1; // consume ')' + Ok(SExpr::List(items)) + } + ")" => { + Err("Unexpected ')'".into()) + } + _ => { + let atom = token.clone(); + *pos += 1; + Ok(SExpr::Atom(atom)) + } + } +} + +/// Parse an entire string into a single top-level `SExpr`. +pub fn parse_string_to_sexpr(s: &str) -> Result { + let tokens = tokenize(s); + let mut pos = 0; + let expr = parse_sexpr_internal(&tokens, &mut pos)?; + if pos < tokens.len() { + return Err(format!("Extra tokens after parse: {:?}", &tokens[pos..])); + } + Ok(expr) +} + +/// Convert an SExpr => UntypedAst +pub fn sexpr_to_untyped(expr: &SExpr) -> Result { + match expr { + SExpr::Atom(text) => { + if let Ok(val) = text.parse::() { + Ok(UntypedAst::IntLiteral(val)) + } else { + match text.to_uppercase().as_str() { + "+" => Ok(UntypedAst::Instruction(OpCode::Plus)), + "-" => Ok(UntypedAst::Instruction(OpCode::Minus)), + "*" => Ok(UntypedAst::Instruction(OpCode::Mult)), + "DUP" => Ok(UntypedAst::Instruction(OpCode::Dup)), + "POP" => Ok(UntypedAst::Instruction(OpCode::Pop)), + _ => Ok(UntypedAst::Instruction(OpCode::Noop)), + } + } + } + SExpr::List(items) => { + let mut sub_asts = Vec::new(); + for child in items { + sub_asts.push(sexpr_to_untyped(child)?); + } + Ok(UntypedAst::Sublist(sub_asts)) + } } } diff --git a/offchain/src/evm_integration/revm_runner.rs b/offchain/src/evm_integration/revm_runner.rs index bf5e021..e69de29 100644 --- a/offchain/src/evm_integration/revm_runner.rs +++ b/offchain/src/evm_integration/revm_runner.rs @@ -1,5 +0,0 @@ -pub fn run_in_revm(bytecode: &[u8]) -> Result, String> { - // set up revm, load the code, call push3 - // for now just stub - Ok(vec![]) -} diff --git a/offchain/src/main.rs b/offchain/src/main.rs index 77c0435..5a473d0 100644 --- a/offchain/src/main.rs +++ b/offchain/src/main.rs @@ -1,9 +1,176 @@ mod compiler; -mod gp; -mod evm_integration; -fn main() { - println!("Welcome to My GP System CLI"); - // e.g., parse arguments, run a small demonstration? - // For now just a stub. +use std::env; +use compiler::ast::{ + parse_string_to_sexpr, + sexpr_to_untyped, + Push3Ast, // The trait + UntypedAst, // The untyped AST enum +}; + +use anyhow::{anyhow, bail, Result}; +use hex; +use database::CacheDB; +use revm::{ + context::Context, + context_interface::result::{ExecutionResult, Output}, + database_interface::EmptyDB, + handler::EthHandler, + primitives::{Bytes, TxKind}, + EvmCommit, MainEvm, +}; +use ethers::abi::{encode, Token}; +use ethers::abi::{ParamType, decode}; +use ethers::types::U256; // Use ethers' U256 instead + + + +fn main() -> Result<()> { + + // 1) Read CLI arguments + let args: Vec = std::env::args().collect(); + if args.len() < 2 { + eprintln!("Usage: cargo run -- ''"); + eprintln!("Example: cargo run -- '((3 5 +) DUP MUL)'"); + // If you want to indicate a failure exit code: + std::process::exit(1); + } + let program_str = &args[1]; + + // 2) Parse the string into an S-expression + let sexpr = parse_string_to_sexpr(program_str) + .map_err(|e| anyhow::anyhow!("Error parsing S-expression: {}", e))?; + + // 3) Convert SExpr => UntypedAst + let ast: UntypedAst = sexpr_to_untyped(&sexpr) + .map_err(|e| anyhow::anyhow!("Error converting to UntypedAst: {}", e))?; + + // 4) Convert UntypedAst => Push3 bytecode + let bytecode = ast.to_bytecode(); + + // 5) Print the resulting AST and bytecode (in hex) + println!("AST: {:?}", ast); + println!("Bytecode (hex): 0x{}", hex::encode(&bytecode)); + + // 1) Suppose you have compiled your contract with Forge. + // Grab the "bytecode" field from e.g. `out/MyContract.sol/MyContract.json`. + // We'll store it here as a string. This is your entire "creation code." + // (Example placeholder below.) + let creation_hex = "6080806040523461001657610cd8908161001b8239f35b5f80fdfe6080604052600480361015610012575f80fd5b5f803560e01c918263093b62c0146100395750506336d9ea8514610034575f80fd5b6101ce565b346101045760803660031901126101045780359167ffffffffffffffff918284116101045736602385011215610104578381013590838211610100573660248387010111610100576024358481116100fc576100989036908301610108565b9290916044358681116100f8576100b29036908301610108565b9690956064359182116100f5576100f16100e260248b8b8b8b8b8b6100d9368c8e01610108565b97909601610480565b60409391935193849384610170565b0390f35b80fd5b8580fd5b8380fd5b8280fd5b5080fd5b9181601f840112156101395782359167ffffffffffffffff8311610139576020808501948460051b01011161013957565b5f80fd5b9081518082526020808093019301915f5b82811061015c575050505090565b83518552938101939281019260010161014e565b906101866101959160608452606084019061013d565b6020938382038585015261013d565b9060408183039101528180845192838152019301915f5b8281106101ba575050505090565b8351855293810193928101926001016101ac565b346101395760803660031901126101395760043560048110156101395763ffffffff60243581811681036101395760443591821682036101395760643590600160b81b82101561024c576020936040519363ffffffff60b81b9060b81b169163ffffffff60d81b9060d81b169060ff60f81b9060f81b161717178152f35b60405162461bcd60e51b81526020600482015260136024820152726c6f77313834206f7574206f662072616e676560681b6044820152606490fd5b634e487b7160e01b5f52602160045260245ffd5b600411156102a557565b610287565b600160b81b81101561024c57600160f91b1790565b634e487b7160e01b5f52601160045260245ffd5b9061010082018092116102e257565b6102bf565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff81116103135760051b60200190565b6102e7565b90610322826102fb565b60405190601f1990601f018116820167ffffffffffffffff8111838210176103135760405283825261035482946102fb565b0190602036910137565b5f1981146102e25760010190565b634e487b7160e01b5f52603260045260245ffd5b91908110156103905760051b0190565b61036c565b80518210156103905760209160051b010190565b5f198101919082116102e257565b6001198101919082116102e257565b919082039182116102e257565b80156102e2575f190190565b90600263ffffffff809316019182116102e257565b90600463ffffffff809316019182116102e257565b91909163ffffffff808094169116019182116102e257565b600611156102a557565b81810292915f8212600160ff1b8214166102e25781840514901517156102e257565b81810392915f1380158285131691841216176102e257565b9190915f83820193841291129080158216911516176102e257565b9794929197969396610499610494846102d3565b610318565b985f5b8481106108ac5750506104b1610494856102d3565b97845f5b81811061088c57505050836104cc610494876102d3565b97865f5b818110610866575050505b6105855750506104ea81610318565b965f5b8281106105675750505061050081610318565b945f5b8281106105495750505061051681610318565b925f5b82811061052557505050565b806105336105449284610395565b5161053e8288610395565b5261035e565b610519565b806105576105629284610395565b5161053e828a610395565b610503565b806105756105809284610395565b5161053e828c610395565b6104ed565b6105a161059a610594866103a9565b8a610395565b51946103d3565b93846105af8260f81c6108c5565b916105b98361029b565b600192808403610777575060ff6105d091166108d4565b916105da83610421565b826105e8575b5090506104db565b6105f183610421565b82810361065c57505050600285101561060e575b835b805f6105e0565b6106558561064b61062861062288996103a9565b8b610395565b5161064561063e610638856103b7565b8d610395565b51936103b7565b92610465565b61053e828b610395565b9450610605565b61066583610421565b6002928084036106b157505050851015610680575b83610607565b6106aa8561064b61069461062288996103a9565b516106a461063e610638856103b7565b9261044d565b945061067a565b6106ba81610421565b600381036106fc575050508510156106d25783610607565b6106aa8561064b6106e661062288996103a9565b516106f661063e610638856103b7565b9261042b565b9091925061070981610421565b6004810361073d575090508510156107215783610607565b6106aa8561073261059487986103a9565b5161053e828b610395565b80610749600592610421565b14610755575b50610607565b9050851015610766575b835f61074f565b61077084956103a9565b945061075f565b909291506107848161029b565b600281036107ad575050849563ffffffff6107a7921660030b61053e828b610395565b946104db565b916003836107bb899561029b565b0361085f5763ffffffff908582808360d81c169260b81c16926107de8484610409565b1611156107ee575b5050506104db565b829350906107fd918686610904565b5f925b61080c575b86926107e6565b9091958a825180891015610857578261084f9261053e879561084261083c8e610837610849986103a9565b6103c6565b89610395565b5192610395565b9761035e565b929190610800565b505095610805565b50506104db565b82935061087881836108839495610380565b3561053e828d610395565b908692916104d0565b808b61053e826108a06108a7958789610380565b3592610395565b6104b5565b808b61053e826108a06108c0958a88610380565b61049c565b60ff1660048110156102a55790565b60ff1660068110156102a55790565b90821015610390570190565b63ffffffff8091169081146102e25760010190565b919063ffffffff92610917848616610318565b95846109245f9786610409565b16955b85851687811015610bbd5784811015610bbd5761096a61096461095e61095060ff9489896108e3565b356001600160f81b03191690565b60f81c90565b966108ef565b95168061098d575061098590600160f81b61053e828b610395565b955b95610927565b600181036109b257506109ac906001600160f81b0161053e828b610395565b95610987565b60028103610a495750866109d16109c8876103f4565b63ffffffff1690565b111580610a34575b15610a01576109ac9061064b876109fa6109f4898989610bca565b986103f4565b97166102aa565b945094505050505b610a1281610318565b925f5b828110610a2157505050565b80610533610a2f9284610395565b610a15565b5083610a426109c8876103f4565b11156109d9565b9096949060038103610b2c575084610a636109c8836103df565b111580610b17575b15610b0b57610a84610a7e828686610c36565b916103df565b9661ffff82169186610a996109c8858c610409565b111580610af5575b15610ae757610ae19291610adb9160d88b901b63ffffffff60d81b1660b89190911b61ffff60b81b1617600360f81b1761053e828d610395565b97610409565b93610987565b509550509450505050610a09565b5085610b046109c8858c610409565b1115610aa1565b50949350505050610a09565b5083610b256109c8836103df565b1115610a6b565b9496909460048103610b4f57506109ac906002600160f81b0161053e828b610395565b60058103610b6e57506109ac906003600160f81b0161053e828b610395565b60068103610b8d57506109ac906004600160f81b0161053e828b610395565b600703610baa576109ac906005600160f81b0161053e828b610395565b6109ac90600160f81b61053e828b610395565b5094509450505050610a09565b919063ffffffff610bda836103f4565b1611610bf157600490604051920182375160e01c90565b60405162461bcd60e51b815260206004820152601760248201527f7265616455696e743332206f7574206f662072616e67650000000000000000006044820152606490fd5b919063ffffffff610c46836103df565b1611610c5d57600290604051920182375160f01c90565b60405162461bcd60e51b815260206004820152601760248201527f7265616455696e743136206f7574206f662072616e67650000000000000000006044820152606490fdfea26469706673582212208a8e0c1517585160ff23b605caf6916a05dae2b541b9387b0dfab23ea71f563964736f6c63430008140033"; + // ^^^^^ Replace with your actual creation code from forge. + + // 2) Convert hex string to raw bytes. + let creation_bytes = match hex::decode(creation_hex) { + Ok(bytes) => bytes, + Err(e) => bail!("Invalid hex for creation code: {e}"), + }; + + // 3) Build a new EVM instance with a "Create" transaction: + let mut evm = MainEvm::new( + // a) Prepare context with a chained transaction + Context::builder() + .modify_tx_chained(|tx| { + tx.transact_to = TxKind::Create; + tx.data = Bytes::from(creation_bytes.clone()); + // If you want to attach a value, e.g. tx.value = + }) + // b) Provide an in-memory DB for ephemeral state + .with_db(CacheDB::::default()), + // c) The "EthHandler" for block/tx environment logic + EthHandler::default(), + ); + + println!("Deploying contract with creation code size: {} bytes", creation_bytes.len()); + + // 4) Execute the CREATE transaction + let creation_result = evm.exec_commit()?; + // => an ExecutionResult + + // 5) Check success + let ExecutionResult::Success { + output: Output::Create(_, Some(deployed_addr)), + .. + } = creation_result + else { + bail!("Deployment failed or didn't return an address: {creation_result:#?}"); + }; + + println!("Deployed contract at: 0x{:x}", deployed_addr); + + // 1) Prepare the function selector for runInterpreter + let func_selector = ðers::utils::id("runInterpreter(bytes,uint256[],uint256[],int256[])")[0..4]; + + // 2) Convert your compiled “Push3” bytecode into the `bytes` argument + let code_arg = Token::Bytes(bytecode.clone()); + + // 3) Build a “SUBLIST descriptor” for the entire bytecode. + // In Solidity, SUBLIST = CodeTag.SUBLIST = 3. The layout is: + // [255..248]=tag, [247..216]=offset, [215..184]=length, [183..0]=low184 + let tag_bits = U256::from(3u64) << 248; // CodeTag.SUBLIST = 3 + let offset_bits = U256::from(0u64) << 216; // offset=0 + let length_bits = U256::from(bytecode.len() as u64) << 184; // length = bytecode.len() + let low_184 = U256::zero(); + + let sublist_descriptor = tag_bits | offset_bits | length_bits | low_184; + + // Now we put *that* descriptor as the one and only item in `initExecStack`. + let init_exec_stack = Token::Array(vec![ + Token::Uint(sublist_descriptor) + ]); + + // For the other two arrays (codeStack, intStack), we’ll just leave them empty: + let empty_uint256_array = Token::Array(vec![]); // codeStack + let empty_int256_array = Token::Array(vec![]); // intStack + + // 4) Encode all arguments in the correct order: + // (bytes code, uint256[] initCodeStack, uint256[] initExecStack, int256[] initIntStack) + let encoded_args = encode(&[ + code_arg, + empty_uint256_array.clone(), // initCodeStack + init_exec_stack, // initExecStack + empty_uint256_array.clone(), // initIntStack (or empty_int256_array if needed) + ]); + + // 5) Concatenate selector + encoded arguments to form the full call data + let mut call_data = Vec::from(func_selector); + call_data.extend_from_slice(&encoded_args); + + // 6) Modify the transaction to call `runInterpreter` with the encoded data + evm.context.modify_tx(|tx| { + tx.transact_to = TxKind::Call(deployed_addr); + tx.data = Bytes::from(call_data); + tx.nonce += 1; // increment nonce to avoid reuse + }); + + // 7) Execute the call. + let call_result = evm.transact()?; + match &call_result.result { + ExecutionResult::Success { + output: Output::Call(return_data), + .. + } => { + println!("Call succeeded, returned data: 0x{}", hex::encode(return_data)); + + // Decode (uint256[], uint256[], int256[]) + use ethers::abi::{decode, ParamType}; + + let param_types = &[ + ParamType::Array(Box::new(ParamType::Uint(256))), // finalCodeStack + ParamType::Array(Box::new(ParamType::Uint(256))), // finalExecStack + ParamType::Array(Box::new(ParamType::Int(256))), // finalIntStack + ]; + + let decoded = decode(param_types, return_data) + .map_err(|e| anyhow!("Failed to decode return data: {e}"))?; + + println!("Decoded return: {:?}", decoded); + } + ExecutionResult::Revert { gas_used, output } => { + bail!("Call reverted: gas used = {gas_used:?}, output = {:?}", output); + } + other => { + bail!("Call failed: {other:?}"); + } + } + Ok(()) } diff --git a/onchain/test/Push3Interpreter.t.sol b/onchain/test/Push3Interpreter.t.sol index 8ef693f..c18526b 100644 --- a/onchain/test/Push3Interpreter.t.sol +++ b/onchain/test/Push3Interpreter.t.sol @@ -43,7 +43,7 @@ contract Push3InterpreterTest is Test { // [9..12] = 0x00000020 => 32 // [13] = 0x01 => plus - bytes memory code = hex"03000B020000000A020000002001"; + bytes memory code = hex"03000B020000000A020000002001"; // Or fully concatenated: // 0x03 00 0B 02 00 00 00 0A 02 00 00 00 20 01 -- 2.34.1 From e17155ecdb3474e958297acc29f8516861064e67 Mon Sep 17 00:00:00 2001 From: zjkree Date: Mon, 13 Jan 2025 09:10:57 +0100 Subject: [PATCH 04/10] Read bytecode from JSON. Clean up ast. --- offchain/src/compiler/ast.rs | 498 ++++++++--------------------------- offchain/src/main.rs | 88 ++++--- 2 files changed, 162 insertions(+), 424 deletions(-) diff --git a/offchain/src/compiler/ast.rs b/offchain/src/compiler/ast.rs index a8929d7..a8ca27b 100644 --- a/offchain/src/compiler/ast.rs +++ b/offchain/src/compiler/ast.rs @@ -1,375 +1,39 @@ -// pub trait Push3Ast { -// /// Convert this AST into a bytecode array (Push3 tokens). -// fn to_bytecode(&self) -> Vec; +//! # ast.rs +//! This module defines the **Abstract Syntax Trees (ASTs)** for our Push3-like language. +//! +//! Currently, we provide only an **untyped AST** (`UntypedAst`), which allows any sequence +//! of instructions, sublists, or integer literals. This is easy to parse and mutate, but +//! **does not** enforce correctness of operand types (for example, `INTEGER_PLUS` might +//! appear even if there's only one integer on the stack). +//! +//! ## Future: Typed AST +//! We **plan** to add a **typed AST** implementation, where each node ensures the correct +//! number and type of arguments at compile-time. This would prevent invalid programs from +//! being constructed in the first place. However, that is not implemented here yet—it’s +//! an **eventual goal** for more advanced genetic programming or verification workflows. -// // Parse an AST from bytecode (the "decompiler"), if possible. -// // Possibly returns a Result in case of partial/invalid parse. -// // fn from_bytecode(data: &[u8]) -> Self -// // where -// // Self: Sized; - -// // Randomly mutate this AST in-place (GP mutation). -// // fn mutate(&mut self, rng: &mut impl rand::Rng); - -// // Possibly a "crossover" method, or we do it externally. -// // fn crossover(&self, other: &Self, rng: &mut impl rand::Rng) -> Self; - -// // Evaluate the AST with some input(s). -// // Optionally do we want this or do we always run in EVM? -// // We can stub it or do an interpret approach for local test. -// // fn interpret_locally(&self, inputs: &[i32]) -> Vec; -// } - - -// #[derive(Debug, Clone)] -// pub enum TypedAst { -// IntLiteral(i32), -// Instruction(InstructionKind), -// } - -// #[derive(Debug, Clone)] -// pub enum InstructionKind { -// Plus(Box, Box), -// Minus(Box, Box), -// Mult(Box, Box), -// Dup, // 0 children -// Pop, // 0 children -// } - -// impl Push3Ast for TypedAst { -// fn to_bytecode(&self) -> Vec { -// // do typed encoding: -// // - for Plus(e1, e2): e1 -> bytecode, e2 -> bytecode, then PLUS opcode -// unimplemented!() -// } - -// // fn from_bytecode(data: &[u8]) -> Self { -// // // parse in a strictly typed manner; might fail or panic -// // // if the code doesn't line up properly -// // unimplemented!() -// // } - -// // fn mutate(&mut self, rng: &mut impl rand::Rng) { -// // // e.g. randomly pick a node, replace it with something -// // // that respects the typed structure -// // unimplemented!() -// // } - -// // fn interpret_locally(&self, inputs: &[i32]) -> Vec { -// // // do a normal expression evaluation. If a node is "Plus(a,b)", -// // // interpret (a) + interpret(b). -// // unimplemented!() -// // } -// } - -// #[derive(Debug, Clone)] -// pub enum UntypedAst { -// /// A single token in a list-based approach, e.g. "Integer literal" -// IntLiteral(i32), - -// /// "Instruction" might be a simple variant with no children, -// /// because the stack-based evaluation decides how many arguments it consumes. -// Instruction(OpCode), - -// /// A sublist of tokens, e.g. "( 2 3 DUP + )" -// Sublist(Vec), -// } - -// /// Possibly an enum for OpCode: -// #[derive(Debug, Clone)] -// pub enum OpCode { -// Noop, -// Plus, -// Minus, -// Mult, -// Dup, -// Pop, -// // maybe Unknown => treat as no-op -// } - -// // impl Push3Ast for UntypedAst { -// // fn to_bytecode(&self) -> Vec { -// // // flatten out sublists vs instructions -// // unimplemented!() -// // } - -// // // fn from_bytecode(data: &[u8]) -> Self { -// // // // parse "0x02 => INT_LITERAL => read next 4 bytes" -// // // // instructions might have no subchildren -// // // unimplemented!() -// // // } - -// // // fn mutate(&mut self, rng: &mut impl rand::Rng) { -// // // // can randomly insert unknown tokens, reorder sublists, etc. -// // // // possibly produce "invalid ops => noops" -// // // unimplemented!() -// // // } - -// // // fn interpret_locally(&self, inputs: &[i32]) -> Vec { -// // // // push-based interpretation: -// // // // sublist => interpret each item in sequence -// // // // if an instruction sees insufficient args => no-op -// // // unimplemented!() -// // // } -// // } - -// use crate::compiler::ast::Push3Ast; - -// /// An untyped AST node, matching your Push3 structure. -// #[derive(Debug, Clone)] -// pub enum UntypedAst { -// /// A single integer literal. -// IntLiteral(i32), -// /// A single push instruction (no subchildren). -// Instruction(OpCode), -// /// A sublist of items, each of which is another UntypedAst. -// Sublist(Vec), -// } - -// /// Your Push3 opcodes in an untyped form. -// #[derive(Debug, Clone)] -// pub enum OpCode { -// Noop, -// Plus, -// Minus, -// Mult, -// Dup, -// Pop, -// } - -// /// Implementation of `Push3Ast` for `UntypedAst`. -// /// -// /// This will produce **bytecode** compatible with your Solidity `Push3Interpreter`: -// /// -// /// - `0x00` => NOOP -// /// - `0x01` => INTEGER_PLUS -// /// - `0x02` => INT_LITERAL => next 4 bytes (little-endian i32) -// /// - `0x03` => SUBLIST => next 2 bytes (big-endian `u16` length), then the sublist contents -// /// - `0x04` => INTEGER_MINUS -// /// - `0x05` => INTEGER_MULT -// /// - `0x06` => INTEGER_DUP -// /// - `0x07` => INTEGER_POP -// /// -// /// In the Solidity parser, `SUBLIST (0x03)` consumes two bytes to determine -// /// how many bytes of tokens to read in that sublist. -// impl Push3Ast for UntypedAst { -// /// Convert this untyped AST into a flattened push3 bytecode sequence. -// fn to_bytecode(&self) -> Vec { -// match self { -// UntypedAst::IntLiteral(val) => { -// // 0x02 followed by 4 bytes of i32 (little-endian) -// let mut bytes = Vec::with_capacity(1 + 4); -// bytes.push(0x02); -// bytes.extend_from_slice(&val.to_le_bytes()); -// bytes -// } -// UntypedAst::Instruction(op) => { -// // Single opcode byte -// let opcode_byte = match op { -// OpCode::Noop => 0x00, -// OpCode::Plus => 0x01, -// OpCode::Minus => 0x04, -// OpCode::Mult => 0x05, -// OpCode::Dup => 0x06, -// OpCode::Pop => 0x07, -// }; -// vec![opcode_byte] -// } -// UntypedAst::Sublist(children) => { -// // 0x03 => SUBLIST -// // Then 2 bytes for length (big-endian u16), -// // Then the concatenated bytecode for all children. -// let mut payload = Vec::new(); -// for child in children { -// let child_bytes = child.to_bytecode(); -// payload.extend_from_slice(&child_bytes); -// } -// let sub_len = payload.len() as u16; // assume it fits in 65535 -// let mut bytes = Vec::with_capacity(1 + 2 + payload.len()); -// bytes.push(0x03); -// // Store the sublist length as big-endian, because readUint16 in solidity -// // does `val = uint16(word >> 240)` (effectively big-endian). -// bytes.extend_from_slice(&sub_len.to_be_bytes()); -// // Then the actual sublist payload -// bytes.extend_from_slice(&payload); -// bytes -// } -// } -// } -// } - - -// #[derive(Debug, Clone, PartialEq)] -// pub enum SExpr { -// Atom(String), // e.g. "3", "DUP", "+" -// List(Vec), // e.g. (3 5 +) -// } - -// fn tokenize(s: &str) -> Vec { -// let mut tokens = Vec::new(); -// let mut current = String::new(); - -// for c in s.chars() { -// match c { -// '(' | ')' => { -// // If we were building up an atom, push it first -// if !current.trim().is_empty() { -// tokens.push(current.trim().to_string()); -// } -// current.clear(); -// // Then push the single-char token -// tokens.push(c.to_string()); -// } -// ' ' | '\t' | '\n' | '\r' => { -// // Whitespace => if we have an atom, finish it -// if !current.trim().is_empty() { -// tokens.push(current.trim().to_string()); -// current.clear(); -// } -// } -// _ => { -// // Part of an atom -// current.push(c); -// } -// } -// } - -// // If something is left in 'current' at the end -// if !current.trim().is_empty() { -// tokens.push(current.trim().to_string()); -// } - -// tokens -// } - - -// fn parse_sexpr(tokens: &[String], pos: &mut usize) -> Result { -// // If we’re out of tokens, error -// if *pos >= tokens.len() { -// return Err("Unexpected end of tokens".into()); -// } - -// let token = &tokens[*pos]; -// match token.as_str() { -// "(" => { -// // Parse a list -// *pos += 1; // consume '(' -// let mut list_items = Vec::new(); - -// while *pos < tokens.len() && tokens[*pos] != ")" { -// let expr = parse_sexpr(tokens, pos)?; -// list_items.push(expr); -// } - -// if *pos >= tokens.len() { -// return Err("Missing closing parenthesis".into()); -// } -// // consume ")" -// *pos += 1; -// Ok(SExpr::List(list_items)) -// } -// ")" => { -// // Should never parse_sexpr starting with ')' -// Err("Unexpected ')'".into()) -// } -// _ => { -// // Atom -// let atom_str = token.clone(); -// *pos += 1; -// Ok(SExpr::Atom(atom_str)) -// } -// } -// } - -// /// Parse an entire string into a single top-level `SExpr`. -// fn parse_string_to_sexpr(s: &str) -> Result { -// let tokens = tokenize(s); -// let mut pos = 0; -// let expr = parse_sexpr(&tokens, &mut pos)?; - -// // If there's leftover tokens, optionally check -// if pos < tokens.len() { -// return Err(format!("Extra tokens after parse: {:?}", &tokens[pos..])); -// } - -// Ok(expr) -// } - -// fn sexpr_to_untyped(expr: &SExpr) -> Result { -// match expr { -// SExpr::Atom(text) => { -// // 1) try to parse as i32 -// if let Ok(val) = text.parse::() { -// Ok(UntypedAst::IntLiteral(val)) -// } else { -// // 2) otherwise parse as OpCode symbol -// match text.to_uppercase().as_str() { -// "+" => Ok(UntypedAst::Instruction(OpCode::Plus)), -// "-" => Ok(UntypedAst::Instruction(OpCode::Minus)), -// "*" => Ok(UntypedAst::Instruction(OpCode::Mult)), -// "DUP" => Ok(UntypedAst::Instruction(OpCode::Dup)), -// "POP" => Ok(UntypedAst::Instruction(OpCode::Pop)), -// // more opcodes ... -// _ => Ok(UntypedAst::Instruction(OpCode::Noop)) -// } -// } -// } -// SExpr::List(list) => { -// // parse each child into UntypedAst -// let mut result = Vec::new(); -// for child in list { -// result.push(sexpr_to_untyped(child)?); -// } -// Ok(UntypedAst::Sublist(result)) -// } -// } -// } - -// src/compiler/ast.rs +use serde::{Deserialize, Serialize}; +// use std::fmt; +/// A trait describing the core operation: converting an AST to Push3 bytecode. +/// +/// We might later add more methods here (like parsing from bytecode or mutation). pub trait Push3Ast { - /// Convert this AST into a bytecode array (Push3 tokens). fn to_bytecode(&self) -> Vec; } -/* -------------------------------------------- - 1) TypedAst stubs (optional) --------------------------------------------- */ - -#[derive(Debug, Clone)] -pub enum TypedAst { - IntLiteral(i32), - Instruction(InstructionKind), -} - -#[derive(Debug, Clone)] -pub enum InstructionKind { - Plus(Box, Box), - Minus(Box, Box), - Mult(Box, Box), - Dup, - Pop, -} - -// Example stub; not fully implemented -impl Push3Ast for TypedAst { - fn to_bytecode(&self) -> Vec { - unimplemented!("TypedAst::to_bytecode not yet implemented"); - } -} - -/* -------------------------------------------- - 2) UntypedAst + OpCode --------------------------------------------- */ - -#[derive(Debug, Clone)] +/// The untyped AST: each node is either an integer literal, a single instruction (no children), +/// or a sublist (which recursively contains more AST nodes). +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum UntypedAst { IntLiteral(i32), Instruction(OpCode), Sublist(Vec), } -#[derive(Debug, Clone)] +/// The set of push3 instructions recognized in our untyped AST. +/// Each corresponds to a single token byte in `to_bytecode`. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum OpCode { Noop, Plus, @@ -379,39 +43,54 @@ pub enum OpCode { Pop, } -/// Implementation of `Push3Ast` for `UntypedAst`. -/// Matches the Solidity-based Push3Interpreter token IDs. +/// Implementation of `Push3Ast` for the **untyped** AST. +/// +/// This produces bytecode recognized by the Push3Interpreter contract: +/// +/// - `0x00` => NOOP +/// - `0x01` => INTEGER_PLUS +/// - `0x02` => INT_LITERAL => next 4 bytes (little-endian i32) +/// - `0x03` => SUBLIST => next 2 bytes (big-endian `u16` length), then the sublist contents +/// - `0x04` => INTEGER_MINUS +/// - `0x05` => INTEGER_MULT +/// - `0x06` => INTEGER_DUP +/// - `0x07` => INTEGER_POP impl Push3Ast for UntypedAst { fn to_bytecode(&self) -> Vec { match self { UntypedAst::IntLiteral(val) => { - // 0x02 => INT_LITERAL => next 4 bytes (little-endian i32) + // 0x02 => INT_LITERAL => then 4 bytes little-endian let mut bytes = Vec::with_capacity(1 + 4); bytes.push(0x02); bytes.extend_from_slice(&val.to_be_bytes()); bytes } UntypedAst::Instruction(op) => { - let opcode_byte = match op { - OpCode::Noop => 0x00, - OpCode::Plus => 0x01, + // Single byte representing the opcode + let byte = match op { + OpCode::Noop => 0x00, + OpCode::Plus => 0x01, OpCode::Minus => 0x04, - OpCode::Mult => 0x05, - OpCode::Dup => 0x06, - OpCode::Pop => 0x07, + OpCode::Mult => 0x05, + OpCode::Dup => 0x06, + OpCode::Pop => 0x07, }; - vec![opcode_byte] + vec![byte] } UntypedAst::Sublist(children) => { - // 0x03 => SUBLIST => next 2 bytes = big-endian length, then sub-payload + // 0x03 => SUBLIST + // Then 2 bytes for the length (big-endian `u16`), + // Then the concatenated child bytecode. let mut payload = Vec::new(); for child in children { - payload.extend(child.to_bytecode()); + let child_bytes = child.to_bytecode(); + payload.extend_from_slice(&child_bytes); } + let sub_len = payload.len() as u16; let mut bytes = Vec::with_capacity(1 + 2 + payload.len()); bytes.push(0x03); - bytes.extend_from_slice(&sub_len.to_be_bytes()); // big-endian + bytes.extend_from_slice(&sub_len.to_be_bytes()); // big-endian length bytes.extend_from_slice(&payload); bytes } @@ -419,15 +98,18 @@ impl Push3Ast for UntypedAst { } } -/* -------------------------------------------- - 3) S-expression parsing helpers --------------------------------------------- */ +// ---------------------------------------------------------------------------- +// S-Expression Parsing Helpers +// ---------------------------------------------------------------------------- + +/// A simple S-expression tree for textual representation: either an `Atom` or a `List`. #[derive(Debug, Clone, PartialEq)] pub enum SExpr { Atom(String), List(Vec), } +/// Tokenize a string into parentheses and symbols (atoms). pub fn tokenize(s: &str) -> Vec { let mut tokens = Vec::new(); let mut current = String::new(); @@ -460,9 +142,10 @@ pub fn tokenize(s: &str) -> Vec { tokens } +/// Recursive helper to parse a single S-expression from a list of tokens, advancing `pos`. fn parse_sexpr_internal(tokens: &[String], pos: &mut usize) -> Result { if *pos >= tokens.len() { - return Err("Unexpected end of tokens".into()); + return Err("Unexpected end of tokens".to_string()); } let token = &tokens[*pos]; @@ -475,47 +158,52 @@ fn parse_sexpr_internal(tokens: &[String], pos: &mut usize) -> Result= tokens.len() { - return Err("Missing closing parenthesis".into()); + return Err("Missing closing parenthesis".to_string()); } *pos += 1; // consume ')' Ok(SExpr::List(items)) } - ")" => { - Err("Unexpected ')'".into()) - } + ")" => Err("Unexpected ')'".to_string()), _ => { - let atom = token.clone(); + let atom_str = token.clone(); *pos += 1; - Ok(SExpr::Atom(atom)) + Ok(SExpr::Atom(atom_str)) } } } -/// Parse an entire string into a single top-level `SExpr`. +/// Parse a full string into a single top-level `SExpr`, assuming balanced parentheses. pub fn parse_string_to_sexpr(s: &str) -> Result { let tokens = tokenize(s); let mut pos = 0; let expr = parse_sexpr_internal(&tokens, &mut pos)?; if pos < tokens.len() { - return Err(format!("Extra tokens after parse: {:?}", &tokens[pos..])); + Err(format!( + "Extra tokens after parse: {:?}", + &tokens[pos..] + )) + } else { + Ok(expr) } - Ok(expr) } -/// Convert an SExpr => UntypedAst +/// Convert an S-expression to an **untyped** AST node. pub fn sexpr_to_untyped(expr: &SExpr) -> Result { match expr { SExpr::Atom(text) => { + // 1) Try parse as integer if let Ok(val) = text.parse::() { Ok(UntypedAst::IntLiteral(val)) } else { + // 2) Otherwise interpret as an opcode match text.to_uppercase().as_str() { - "+" => Ok(UntypedAst::Instruction(OpCode::Plus)), - "-" => Ok(UntypedAst::Instruction(OpCode::Minus)), - "*" => Ok(UntypedAst::Instruction(OpCode::Mult)), + "+" => Ok(UntypedAst::Instruction(OpCode::Plus)), + "-" => Ok(UntypedAst::Instruction(OpCode::Minus)), + "*" => Ok(UntypedAst::Instruction(OpCode::Mult)), "DUP" => Ok(UntypedAst::Instruction(OpCode::Dup)), "POP" => Ok(UntypedAst::Instruction(OpCode::Pop)), - _ => Ok(UntypedAst::Instruction(OpCode::Noop)), + // unknown => treat as Noop + _ => Ok(UntypedAst::Instruction(OpCode::Noop)), } } } @@ -528,3 +216,31 @@ pub fn sexpr_to_untyped(expr: &SExpr) -> Result { } } } + +// ---------------------------------------------------------------------------- +// (Optional) Placeholder for a future typed AST +// ---------------------------------------------------------------------------- + +// /// In the future, we plan to define a `TypedAst` enum that ensures each operation +// /// has the correct number of typed children. We might also handle errors +// /// if an operation expects two integer children, but the user tries to attach +// /// a sublist or zero children, etc. +// /// +// /// For now, the untyped AST suffices for quick prototyping, but typed checks +// /// will be crucial in more advanced genetic programming or static analysis scenarios. +// #[derive(Debug, Clone)] +// pub enum TypedAst { +// // e.g. IntLiteral(i32), +// // Instruction(InstructionKind), +// } + +// #[derive(Debug, Clone)] +// pub enum InstructionKind { +// // e.g. Plus(Box, Box), +// // Minus(Box, Box), +// // Mult(Box, Box), +// // Dup, +// // Pop, +// } + +// // etc. diff --git a/offchain/src/main.rs b/offchain/src/main.rs index 5a473d0..d931b73 100644 --- a/offchain/src/main.rs +++ b/offchain/src/main.rs @@ -1,3 +1,5 @@ +// src/main.rs + mod compiler; use std::env; @@ -21,29 +23,36 @@ use revm::{ }; use ethers::abi::{encode, Token}; use ethers::abi::{ParamType, decode}; -use ethers::types::U256; // Use ethers' U256 instead +use ethers::types::U256; +use serde::Deserialize; // <--- NEW: for deserializing from JSON +#[derive(Debug, Deserialize)] +struct BytecodeObject { + object: String, +} +#[derive(Debug, Deserialize)] +struct MyContractArtifact { + bytecode: BytecodeObject, +} fn main() -> Result<()> { - // 1) Read CLI arguments let args: Vec = std::env::args().collect(); if args.len() < 2 { eprintln!("Usage: cargo run -- ''"); eprintln!("Example: cargo run -- '((3 5 +) DUP MUL)'"); - // If you want to indicate a failure exit code: std::process::exit(1); } let program_str = &args[1]; // 2) Parse the string into an S-expression let sexpr = parse_string_to_sexpr(program_str) - .map_err(|e| anyhow::anyhow!("Error parsing S-expression: {}", e))?; + .map_err(|e| anyhow!("Error parsing S-expression: {}", e))?; // 3) Convert SExpr => UntypedAst let ast: UntypedAst = sexpr_to_untyped(&sexpr) - .map_err(|e| anyhow::anyhow!("Error converting to UntypedAst: {}", e))?; + .map_err(|e| anyhow!("Error converting to UntypedAst: {}", e))?; // 4) Convert UntypedAst => Push3 bytecode let bytecode = ast.to_bytecode(); @@ -51,16 +60,35 @@ fn main() -> Result<()> { // 5) Print the resulting AST and bytecode (in hex) println!("AST: {:?}", ast); println!("Bytecode (hex): 0x{}", hex::encode(&bytecode)); + + // ---------------------------------------------------------------------- + // NEW: Read the contract creation code (bytecode) from a JSON artifact + // ---------------------------------------------------------------------- + // Example JSON (Forge artifact) might look like: + // { + // "bytecode": "60808060...0033" <--- entire creation code + // ... other fields ... + // } + + // Path to your JSON artifact. Adjust as needed: + let creation_hex_filename = "../onchain/out/Push3Interpreter.sol/Push3Interpreter.json"; + + // Read and parse the JSON artifact + let creation_json = std::fs::read_to_string(creation_hex_filename) + .map_err(|e| anyhow!("Failed to read JSON file {}: {}", creation_hex_filename, e))?; + let contract_artifact: MyContractArtifact = serde_json::from_str(&creation_json) + .map_err(|e| anyhow!("Failed to parse JSON artifact: {}", e))?; - // 1) Suppose you have compiled your contract with Forge. - // Grab the "bytecode" field from e.g. `out/MyContract.sol/MyContract.json`. - // We'll store it here as a string. This is your entire "creation code." - // (Example placeholder below.) - let creation_hex = "6080806040523461001657610cd8908161001b8239f35b5f80fdfe6080604052600480361015610012575f80fd5b5f803560e01c918263093b62c0146100395750506336d9ea8514610034575f80fd5b6101ce565b346101045760803660031901126101045780359167ffffffffffffffff918284116101045736602385011215610104578381013590838211610100573660248387010111610100576024358481116100fc576100989036908301610108565b9290916044358681116100f8576100b29036908301610108565b9690956064359182116100f5576100f16100e260248b8b8b8b8b8b6100d9368c8e01610108565b97909601610480565b60409391935193849384610170565b0390f35b80fd5b8580fd5b8380fd5b8280fd5b5080fd5b9181601f840112156101395782359167ffffffffffffffff8311610139576020808501948460051b01011161013957565b5f80fd5b9081518082526020808093019301915f5b82811061015c575050505090565b83518552938101939281019260010161014e565b906101866101959160608452606084019061013d565b6020938382038585015261013d565b9060408183039101528180845192838152019301915f5b8281106101ba575050505090565b8351855293810193928101926001016101ac565b346101395760803660031901126101395760043560048110156101395763ffffffff60243581811681036101395760443591821682036101395760643590600160b81b82101561024c576020936040519363ffffffff60b81b9060b81b169163ffffffff60d81b9060d81b169060ff60f81b9060f81b161717178152f35b60405162461bcd60e51b81526020600482015260136024820152726c6f77313834206f7574206f662072616e676560681b6044820152606490fd5b634e487b7160e01b5f52602160045260245ffd5b600411156102a557565b610287565b600160b81b81101561024c57600160f91b1790565b634e487b7160e01b5f52601160045260245ffd5b9061010082018092116102e257565b6102bf565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff81116103135760051b60200190565b6102e7565b90610322826102fb565b60405190601f1990601f018116820167ffffffffffffffff8111838210176103135760405283825261035482946102fb565b0190602036910137565b5f1981146102e25760010190565b634e487b7160e01b5f52603260045260245ffd5b91908110156103905760051b0190565b61036c565b80518210156103905760209160051b010190565b5f198101919082116102e257565b6001198101919082116102e257565b919082039182116102e257565b80156102e2575f190190565b90600263ffffffff809316019182116102e257565b90600463ffffffff809316019182116102e257565b91909163ffffffff808094169116019182116102e257565b600611156102a557565b81810292915f8212600160ff1b8214166102e25781840514901517156102e257565b81810392915f1380158285131691841216176102e257565b9190915f83820193841291129080158216911516176102e257565b9794929197969396610499610494846102d3565b610318565b985f5b8481106108ac5750506104b1610494856102d3565b97845f5b81811061088c57505050836104cc610494876102d3565b97865f5b818110610866575050505b6105855750506104ea81610318565b965f5b8281106105675750505061050081610318565b945f5b8281106105495750505061051681610318565b925f5b82811061052557505050565b806105336105449284610395565b5161053e8288610395565b5261035e565b610519565b806105576105629284610395565b5161053e828a610395565b610503565b806105756105809284610395565b5161053e828c610395565b6104ed565b6105a161059a610594866103a9565b8a610395565b51946103d3565b93846105af8260f81c6108c5565b916105b98361029b565b600192808403610777575060ff6105d091166108d4565b916105da83610421565b826105e8575b5090506104db565b6105f183610421565b82810361065c57505050600285101561060e575b835b805f6105e0565b6106558561064b61062861062288996103a9565b8b610395565b5161064561063e610638856103b7565b8d610395565b51936103b7565b92610465565b61053e828b610395565b9450610605565b61066583610421565b6002928084036106b157505050851015610680575b83610607565b6106aa8561064b61069461062288996103a9565b516106a461063e610638856103b7565b9261044d565b945061067a565b6106ba81610421565b600381036106fc575050508510156106d25783610607565b6106aa8561064b6106e661062288996103a9565b516106f661063e610638856103b7565b9261042b565b9091925061070981610421565b6004810361073d575090508510156107215783610607565b6106aa8561073261059487986103a9565b5161053e828b610395565b80610749600592610421565b14610755575b50610607565b9050851015610766575b835f61074f565b61077084956103a9565b945061075f565b909291506107848161029b565b600281036107ad575050849563ffffffff6107a7921660030b61053e828b610395565b946104db565b916003836107bb899561029b565b0361085f5763ffffffff908582808360d81c169260b81c16926107de8484610409565b1611156107ee575b5050506104db565b829350906107fd918686610904565b5f925b61080c575b86926107e6565b9091958a825180891015610857578261084f9261053e879561084261083c8e610837610849986103a9565b6103c6565b89610395565b5192610395565b9761035e565b929190610800565b505095610805565b50506104db565b82935061087881836108839495610380565b3561053e828d610395565b908692916104d0565b808b61053e826108a06108a7958789610380565b3592610395565b6104b5565b808b61053e826108a06108c0958a88610380565b61049c565b60ff1660048110156102a55790565b60ff1660068110156102a55790565b90821015610390570190565b63ffffffff8091169081146102e25760010190565b919063ffffffff92610917848616610318565b95846109245f9786610409565b16955b85851687811015610bbd5784811015610bbd5761096a61096461095e61095060ff9489896108e3565b356001600160f81b03191690565b60f81c90565b966108ef565b95168061098d575061098590600160f81b61053e828b610395565b955b95610927565b600181036109b257506109ac906001600160f81b0161053e828b610395565b95610987565b60028103610a495750866109d16109c8876103f4565b63ffffffff1690565b111580610a34575b15610a01576109ac9061064b876109fa6109f4898989610bca565b986103f4565b97166102aa565b945094505050505b610a1281610318565b925f5b828110610a2157505050565b80610533610a2f9284610395565b610a15565b5083610a426109c8876103f4565b11156109d9565b9096949060038103610b2c575084610a636109c8836103df565b111580610b17575b15610b0b57610a84610a7e828686610c36565b916103df565b9661ffff82169186610a996109c8858c610409565b111580610af5575b15610ae757610ae19291610adb9160d88b901b63ffffffff60d81b1660b89190911b61ffff60b81b1617600360f81b1761053e828d610395565b97610409565b93610987565b509550509450505050610a09565b5085610b046109c8858c610409565b1115610aa1565b50949350505050610a09565b5083610b256109c8836103df565b1115610a6b565b9496909460048103610b4f57506109ac906002600160f81b0161053e828b610395565b60058103610b6e57506109ac906003600160f81b0161053e828b610395565b60068103610b8d57506109ac906004600160f81b0161053e828b610395565b600703610baa576109ac906005600160f81b0161053e828b610395565b6109ac90600160f81b61053e828b610395565b5094509450505050610a09565b919063ffffffff610bda836103f4565b1611610bf157600490604051920182375160e01c90565b60405162461bcd60e51b815260206004820152601760248201527f7265616455696e743332206f7574206f662072616e67650000000000000000006044820152606490fd5b919063ffffffff610c46836103df565b1611610c5d57600290604051920182375160f01c90565b60405162461bcd60e51b815260206004820152601760248201527f7265616455696e743136206f7574206f662072616e67650000000000000000006044820152606490fdfea26469706673582212208a8e0c1517585160ff23b605caf6916a05dae2b541b9387b0dfab23ea71f563964736f6c63430008140033"; - // ^^^^^ Replace with your actual creation code from forge. + // Extract the "bytecode" field from the JSON + let raw_hex = &contract_artifact.bytecode.object; + let stripped_hex = raw_hex.trim_start_matches("0x"); + + // ---------------------------------------------------------------------- + // The rest of the deployment+call logic remains mostly unchanged + // ---------------------------------------------------------------------- // 2) Convert hex string to raw bytes. - let creation_bytes = match hex::decode(creation_hex) { + let creation_bytes = match hex::decode(stripped_hex) { Ok(bytes) => bytes, Err(e) => bail!("Invalid hex for creation code: {e}"), }; @@ -71,8 +99,7 @@ fn main() -> Result<()> { Context::builder() .modify_tx_chained(|tx| { tx.transact_to = TxKind::Create; - tx.data = Bytes::from(creation_bytes.clone()); - // If you want to attach a value, e.g. tx.value = + tx.data = Bytes::from(creation_bytes.clone()); }) // b) Provide an in-memory DB for ephemeral state .with_db(CacheDB::::default()), @@ -83,7 +110,7 @@ fn main() -> Result<()> { println!("Deploying contract with creation code size: {} bytes", creation_bytes.len()); // 4) Execute the CREATE transaction - let creation_result = evm.exec_commit()?; + let creation_result = evm.exec_commit()?; // => an ExecutionResult // 5) Check success @@ -96,52 +123,49 @@ fn main() -> Result<()> { }; println!("Deployed contract at: 0x{:x}", deployed_addr); - + // 1) Prepare the function selector for runInterpreter let func_selector = ðers::utils::id("runInterpreter(bytes,uint256[],uint256[],int256[])")[0..4]; - + // 2) Convert your compiled “Push3” bytecode into the `bytes` argument let code_arg = Token::Bytes(bytecode.clone()); - + // 3) Build a “SUBLIST descriptor” for the entire bytecode. - // In Solidity, SUBLIST = CodeTag.SUBLIST = 3. The layout is: - // [255..248]=tag, [247..216]=offset, [215..184]=length, [183..0]=low184 let tag_bits = U256::from(3u64) << 248; // CodeTag.SUBLIST = 3 let offset_bits = U256::from(0u64) << 216; // offset=0 let length_bits = U256::from(bytecode.len() as u64) << 184; // length = bytecode.len() - let low_184 = U256::zero(); - + let low_184 = U256::zero(); + let sublist_descriptor = tag_bits | offset_bits | length_bits | low_184; - // Now we put *that* descriptor as the one and only item in `initExecStack`. + // Now we put that descriptor as the one and only item in `initExecStack`. let init_exec_stack = Token::Array(vec![ Token::Uint(sublist_descriptor) ]); - + // For the other two arrays (codeStack, intStack), we’ll just leave them empty: let empty_uint256_array = Token::Array(vec![]); // codeStack let empty_int256_array = Token::Array(vec![]); // intStack // 4) Encode all arguments in the correct order: - // (bytes code, uint256[] initCodeStack, uint256[] initExecStack, int256[] initIntStack) let encoded_args = encode(&[ code_arg, empty_uint256_array.clone(), // initCodeStack init_exec_stack, // initExecStack - empty_uint256_array.clone(), // initIntStack (or empty_int256_array if needed) + empty_uint256_array.clone(), // initIntStack ]); - + // 5) Concatenate selector + encoded arguments to form the full call data let mut call_data = Vec::from(func_selector); call_data.extend_from_slice(&encoded_args); - + // 6) Modify the transaction to call `runInterpreter` with the encoded data evm.context.modify_tx(|tx| { tx.transact_to = TxKind::Call(deployed_addr); tx.data = Bytes::from(call_data); tx.nonce += 1; // increment nonce to avoid reuse }); - + // 7) Execute the call. let call_result = evm.transact()?; match &call_result.result { @@ -150,10 +174,8 @@ fn main() -> Result<()> { .. } => { println!("Call succeeded, returned data: 0x{}", hex::encode(return_data)); - + // Decode (uint256[], uint256[], int256[]) - use ethers::abi::{decode, ParamType}; - let param_types = &[ ParamType::Array(Box::new(ParamType::Uint(256))), // finalCodeStack ParamType::Array(Box::new(ParamType::Uint(256))), // finalExecStack @@ -171,6 +193,6 @@ fn main() -> Result<()> { other => { bail!("Call failed: {other:?}"); } - } + } Ok(()) } -- 2.34.1 From 46683c4e2137ba90e28ebe78fa1b4553622892bd Mon Sep 17 00:00:00 2001 From: zjkree Date: Mon, 13 Jan 2025 10:12:43 +0100 Subject: [PATCH 05/10] Update to ast. --- offchain/src/compiler/ast.rs | 139 +++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/offchain/src/compiler/ast.rs b/offchain/src/compiler/ast.rs index a8ca27b..e7fcce9 100644 --- a/offchain/src/compiler/ast.rs +++ b/offchain/src/compiler/ast.rs @@ -1,39 +1,50 @@ -//! # ast.rs -//! This module defines the **Abstract Syntax Trees (ASTs)** for our Push3-like language. -//! -//! Currently, we provide only an **untyped AST** (`UntypedAst`), which allows any sequence -//! of instructions, sublists, or integer literals. This is easy to parse and mutate, but -//! **does not** enforce correctness of operand types (for example, `INTEGER_PLUS` might -//! appear even if there's only one integer on the stack). -//! -//! ## Future: Typed AST -//! We **plan** to add a **typed AST** implementation, where each node ensures the correct -//! number and type of arguments at compile-time. This would prevent invalid programs from -//! being constructed in the first place. However, that is not implemented here yet—it’s -//! an **eventual goal** for more advanced genetic programming or verification workflows. +//! src/compiler/ast.rs +//! +//! This module defines an **abstract** untyped AST for our Push3-like language, +//! plus a mapping for how to encode opcodes as bytes. We do *not* hardcode numeric +//! values in the `OpCode` enum. Instead, we provide a trait that can map +//! opcodes to bytes. This allows us to expand or change instructions easily +//! (e.g., when the on-chain interpreter adds new opcodes or changes their IDs). -use serde::{Deserialize, Serialize}; -// use std::fmt; - -/// A trait describing the core operation: converting an AST to Push3 bytecode. +/// A trait describing how to convert an AST into Push3 bytecode. /// -/// We might later add more methods here (like parsing from bytecode or mutation). +/// This is deliberately minimal for now. In the future, we could add more methods +/// (like parsing from bytecode or AST mutation). pub trait Push3Ast { + /// Convert this AST into a bytecode vector that the on-chain interpreter + /// can parse and execute. fn to_bytecode(&self) -> Vec; } -/// The untyped AST: each node is either an integer literal, a single instruction (no children), -/// or a sublist (which recursively contains more AST nodes). -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +/// A trait that **maps** each [`OpCode`] variant to its **single-byte** representation. +/// +/// By centralizing this, we can easily add or reorder instructions without rewriting +/// big chunks of code everywhere. For example, if we add `OpCode::MyNewOp`, we just +/// update this trait’s logic. +pub trait OpCodeMapping { + /// Given an `OpCode` enum variant, return the corresponding single `u8` + /// that the interpreter expects. + fn opcode_byte(&self, op: &OpCode) -> u8; + + // If you need reverse-lookup (byte => OpCode), you could add a method like: + // fn from_byte(&self, b: u8) -> Option; + // for now, we omit it since we only do forward mapping in this file. +} + +/// Our untyped AST node: +/// - `IntLiteral(i32)` holds a literal integer, +/// - `Instruction(OpCode)` holds one opcode, +/// - `Sublist(Vec)` holds a collection of nested AST nodes. +#[derive(Debug, Clone, PartialEq)] pub enum UntypedAst { IntLiteral(i32), Instruction(OpCode), Sublist(Vec), } -/// The set of push3 instructions recognized in our untyped AST. -/// Each corresponds to a single token byte in `to_bytecode`. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +/// An **abstract** set of opcodes. We do *not* assign numeric values here. +/// Instead, see [`OpCodeMapping::opcode_byte`] for how we convert them to bytes. +#[derive(Debug, Clone, PartialEq)] pub enum OpCode { Noop, Plus, @@ -41,63 +52,79 @@ pub enum OpCode { Mult, Dup, Pop, + // Add new instructions here as needed. E.g.: + // MyNewOp, etc. } -/// Implementation of `Push3Ast` for the **untyped** AST. -/// -/// This produces bytecode recognized by the Push3Interpreter contract: -/// -/// - `0x00` => NOOP -/// - `0x01` => INTEGER_PLUS -/// - `0x02` => INT_LITERAL => next 4 bytes (little-endian i32) -/// - `0x03` => SUBLIST => next 2 bytes (big-endian `u16` length), then the sublist contents -/// - `0x04` => INTEGER_MINUS -/// - `0x05` => INTEGER_MULT -/// - `0x06` => INTEGER_DUP -/// - `0x07` => INTEGER_POP -impl Push3Ast for UntypedAst { - fn to_bytecode(&self) -> Vec { +impl UntypedAst { + /// Encode this AST into bytecode, using a provided [`OpCodeMapping`]. + /// + /// This method is more flexible than `to_bytecode()`, because you can pass in + /// *any* mapping if needed. The method used by the trait’s `to_bytecode()` + /// relies on the global `DEFAULT_OP_MAPPING`. + pub fn to_bytecode_with_mapping(&self, mapping: &M) -> Vec { match self { + // For an integer literal, we write the “tag byte” for int-literal, then 4 bytes (LE). UntypedAst::IntLiteral(val) => { - // 0x02 => INT_LITERAL => then 4 bytes little-endian + // Hardcode 0x02 => INT_LITERAL. + // You *could* put that in the mapping if you want to make that flexible, too. let mut bytes = Vec::with_capacity(1 + 4); bytes.push(0x02); bytes.extend_from_slice(&val.to_be_bytes()); bytes } UntypedAst::Instruction(op) => { - // Single byte representing the opcode - let byte = match op { - OpCode::Noop => 0x00, - OpCode::Plus => 0x01, - OpCode::Minus => 0x04, - OpCode::Mult => 0x05, - OpCode::Dup => 0x06, - OpCode::Pop => 0x07, - }; - vec![byte] + // Use the mapping to find the correct opcode byte: + let b = mapping.opcode_byte(op); + vec![b] } UntypedAst::Sublist(children) => { - // 0x03 => SUBLIST - // Then 2 bytes for the length (big-endian `u16`), - // Then the concatenated child bytecode. + // Hardcode 0x03 => SUBLIST, then big-endian length, then child payload let mut payload = Vec::new(); for child in children { - let child_bytes = child.to_bytecode(); - payload.extend_from_slice(&child_bytes); + let child_bytes = child.to_bytecode_with_mapping(mapping); + payload.extend(child_bytes); } - let sub_len = payload.len() as u16; let mut bytes = Vec::with_capacity(1 + 2 + payload.len()); bytes.push(0x03); bytes.extend_from_slice(&sub_len.to_be_bytes()); // big-endian length - bytes.extend_from_slice(&payload); + bytes.extend(payload); bytes } } } } +/// For convenience, we implement `Push3Ast` using a *default* mapping. +impl Push3Ast for UntypedAst { + fn to_bytecode(&self) -> Vec { + self.to_bytecode_with_mapping(&DEFAULT_OP_MAPPING) + } +} + +/// A default mapping that corresponds to your current on-chain byte definitions. +/// +/// This way, if your interpreter changes (e.g., `Minus` becomes 0x0A), +/// you just update this mapping. +pub struct DefaultOpCodeMapping; + +impl OpCodeMapping for DefaultOpCodeMapping { + fn opcode_byte(&self, op: &OpCode) -> u8 { + match op { + OpCode::Noop => 0x00, // 0x00 => NOOP + OpCode::Plus => 0x01, // 0x01 => INTEGER_PLUS + OpCode::Minus => 0x04, // 0x04 => INTEGER_MINUS + OpCode::Mult => 0x05, // 0x05 => INTEGER_MULT + OpCode::Dup => 0x06, // 0x06 => INTEGER_DUP + OpCode::Pop => 0x07, // 0x07 => INTEGER_POP + } + } +} + +/// A convenient global `const` or `static` for quick usage. +pub const DEFAULT_OP_MAPPING: DefaultOpCodeMapping = DefaultOpCodeMapping; + // ---------------------------------------------------------------------------- // S-Expression Parsing Helpers // ---------------------------------------------------------------------------- -- 2.34.1 From 856779e0bc0db59c3f67f3354ba9245ae3786699 Mon Sep 17 00:00:00 2001 From: zjkree Date: Mon, 13 Jan 2025 10:35:54 +0100 Subject: [PATCH 06/10] Add revm_runner as module. --- offchain/Cargo.lock | 250 +++++++++--------- offchain/src/compiler/mod.rs | 1 + offchain/src/compiler/push3_describtor.rs | 67 +++++ offchain/src/evm_integration/revm_runner.rs | 0 offchain/src/main.rs | 182 ++++--------- .../src/{evm_integration => runner}/mod.rs | 0 offchain/src/runner/revm_runner.rs | 232 ++++++++++++++++ 7 files changed, 480 insertions(+), 252 deletions(-) create mode 100644 offchain/src/compiler/push3_describtor.rs delete mode 100644 offchain/src/evm_integration/revm_runner.rs rename offchain/src/{evm_integration => runner}/mod.rs (100%) create mode 100644 offchain/src/runner/revm_runner.rs diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock index d3e9827..2349a75 100644 --- a/offchain/Cargo.lock +++ b/offchain/Cargo.lock @@ -70,9 +70,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.15" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6259a506ab13e1d658796c31e6e39d2e2ee89243bcc505ddc613b35732e0a430" +checksum = "788bb18e8f61d5d9340b52143f27771daf7e1dccbaf2741621d2493f9debf52e" dependencies = [ "alloy-rlp", "bytes", @@ -81,7 +81,6 @@ dependencies = [ "derive_more", "foldhash", "hashbrown", - "hex-literal", "indexmap", "itoa", "k256", @@ -115,7 +114,7 @@ checksum = "5a833d97bf8a5f0f878daf2c8451fff7de7f9de38baa5a45d936ec718d81255a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -265,13 +264,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -303,7 +302,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -380,9 +379,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "1be3f42a67d6d345ecd59f675f3f012d6974981560836e938c22b424b85ce1be" [[package]] name = "bitvec" @@ -524,9 +523,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.5" +version = "1.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" +checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" dependencies = [ "jobserver", "libc", @@ -775,7 +774,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -795,7 +794,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "unicode-xid", ] @@ -870,7 +869,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -962,7 +961,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1117,7 +1116,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.91", + "syn 2.0.96", "toml", "walkdir", ] @@ -1135,7 +1134,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1161,7 +1160,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.91", + "syn 2.0.96", "tempfile", "thiserror 1.0.69", "tiny-keccak", @@ -1478,7 +1477,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1560,9 +1559,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "gloo-timers" @@ -1642,12 +1641,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hex-literal" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" - [[package]] name = "hmac" version = "0.12.1" @@ -1853,7 +1846,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1912,7 +1905,7 @@ checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -1990,9 +1983,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", @@ -2102,15 +2095,15 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.7.0", "libc", ] [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "litemap" @@ -2290,7 +2283,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -2469,7 +2462,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 2.0.9", + "thiserror 2.0.11", "ucd-trie", ] @@ -2495,35 +2488,35 @@ dependencies = [ [[package]] name = "phf" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" dependencies = [ "phf_macros", - "phf_shared 0.11.2", + "phf_shared 0.11.3", ] [[package]] name = "phf_generator" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" dependencies = [ - "phf_shared 0.11.2", + "phf_shared 0.11.3", "rand", ] [[package]] name = "phf_macros" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" dependencies = [ "phf_generator", - "phf_shared 0.11.2", + "phf_shared 0.11.3", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -2532,43 +2525,43 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" dependencies = [ - "siphasher", + "siphasher 0.3.11", ] [[package]] name = "phf_shared" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ - "siphasher", + "siphasher 1.0.1", ] [[package]] name = "pin-project" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" +checksum = "1e2ec53ad785f4d35dac0adea7f7dc6f1bb277ad84a680c7afefeae05d1f5916" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" +checksum = "d56a66c0c55993aa927429d0f8a0abfd74f084e4d9c192cffed01e418d83eefb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "pin-project-lite" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" [[package]] name = "pin-utils" @@ -2615,12 +2608,12 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.25" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac" dependencies = [ "proc-macro2", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -2648,9 +2641,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -2663,7 +2656,7 @@ checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.6.0", + "bitflags 2.7.0", "lazy_static", "num-traits", "rand", @@ -2683,9 +2676,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -2761,7 +2754,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.7.0", ] [[package]] @@ -3008,7 +3001,7 @@ name = "revm-state" version = "1.0.0" source = "git+https://github.com/bluealloy/revm.git?rev=03ea24bd9550e93b08f343e0b410725557c1adb4#03ea24bd9550e93b08f343e0b410725557c1adb4" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.7.0", "revm-bytecode", "revm-primitives", "revm-specification", @@ -3155,11 +3148,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.42" +version = "0.38.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.7.0", "errno", "libc", "linux-raw-sys", @@ -3199,9 +3192,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" [[package]] name = "rusty-fork" @@ -3260,7 +3253,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3365,29 +3358,29 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "serde_json" -version = "1.0.134" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" dependencies = [ "itoa", "memchr", @@ -3476,13 +3469,13 @@ dependencies = [ [[package]] name = "simple_asn1" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb" dependencies = [ "num-bigint", "num-traits", - "thiserror 1.0.69", + "thiserror 2.0.11", "time", ] @@ -3492,6 +3485,12 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "slab" version = "0.4.9" @@ -3597,7 +3596,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3652,9 +3651,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.91" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -3675,7 +3674,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3707,12 +3706,13 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.14.0" +version = "3.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" dependencies = [ "cfg-if", "fastrand", + "getrandom", "once_cell", "rustix", "windows-sys 0.59.0", @@ -3740,11 +3740,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.9" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" dependencies = [ - "thiserror-impl 2.0.9", + "thiserror-impl 2.0.11", ] [[package]] @@ -3755,18 +3755,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] name = "thiserror-impl" -version = "2.0.9" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -3845,9 +3845,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.42.0" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" dependencies = [ "backtrace", "bytes", @@ -3955,7 +3955,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4144,34 +4144,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.49" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", @@ -4182,9 +4183,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4192,28 +4193,31 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -4406,9 +4410,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.20" +version = "0.6.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" dependencies = [ "memchr", ] @@ -4489,7 +4493,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "synstructure", ] @@ -4511,7 +4515,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4531,7 +4535,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", "synstructure", ] @@ -4552,7 +4556,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] @@ -4574,7 +4578,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.91", + "syn 2.0.96", ] [[package]] diff --git a/offchain/src/compiler/mod.rs b/offchain/src/compiler/mod.rs index 851c0bc..c705e00 100644 --- a/offchain/src/compiler/mod.rs +++ b/offchain/src/compiler/mod.rs @@ -1 +1,2 @@ pub mod ast; +pub mod push3_describtor; diff --git a/offchain/src/compiler/push3_describtor.rs b/offchain/src/compiler/push3_describtor.rs new file mode 100644 index 0000000..51197fb --- /dev/null +++ b/offchain/src/compiler/push3_describtor.rs @@ -0,0 +1,67 @@ +//! src/compiler/push3_descriptor.rs +//! +//! A small module of helper functions to construct or interpret the 256-bit descriptors +//! used by our on-chain `Push3Interpreter`. Each descriptor encodes a tag, an offset, +//! a length, and any leftover bits (e.g., immediate data). + +use ethers::types::U256; + +/// The 256-bit descriptor layout is as follows: +/// [ 8 bits: tag | 32 bits: offset | 32 bits: length | 184 bits: leftover ] +/// +/// We'll define small helper functions to build or parse these. +/// Our `make_sublist_descriptor` is an example for tag=3 (SUBLIST). + +/// Tag constants, if you want them: +pub const TAG_SUBLIST: u8 = 3; +pub const TAG_INT_LITERAL: u8 = 2; +pub const TAG_INSTRUCTION: u8 = 1; +pub const TAG_NONE: u8 = 0; + +/// A small helper to shift the tag into the top 8 bits. +#[inline] +fn tag_bits(tag: u8) -> U256 { + U256::from(tag) << 248 +} + +/// Build a descriptor for a SUBLIST with the given offset and length (in bytes), +/// leftover=0. +/// +/// # Example +/// ``` +/// let desc = make_sublist_descriptor(0, code_bytes.len() as u32); +/// // pass `desc` into the interpreter's exec stack +/// ``` +pub fn make_sublist_descriptor(offset: u32, length: u32) -> U256 { + tag_bits(TAG_SUBLIST as u8) + | (U256::from(offset) << 216) + | (U256::from(length) << 184) + | U256::zero() // leftover +} + +/// Possibly you want a more general helper that builds any descriptor: +/// If you have other uses for leftover bits, you can pass that in: +pub fn make_descriptor(tag: u8, offset: u32, length: u32, leftover: U256) -> U256 { + tag_bits(tag) + | (U256::from(offset) << 216) + | (U256::from(length) << 184) + | leftover +} + +/// If you want to parse a descriptor, you can define getTag, getOffset, getLength, etc: +pub fn get_tag(desc: U256) -> u8 { + // top 8 bits => shift right 248 + (desc >> 248).as_u32() as u8 +} + +pub fn get_offset(desc: U256) -> u32 { + ((desc >> 216) & U256::from(u32::MAX)).as_u32() +} + +pub fn get_length(desc: U256) -> u32 { + ((desc >> 184) & U256::from(u32::MAX)).as_u32() +} + +pub fn get_low_184(desc: U256) -> U256 { + desc & ((U256::from(1u64) << 184) - 1) +} diff --git a/offchain/src/evm_integration/revm_runner.rs b/offchain/src/evm_integration/revm_runner.rs deleted file mode 100644 index e69de29..0000000 diff --git a/offchain/src/main.rs b/offchain/src/main.rs index d931b73..90e1460 100644 --- a/offchain/src/main.rs +++ b/offchain/src/main.rs @@ -1,8 +1,11 @@ // src/main.rs mod compiler; +mod runner; use std::env; + +// We’ll use your existing AST definitions for parsing use compiler::ast::{ parse_string_to_sexpr, sexpr_to_untyped, @@ -10,22 +13,28 @@ use compiler::ast::{ UntypedAst, // The untyped AST enum }; +use runner::revm_runner::{EvmRunner, Push3InterpreterOutputs}; // <--- We import our EvmRunner + use anyhow::{anyhow, bail, Result}; use hex; -use database::CacheDB; -use revm::{ - context::Context, - context_interface::result::{ExecutionResult, Output}, - database_interface::EmptyDB, - handler::EthHandler, - primitives::{Bytes, TxKind}, - EvmCommit, MainEvm, -}; -use ethers::abi::{encode, Token}; -use ethers::abi::{ParamType, decode}; -use ethers::types::U256; -use serde::Deserialize; // <--- NEW: for deserializing from JSON +use serde::Deserialize; // For JSON artifact loading +// If you still need these (not strictly required anymore): +// use database::CacheDB; +// use revm::{ +// context::Context, +// context_interface::result::{ExecutionResult, Output}, +// database_interface::EmptyDB, +// handler::EthHandler, +// primitives::{Bytes, TxKind}, +// EvmCommit, MainEvm, +// }; +use ethers::abi::{decode, ParamType}; +use ethers::types::U256; + +// ---------------------------------------------------------------------- +// JSON artifact struct, as before +// ---------------------------------------------------------------------- #[derive(Debug, Deserialize)] struct BytecodeObject { object: String, @@ -36,9 +45,12 @@ struct MyContractArtifact { bytecode: BytecodeObject, } +// ---------------------------------------------------------------------- +// MAIN +// ---------------------------------------------------------------------- fn main() -> Result<()> { - // 1) Read CLI arguments - let args: Vec = std::env::args().collect(); + // 1) Read CLI arguments for the Push3 program + let args: Vec = env::args().collect(); if args.len() < 2 { eprintln!("Usage: cargo run -- ''"); eprintln!("Example: cargo run -- '((3 5 +) DUP MUL)'"); @@ -54,7 +66,7 @@ fn main() -> Result<()> { let ast: UntypedAst = sexpr_to_untyped(&sexpr) .map_err(|e| anyhow!("Error converting to UntypedAst: {}", e))?; - // 4) Convert UntypedAst => Push3 bytecode + // 4) Convert UntypedAst => Push3 bytecode (for debugging, so we can see it) let bytecode = ast.to_bytecode(); // 5) Print the resulting AST and bytecode (in hex) @@ -62,137 +74,49 @@ fn main() -> Result<()> { println!("Bytecode (hex): 0x{}", hex::encode(&bytecode)); // ---------------------------------------------------------------------- - // NEW: Read the contract creation code (bytecode) from a JSON artifact + // Load the creation code (bytecode) from a JSON artifact // ---------------------------------------------------------------------- - // Example JSON (Forge artifact) might look like: - // { - // "bytecode": "60808060...0033" <--- entire creation code - // ... other fields ... - // } - - // Path to your JSON artifact. Adjust as needed: let creation_hex_filename = "../onchain/out/Push3Interpreter.sol/Push3Interpreter.json"; - - // Read and parse the JSON artifact let creation_json = std::fs::read_to_string(creation_hex_filename) .map_err(|e| anyhow!("Failed to read JSON file {}: {}", creation_hex_filename, e))?; let contract_artifact: MyContractArtifact = serde_json::from_str(&creation_json) .map_err(|e| anyhow!("Failed to parse JSON artifact: {}", e))?; - - // Extract the "bytecode" field from the JSON + let raw_hex = &contract_artifact.bytecode.object; let stripped_hex = raw_hex.trim_start_matches("0x"); - // ---------------------------------------------------------------------- - // The rest of the deployment+call logic remains mostly unchanged - // ---------------------------------------------------------------------- - - // 2) Convert hex string to raw bytes. let creation_bytes = match hex::decode(stripped_hex) { Ok(bytes) => bytes, Err(e) => bail!("Invalid hex for creation code: {e}"), }; - // 3) Build a new EVM instance with a "Create" transaction: - let mut evm = MainEvm::new( - // a) Prepare context with a chained transaction - Context::builder() - .modify_tx_chained(|tx| { - tx.transact_to = TxKind::Create; - tx.data = Bytes::from(creation_bytes.clone()); - }) - // b) Provide an in-memory DB for ephemeral state - .with_db(CacheDB::::default()), - // c) The "EthHandler" for block/tx environment logic - EthHandler::default(), + println!( + "Loaded creation code ({} bytes) from {}", + creation_bytes.len(), + creation_hex_filename ); - println!("Deploying contract with creation code size: {} bytes", creation_bytes.len()); + // ---------------------------------------------------------------------- + // 6) Deploy the interpreter in an ephemeral EVM using `EvmRunner` + // ---------------------------------------------------------------------- + let mut runner = EvmRunner::new(creation_bytes)?; + println!("Interpreter deployed successfully in ephemeral EVM at: 0x{:x}", runner.interpreter_addr); - // 4) Execute the CREATE transaction - let creation_result = evm.exec_commit()?; - // => an ExecutionResult + // ---------------------------------------------------------------------- + // 7) Evaluate the AST in our EVM + // ---------------------------------------------------------------------- + // We'll call `runner.run_ast(&ast)`, which: + // - Converts AST => push3 code, + // - Builds a sublist descriptor in the exec stack, + // - Calls `runInterpreter`, + // - Returns final stacks in a `Push3InterpreterOutputs`. + let outputs = runner.run_ast(&ast)?; + println!("Ran the AST successfully!"); - // 5) Check success - let ExecutionResult::Success { - output: Output::Create(_, Some(deployed_addr)), - .. - } = creation_result - else { - bail!("Deployment failed or didn't return an address: {creation_result:#?}"); - }; + // 8) Print the final stacks + println!("Final CODE stack: {:?}", outputs.final_code_stack); + println!("Final EXEC stack: {:?}", outputs.final_exec_stack); + println!("Final INT stack: {:?}", outputs.final_int_stack); - println!("Deployed contract at: 0x{:x}", deployed_addr); - - // 1) Prepare the function selector for runInterpreter - let func_selector = ðers::utils::id("runInterpreter(bytes,uint256[],uint256[],int256[])")[0..4]; - - // 2) Convert your compiled “Push3” bytecode into the `bytes` argument - let code_arg = Token::Bytes(bytecode.clone()); - - // 3) Build a “SUBLIST descriptor” for the entire bytecode. - let tag_bits = U256::from(3u64) << 248; // CodeTag.SUBLIST = 3 - let offset_bits = U256::from(0u64) << 216; // offset=0 - let length_bits = U256::from(bytecode.len() as u64) << 184; // length = bytecode.len() - let low_184 = U256::zero(); - - let sublist_descriptor = tag_bits | offset_bits | length_bits | low_184; - - // Now we put that descriptor as the one and only item in `initExecStack`. - let init_exec_stack = Token::Array(vec![ - Token::Uint(sublist_descriptor) - ]); - - // For the other two arrays (codeStack, intStack), we’ll just leave them empty: - let empty_uint256_array = Token::Array(vec![]); // codeStack - let empty_int256_array = Token::Array(vec![]); // intStack - - // 4) Encode all arguments in the correct order: - let encoded_args = encode(&[ - code_arg, - empty_uint256_array.clone(), // initCodeStack - init_exec_stack, // initExecStack - empty_uint256_array.clone(), // initIntStack - ]); - - // 5) Concatenate selector + encoded arguments to form the full call data - let mut call_data = Vec::from(func_selector); - call_data.extend_from_slice(&encoded_args); - - // 6) Modify the transaction to call `runInterpreter` with the encoded data - evm.context.modify_tx(|tx| { - tx.transact_to = TxKind::Call(deployed_addr); - tx.data = Bytes::from(call_data); - tx.nonce += 1; // increment nonce to avoid reuse - }); - - // 7) Execute the call. - let call_result = evm.transact()?; - match &call_result.result { - ExecutionResult::Success { - output: Output::Call(return_data), - .. - } => { - println!("Call succeeded, returned data: 0x{}", hex::encode(return_data)); - - // Decode (uint256[], uint256[], int256[]) - let param_types = &[ - ParamType::Array(Box::new(ParamType::Uint(256))), // finalCodeStack - ParamType::Array(Box::new(ParamType::Uint(256))), // finalExecStack - ParamType::Array(Box::new(ParamType::Int(256))), // finalIntStack - ]; - - let decoded = decode(param_types, return_data) - .map_err(|e| anyhow!("Failed to decode return data: {e}"))?; - - println!("Decoded return: {:?}", decoded); - } - ExecutionResult::Revert { gas_used, output } => { - bail!("Call reverted: gas used = {gas_used:?}, output = {:?}", output); - } - other => { - bail!("Call failed: {other:?}"); - } - } Ok(()) } diff --git a/offchain/src/evm_integration/mod.rs b/offchain/src/runner/mod.rs similarity index 100% rename from offchain/src/evm_integration/mod.rs rename to offchain/src/runner/mod.rs diff --git a/offchain/src/runner/revm_runner.rs b/offchain/src/runner/revm_runner.rs new file mode 100644 index 0000000..fe97a21 --- /dev/null +++ b/offchain/src/runner/revm_runner.rs @@ -0,0 +1,232 @@ +//! src/evm_integration/revm_runner.rs +//! +//! This module provides a thin wrapper around REVM to deploy a Push3Interpreter +//! contract, then call its `runInterpreter(...)` function with flexible inputs/outputs, +//! using the same style (Context::builder(), .modify_tx_chained, etc.) you had in your main. + +use anyhow::{anyhow, bail, Result}; +use ethers::abi::{encode, decode, Token, ParamType}; +use ethers::types::U256; +use ethers::utils; +use database::CacheDB; +use revm::{ + context::Context, + context::{BlockEnv, TxEnv, CfgEnv}, + context_interface::result::{ExecutionResult, Output}, + database_interface::EmptyDB, + handler::EthHandler, + primitives::{Bytes, TxKind}, // 4 generics + EvmCommit, + MainEvm, +}; + +// We import your AST definitions so we can call `ast.to_bytecode()`. +use crate::compiler::ast::{UntypedAst, Push3Ast}; + +// If you have a descriptor helper (like make_sublist_descriptor), bring it in: +use crate::compiler::push3_describtor::make_sublist_descriptor; + +/// The input parameters for `runInterpreter(...)`: four fields (code, codeStack, execStack, intStack). +pub struct Push3InterpreterInputs { + pub code: Vec, + pub init_code_stack: Vec, + pub init_exec_stack: Vec, + pub init_int_stack: Vec, +} + +/// The outputs from `runInterpreter(...)`: three arrays for code/exec/int stacks. +pub struct Push3InterpreterOutputs { + pub final_code_stack: Vec, + pub final_exec_stack: Vec, + pub final_int_stack: Vec, +} + +/// A thin wrapper around REVM, parameterized by the 4 generics (DB, BLOCK, TX, CFG). +/// - We store the ephemeral EVM instance, +/// - We store the deployed address of your `Push3Interpreter`, +/// - We provide `run_interpreter` and `run_ast`. +pub struct EvmRunner { + /// The 4-parameter MainEvm: + /// DB = CacheDB, + /// BLOCK = BlockEnv, + /// TX = TxEnv, + /// CFG = CfgEnv + pub evm: MainEvm, BlockEnv, TxEnv, CfgEnv>, + + /// The address where Push3Interpreter was deployed. + pub interpreter_addr: revm::primitives::Address, +} + +impl EvmRunner { + /// Deploy a new ephemeral EVM with a "Create" transaction for the given `creation_code`. + /// + /// This matches your older style of: + /// `MainEvm::new(Context::builder()... .with_db(...), EthHandler::default())` + pub fn new(creation_code: Vec) -> Result { + // 1) Create the EVM using your old style: `Context::builder()...` + // Then pass to MainEvm::new(...). + // The difference is that we explicitly say MainEvm. + let mut evm = MainEvm::new( + // a) Prepare context with a chained transaction to CREATE + Context::builder() + .modify_tx_chained(|tx| { + tx.transact_to = TxKind::Create; + tx.data = Bytes::from(creation_code.clone()); + }) + // b) Provide ephemeral DB + .with_db(CacheDB::::default()), + // c) The EthHandler for block/tx environment logic + EthHandler::default(), + ); + + // 2) Execute the CREATE transaction + let creation_result = evm.exec_commit()?; + let ExecutionResult::Success { + output: Output::Create(_, Some(deployed_addr)), + .. + } = creation_result + else { + bail!("Interpreter deployment failed or no address returned: {creation_result:#?}"); + }; + + // 3) Return the EvmRunner + Ok(Self { + evm, + interpreter_addr: deployed_addr, + }) + } + + /// Call `runInterpreter(bytes,uint256[],uint256[],int256[])` on the deployed contract, + /// returning the final code/exec/int stacks. + pub fn run_interpreter( + &mut self, + inputs: &Push3InterpreterInputs + ) -> Result { + // 1) Build function selector + let func_selector = &utils::id("runInterpreter(bytes,uint256[],uint256[],int256[])")[0..4]; + + // 2) Convert each field to `ethers::abi::Token` + let code_token = Token::Bytes(inputs.code.clone()); + let init_code_stack = Token::Array( + inputs.init_code_stack + .iter() + .map(|&u| Token::Uint(u)) + .collect() + ); + let init_exec_stack = Token::Array( + inputs.init_exec_stack + .iter() + .map(|&u| Token::Uint(u)) + .collect() + ); + let init_int_stack = Token::Array( + inputs.init_int_stack + .iter() + .map(|&val_i128| { + // store i128 as a U256. If you need negative values, do a two’s complement approach. + let as_u128 = val_i128 as u128; + Token::Int(U256::from(as_u128)) + }) + .collect() + ); + + // 3) Encode + let encoded_args = encode(&[ + code_token, + init_code_stack, + init_exec_stack, + init_int_stack, + ]); + + // 4) Build final call data + let mut call_data = Vec::from(func_selector); + call_data.extend_from_slice(&encoded_args); + + // 5) Modify the transaction to CALL the deployed interpreter + self.evm.context.modify_tx(|tx| { + tx.transact_to = TxKind::Call(self.interpreter_addr); + tx.data = Bytes::from(call_data); + tx.nonce += 1; // increment nonce to avoid reuse + }); + + // 6) Execute the call + let call_result = self.evm.transact()?; + match &call_result.result { + ExecutionResult::Success { + output: Output::Call(return_data), + .. + } => { + // 7) Decode (uint256[], uint256[], int256[]) + let param_types = &[ + ParamType::Array(Box::new(ParamType::Uint(256))), // finalCodeStack + ParamType::Array(Box::new(ParamType::Uint(256))), // finalExecStack + ParamType::Array(Box::new(ParamType::Int(256))), // finalIntStack + ]; + let decoded = decode(param_types, return_data) + .map_err(|e| anyhow!("Failed to decode return data: {e}"))?; + + // parse each array + let final_code_stack = match &decoded[0] { + Token::Array(arr) => arr.iter().filter_map(|t| { + if let Token::Uint(u) = t { Some(*u) } else { None } + }).collect(), + _ => Vec::new(), + }; + let final_exec_stack = match &decoded[1] { + Token::Array(arr) => arr.iter().filter_map(|t| { + if let Token::Uint(u) = t { Some(*u) } else { None } + }).collect(), + _ => Vec::new(), + }; + let final_int_stack = match &decoded[2] { + Token::Array(arr) => arr.iter().filter_map(|t| { + if let Token::Int(u256_val) = t { + // read only the lower 128 bits => ignoring sign extension + let lo = u256_val.low_u128(); + Some(lo as i128) + } else { + None + } + }).collect(), + _ => Vec::new(), + }; + + Ok(Push3InterpreterOutputs { + final_code_stack, + final_exec_stack, + final_int_stack, + }) + } + ExecutionResult::Revert { gas_used, output } => { + bail!("Call reverted: gas used={gas_used:?}, output={output:?}") + } + other => { + bail!("Call failed: {other:?}") + } + } + } + + /// A convenience method to run an `UntypedAst`: + /// - Convert AST => push3 code, + /// - Build a sublist descriptor in the exec stack, + /// - Call `run_interpreter`. + pub fn run_ast(&mut self, ast: &UntypedAst) -> Result { + // 1) Convert AST => push3 bytecode + let code_bytes = ast.to_bytecode(); + let code_len = code_bytes.len() as u32; + + // 2) Build a sublist descriptor + let descriptor = make_sublist_descriptor(0, code_len); + + // 3) Put code in `code` and sublist descriptor in `execStack` + let inputs = Push3InterpreterInputs { + code: code_bytes, + init_code_stack: Vec::new(), + init_exec_stack: vec![descriptor], + init_int_stack: Vec::new(), + }; + + // 4) Run interpreter + self.run_interpreter(&inputs) + } +} -- 2.34.1 From c5538e35bbb0b04c491a9aca3a2983085cf5730c Mon Sep 17 00:00:00 2001 From: zjkree Date: Mon, 13 Jan 2025 11:57:18 +0100 Subject: [PATCH 07/10] Add random program generation and mutation. --- offchain/Cargo.toml | 4 ++ offchain/src/bin/gp_tester.rs | 91 ++++++++++++++++++++++++++++++ offchain/src/gp/generate.rs | 79 ++++++++++++++++++++++++++ offchain/src/gp/genetic_ops.rs | 70 ++++++++++++++++++++--- offchain/src/gp/mod.rs | 12 +--- offchain/src/helpers/artifact.rs | 41 ++++++++++++++ offchain/src/helpers/mod.rs | 1 + offchain/src/lib.rs | 4 ++ offchain/src/main.rs | 8 +-- offchain/src/runner/revm_runner.rs | 2 +- 10 files changed, 286 insertions(+), 26 deletions(-) create mode 100644 offchain/src/bin/gp_tester.rs create mode 100644 offchain/src/gp/generate.rs create mode 100644 offchain/src/helpers/artifact.rs create mode 100644 offchain/src/helpers/mod.rs create mode 100644 offchain/src/lib.rs diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index fffccda..03796d0 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -3,6 +3,10 @@ name = "offchain" version = "0.1.0" edition = "2021" +[[bin]] +name = "gp_tester" +path = "src/bin/gp_tester.rs" + [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/offchain/src/bin/gp_tester.rs b/offchain/src/bin/gp_tester.rs new file mode 100644 index 0000000..aae71ca --- /dev/null +++ b/offchain/src/bin/gp_tester.rs @@ -0,0 +1,91 @@ +// src/bin/gp_tester.rs + +use anyhow::{anyhow, bail, Result}; +use rand::{thread_rng, Rng}; + +// 1) We'll use the helper that reads creation code from a JSON artifact +use offchain::helpers::artifact::get_creation_code; + +// 2) EvmRunner to deploy & run the interpreter +use offchain::runner::revm_runner::EvmRunner; + +// 3) AST generation & mutation +use offchain::gp::generate::random_ast; +use offchain::gp::genetic_ops::mutated_ast; +use offchain::compiler::ast::UntypedAst; + +fn main() -> Result<()> { + // ---------------------------------------------------------------------- + // 1) Read the creation code (Push3Interpreter) using our helper function + // ---------------------------------------------------------------------- + let creation_hex_filename = "../onchain/out/Push3Interpreter.sol/Push3Interpreter.json"; + let creation_bytes = get_creation_code(creation_hex_filename)?; + println!( + "Loaded creation code from {} ({} bytes)", + creation_hex_filename, + creation_bytes.len() + ); + + // 2) Create the ephemeral EVM (deploy the contract) + let mut runner = EvmRunner::new(creation_bytes)?; + println!("Deployed test interpreter at: 0x{:x}\n", runner.interpreter_addr); + + // 3) We'll generate random ASTs & mutate them + let number_of_programs = 3; // how many random ASTs to try + let max_depth = 4; // max AST depth + let mut rng = thread_rng(); + + for i in 0..number_of_programs { + // a) Generate a random AST + let ast: UntypedAst = random_ast(&mut rng, 0, max_depth); + + println!("=== Program {} ===", i); + println!("Random AST:\n{:#?}", ast); + + // b) Run the original AST + match runner.run_ast(&ast) { + Ok(outputs) => { + println!("Original AST ran successfully!"); + println!("Final CODE stack: {:?}", outputs.final_code_stack); + println!("Final EXEC stack: {:?}", outputs.final_exec_stack); + println!("Final INT stack: {:?}", outputs.final_int_stack); + + // c) Mutate it a few times + let mutated1 = mutated_ast(&ast, &mut rng, 0, max_depth); + println!("\n-- MUTATED 1 --\n{:#?}", mutated1); + + match runner.run_ast(&mutated1) { + Ok(m1_out) => { + println!("MUTATED 1 ran successfully!"); + println!("Final INT stack: {:?}", m1_out.final_int_stack); + } + Err(e) => { + println!("MUTATED 1 error: {}", e); + } + } + + let mutated2 = mutated_ast(&ast, &mut rng, 0, max_depth); + println!("\n-- MUTATED 2 --\n{:#?}", mutated2); + + match runner.run_ast(&mutated2) { + Ok(m2_out) => { + println!("MUTATED 2 ran successfully!"); + println!("Final INT stack: {:?}", m2_out.final_int_stack); + } + Err(e) => { + println!("MUTATED 2 error: {}", e); + } + } + } + Err(e) => { + // If the original fails, we won't bother mutating it + println!("Original AST error: {}", e); + } + } + + println!("=== End of Program {} ===\n", i); + } + + println!("Finished running & mutating {} random programs.", number_of_programs); + Ok(()) +} diff --git a/offchain/src/gp/generate.rs b/offchain/src/gp/generate.rs new file mode 100644 index 0000000..11ed512 --- /dev/null +++ b/offchain/src/gp/generate.rs @@ -0,0 +1,79 @@ +use rand::Rng; +use crate::compiler::ast::{UntypedAst, OpCode}; + +pub fn random_sublist_ast(rng: &mut impl Rng, max_depth: usize) -> UntypedAst { + // 1) Choose how many children the top-level `Sublist` will have. + let len = rng.gen_range(1..=3); + + // 2) Build a vector of sub-ASTs by calling `random_ast` for each child + let mut children = Vec::with_capacity(len); + for _ in 0..len { + // We start at `depth=1` because the top-level sublist itself is `depth=0`. + children.push(random_ast(rng, 1, max_depth)); + } + + // 3) Return a `Sublist` as the root node + UntypedAst::Sublist(children) +} + +/// Generate a random `UntypedAst` by recursively building sub-trees, +/// int literals, or instructions. +/// +/// - `depth` tracks how deep we are in the tree. +/// - `max_depth` is the maximum allowed depth to prevent infinite recursion. +pub fn random_ast(rng: &mut impl Rng, depth: usize, max_depth: usize) -> UntypedAst { + if depth >= max_depth { + // Return something "terminal," + // e.g. an IntLiteral or a single Instruction + random_terminal(rng) + } else { + // Weighted choice: + // 0 => IntLiteral, + // 1 => single Instruction, + // 2 => Sublist with children + let choice = rng.gen_range(0..3); + match choice { + 0 => UntypedAst::IntLiteral(rng.gen_range(-10..10)), + 1 => UntypedAst::Instruction(random_opcode(rng)), + 2 => { + // Make a sublist with 1..=3 children + let len = rng.gen_range(1..=3); + let mut children = Vec::with_capacity(len); + for _ in 0..len { + children.push(random_ast(rng, depth + 1, max_depth)); + } + UntypedAst::Sublist(children) + } + _ => unreachable!(), + } + } +} + +/// Generate a random "terminal" node. +/// Typically either an int literal or a single instruction. +fn random_terminal(rng: &mut impl Rng) -> UntypedAst { + // Weighted choice: + // 0 => IntLiteral + // 1 => single Instruction + let choice = rng.gen_range(0..2); + match choice { + 0 => UntypedAst::IntLiteral(rng.gen_range(-10..10)), + 1 => UntypedAst::Instruction(random_opcode(rng)), + _ => unreachable!(), + } +} + +/// Generate a random `OpCode` from your known set of instructions. +pub fn random_opcode(rng: &mut impl Rng) -> OpCode { + let choice = rng.gen_range(0..6); + // because we have 6 variants: Noop, Plus, Minus, Mult, Dup, Pop + match choice { + 0 => OpCode::Noop, + 1 => OpCode::Plus, + 2 => OpCode::Minus, + 3 => OpCode::Mult, + 4 => OpCode::Dup, + 5 => OpCode::Pop, + _ => unreachable!(), + } +} diff --git a/offchain/src/gp/genetic_ops.rs b/offchain/src/gp/genetic_ops.rs index b5fb028..d204b2e 100644 --- a/offchain/src/gp/genetic_ops.rs +++ b/offchain/src/gp/genetic_ops.rs @@ -1,10 +1,64 @@ -// use crate::compiler::ast::{Expr}; +use rand::Rng; +use crate::compiler::ast::{UntypedAst, OpCode}; +use crate::gp::generate::{random_ast, random_opcode}; -// pub fn crossover(a: &Expr, b: &Expr) -> (Expr, Expr) { -// // stub -// (a.clone(), b.clone()) -// } +/// Returns a new `UntypedAst` that is a mutated version of `original`. +/// We do not modify `original`; we clone or build new pieces as needed. +/// +/// - `depth`: current depth of this node, +/// - `max_depth`: max allowed depth (to prevent infinite recursion). +pub fn mutated_ast(original: &UntypedAst, rng: &mut impl Rng, depth: usize, max_depth: usize) -> UntypedAst { + // 10% chance: completely replace this node with a fresh random subtree + if rng.gen_range(0..100) < 10 { + return random_ast(rng, depth, max_depth); + } -// pub fn mutate(expr: &mut Expr) { -// // stub -// } + match original { + UntypedAst::IntLiteral(val) => { + // Another small chance to replace the entire node with random subtree + if rng.gen_range(0..100) < 10 { + return random_ast(rng, depth, max_depth); + } + + // Otherwise, "tweak" the int by a small offset + let delta = rng.gen_range(-2..=2); + let new_val = val.saturating_add(delta); + UntypedAst::IntLiteral(new_val) + } + UntypedAst::Instruction(op) => { + // 10% chance to replace node + if rng.gen_range(0..100) < 10 { + return random_ast(rng, depth, max_depth); + } + + // 50% chance to pick a new opcode + // or else keep the same + if rng.gen_bool(0.5) { + UntypedAst::Instruction(random_opcode(rng)) + } else { + // Just clone the original + UntypedAst::Instruction(op.clone()) + } + } + UntypedAst::Sublist(children) => { + // 10% chance to replace this sublist entirely + if rng.gen_range(0..100) < 10 { + return random_ast(rng, depth, max_depth); + } + + // Otherwise, mutate zero or more children + let mut new_children = children.clone(); + if !new_children.is_empty() { + // Choose how many kids to mutate: + // e.g., 1..=min(2, children.len()) + let mut_count = rng.gen_range(1..=new_children.len().min(2)); + + for _ in 0..mut_count { + let idx = rng.gen_range(0..new_children.len()); + new_children[idx] = mutated_ast(&new_children[idx], rng, depth+1, max_depth); + } + } + UntypedAst::Sublist(new_children) + } + } +} diff --git a/offchain/src/gp/mod.rs b/offchain/src/gp/mod.rs index 12178cb..3681485 100644 --- a/offchain/src/gp/mod.rs +++ b/offchain/src/gp/mod.rs @@ -1,13 +1,3 @@ pub mod population; pub mod genetic_ops; -// pub mod fitness; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_dummy() { - assert_eq!(2+2, 4); - } -} +pub mod generate; diff --git a/offchain/src/helpers/artifact.rs b/offchain/src/helpers/artifact.rs new file mode 100644 index 0000000..444710f --- /dev/null +++ b/offchain/src/helpers/artifact.rs @@ -0,0 +1,41 @@ +//! src/helpers/artifact.rs +//! A small helper module to read a Forge artifact JSON and extract the creation code. + +use anyhow::{anyhow, bail, Result}; +use serde::Deserialize; +use std::fs; + +/// This mirrors the JSON structure: "bytecode": { "object": "...hex..." } +#[derive(Debug, Deserialize)] +struct BytecodeObject { + object: String, +} + +/// The top-level artifact with a "bytecode" field. +#[derive(Debug, Deserialize)] +struct MyContractArtifact { + bytecode: BytecodeObject, +} + +/// Reads the given JSON file (a Forge artifact) and returns the raw creation code bytes. +/// +/// * `filename`: path to the artifact JSON (e.g. `../onchain/out/Push3Interpreter.sol/Push3Interpreter.json`) +pub fn get_creation_code(filename: &str) -> Result> { + // 1) Read the JSON file + let creation_json = fs::read_to_string(filename) + .map_err(|e| anyhow!("Failed to read JSON file {}: {}", filename, e))?; + + // 2) Parse + let contract_artifact: MyContractArtifact = serde_json::from_str(&creation_json) + .map_err(|e| anyhow!("Failed to parse JSON artifact: {}", e))?; + + // 3) Extract the hex code + let raw_hex = &contract_artifact.bytecode.object; + let stripped_hex = raw_hex.trim_start_matches("0x"); + + // 4) Convert from hex => bytes + match hex::decode(stripped_hex) { + Ok(bytes) => Ok(bytes), + Err(e) => bail!("Invalid hex for creation code: {e}"), + } +} diff --git a/offchain/src/helpers/mod.rs b/offchain/src/helpers/mod.rs new file mode 100644 index 0000000..3ee85ee --- /dev/null +++ b/offchain/src/helpers/mod.rs @@ -0,0 +1 @@ +pub mod artifact; diff --git a/offchain/src/lib.rs b/offchain/src/lib.rs new file mode 100644 index 0000000..f969342 --- /dev/null +++ b/offchain/src/lib.rs @@ -0,0 +1,4 @@ +pub mod compiler; +pub mod runner; +pub mod gp; +pub mod helpers; diff --git a/offchain/src/main.rs b/offchain/src/main.rs index 90e1460..7c093f6 100644 --- a/offchain/src/main.rs +++ b/offchain/src/main.rs @@ -1,19 +1,15 @@ // src/main.rs - -mod compiler; -mod runner; - use std::env; // We’ll use your existing AST definitions for parsing -use compiler::ast::{ +use offchain::compiler::ast::{ parse_string_to_sexpr, sexpr_to_untyped, Push3Ast, // The trait UntypedAst, // The untyped AST enum }; -use runner::revm_runner::{EvmRunner, Push3InterpreterOutputs}; // <--- We import our EvmRunner +use offchain::runner::revm_runner::{EvmRunner, Push3InterpreterOutputs}; // <--- We import our EvmRunner use anyhow::{anyhow, bail, Result}; use hex; diff --git a/offchain/src/runner/revm_runner.rs b/offchain/src/runner/revm_runner.rs index fe97a21..5047d78 100644 --- a/offchain/src/runner/revm_runner.rs +++ b/offchain/src/runner/revm_runner.rs @@ -146,7 +146,7 @@ impl EvmRunner { self.evm.context.modify_tx(|tx| { tx.transact_to = TxKind::Call(self.interpreter_addr); tx.data = Bytes::from(call_data); - tx.nonce += 1; // increment nonce to avoid reuse + tx.nonce = 1; // increment nonce to avoid reuse }); // 6) Execute the call -- 2.34.1 From 64a81e41104d71b3a7e89cb566a8bf7b32bd2849 Mon Sep 17 00:00:00 2001 From: zjkree Date: Tue, 14 Jan 2025 05:22:08 +0100 Subject: [PATCH 08/10] Add symbolic regression experiment. --- offchain/Cargo.toml | 8 ++ offchain/src/bin/gp_spec_tester.rs | 36 ++++++ offchain/src/bin/symreg_experiment.rs | 170 ++++++++++++++++++++++++++ offchain/src/gp/generate_spec.rs | 121 ++++++++++++++++++ offchain/src/gp/mod.rs | 2 + offchain/src/gp/mutation.rs | 86 +++++++++++++ 6 files changed, 423 insertions(+) create mode 100644 offchain/src/bin/gp_spec_tester.rs create mode 100644 offchain/src/bin/symreg_experiment.rs create mode 100644 offchain/src/gp/generate_spec.rs create mode 100644 offchain/src/gp/mutation.rs diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index 03796d0..62a6f91 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -7,6 +7,14 @@ edition = "2021" name = "gp_tester" path = "src/bin/gp_tester.rs" +[[bin]] +name = "gp_spec_tester" +path = "src/bin/gp_spec_tester.rs" + +[[bin]] +name = "symreg_experiment" +path = "src/bin/symreg_experiment.rs" + [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/offchain/src/bin/gp_spec_tester.rs b/offchain/src/bin/gp_spec_tester.rs new file mode 100644 index 0000000..b579b3b --- /dev/null +++ b/offchain/src/bin/gp_spec_tester.rs @@ -0,0 +1,36 @@ +use anyhow::Result; +use rand::thread_rng; +use rand::Rng; + +// Suppose you have these in your library: +use offchain::gp::generate_spec::ranmdom_code_fixed; +use offchain::gp::mutation::mutate_by_index; +use offchain::compiler::ast::UntypedAst; + +fn main() -> Result<()> { + let mut rng = thread_rng(); + + // We'll produce, say, 3 random ASTs ("subjects"). + let num_subjects = 3; + let max_points = 6; + + for i in 0..num_subjects { + // Generate a random AST + let original = ranmdom_code_fixed(&mut rng, max_points); + println!("=== Subject #{} ===", i); + println!("Original AST:\n{:#?}", original); + + // Let's do 2 successive mutations on it + let mut prev = original.clone(); + for mut_idx in 0..2 { + let mutated = mutate_by_index(&prev, &mut rng, max_points); + println!("Mutation #{} result:\n{:#?}", mut_idx, mutated); + prev = mutated; // so the next iteration mutates from the last result + } + + println!("=== End of Subject #{} ===\n", i); + } + + println!("Done generating & mutating random ASTs!"); + Ok(()) +} diff --git a/offchain/src/bin/symreg_experiment.rs b/offchain/src/bin/symreg_experiment.rs new file mode 100644 index 0000000..116c4e7 --- /dev/null +++ b/offchain/src/bin/symreg_experiment.rs @@ -0,0 +1,170 @@ +// src/bin/symreg_experiment.rs + +use anyhow::Result; +use rand::{thread_rng, Rng}; +use offchain::compiler::ast::{UntypedAst, Push3Ast}; +use offchain::helpers::artifact::get_creation_code; +use offchain::runner::revm_runner::{ + EvmRunner, + Push3InterpreterInputs, + Push3InterpreterOutputs +}; +use offchain::gp::generate_spec::{ranmdom_code_fixed}; +use offchain::gp::mutation::mutate_by_index; +use offchain::compiler::push3_describtor::make_sublist_descriptor; +use ethers::types::U256; +use ethers::abi::{encode, Token}; + +// 1) Generate (x, y) samples for f(x) = 3x^2 + x + 3 +fn generate_samples() -> Vec<(i32, i32)> { + let mut samples = Vec::new(); + for x in -5..=5 { + let y = 3 * x * x + x + 3; + samples.push((x, y)); + } + samples +} + +// 2) Evaluate a single AST on a single input `x`, returning the integer +// that ends up on top of the final int stack (or 0 if empty). +fn evaluate_ast_on_x( + runner: &mut EvmRunner, + ast: &UntypedAst, + x: i32, +) -> i32 { + // a) Convert AST => push3 bytecode + let code_bytes = ast.to_bytecode(); + let code_len = code_bytes.len() as u32; + + // b) Build a sublist descriptor + let descriptor = make_sublist_descriptor(0, code_len); + + // c) Provide x in `init_int_stack` + let inputs = Push3InterpreterInputs { + code: code_bytes, + init_code_stack: Vec::new(), + init_exec_stack: vec![descriptor], + init_int_stack: vec![x as i128], + }; + + // d) Actually run the interpreter + let outputs = match runner.run_interpreter(&inputs) { + Ok(o) => o, + Err(_) => { + // If the call fails or reverts, return 0 + return 0; + } + }; + + // e) If final_int_stack is empty => 0, else top item + if outputs.final_int_stack.is_empty() { + 0 + } else { + *outputs.final_int_stack.last().unwrap() as i32 + } +} + +// 3) Evaluate an AST on all (x, y) samples => compute MSE +fn evaluate_fitness( + runner: &mut EvmRunner, + ast: &UntypedAst, + samples: &[(i32, i32)] +) -> f64 { + let mut error_sum = 0.0; + for &(x, target_y) in samples { + let predicted = evaluate_ast_on_x(runner, ast, x); + let diff = (predicted - target_y) as f64; + error_sum += diff * diff; + } + error_sum / samples.len() as f64 +} + +fn main() -> Result<()> { + // A) Generate samples for f(x)=3x^2 + x + 3 + let samples = generate_samples(); + + // B) Create an ephemeral EVM runner (Push3Interpreter) + let creation_hex_filename = "../onchain/out/Push3Interpreter.sol/Push3Interpreter.json"; + let creation_bytes = get_creation_code(creation_hex_filename)?; + let mut runner = EvmRunner::new(creation_bytes)?; + + // C) Setup GP parameters + let pop_size = 1000; // population size + let max_points = 15; // max "size" for random code + let generations = 100; // how many generations we run + let early_stop_threshold = 1.0; // if error < this => we can stop + + let mut rng = thread_rng(); + + // D) Initialize random population + let mut population: Vec = (0..pop_size) + .map(|_| ranmdom_code_fixed(&mut rng, max_points)) + .collect(); + + // E) Main GP Loop + for gen in 0..generations { + // 1) Evaluate each => store (ast, error) + let mut scored: Vec<(UntypedAst, f64)> = population.into_iter() + .map(|ast| { + let err = evaluate_fitness(&mut runner, &ast, &samples); + (ast, err) + }) + .collect(); + + // 2) Sort ascending by error + scored.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); + + // 3) Print best error + let best_err = scored[0].1; + println!("Generation {gen}, best error = {best_err}"); + + // 4) Check if best is below threshold => early stop + if best_err < early_stop_threshold { + println!("Best error < {early_stop_threshold}, stopping early!"); + population = scored.into_iter().map(|(a, _)| a).collect(); + break; + } + + // 5) Keep best half + let half = scored.len() / 2; + let survivors = &scored[..half]; + + // 6) Refill population: half mutated, half fresh random + let mut new_pop = Vec::with_capacity(scored.len()); + // a) keep survivors + for &(ref ast, _) in survivors { + new_pop.push(ast.clone()); + } + + // b) how many to add? + let remainder_size = pop_size - new_pop.len(); + // we do half mutated, half new random + let mutated_count = remainder_size / 2; + let random_count = remainder_size - mutated_count; + + // c) add mutated + for _ in 0..mutated_count { + let idx = rng.gen_range(0..half); + let mutated = mutate_by_index(&survivors[idx].0, &mut rng, max_points); + new_pop.push(mutated); + } + + // d) add brand-new random + for _ in 0..random_count { + let fresh = ranmdom_code_fixed(&mut rng, max_points); + new_pop.push(fresh); + } + + // store for next generation + population = new_pop; + } + + // F) Final Print + println!("\n=== Final Population ==="); + for (i, ast) in population.iter().enumerate() { + let err = evaluate_fitness(&mut runner, ast, &samples); + println!("Subject #{i}, err={err}, ast={:?}", ast); + } + + Ok(()) +} diff --git a/offchain/src/gp/generate_spec.rs b/offchain/src/gp/generate_spec.rs new file mode 100644 index 0000000..15a2100 --- /dev/null +++ b/offchain/src/gp/generate_spec.rs @@ -0,0 +1,121 @@ +use crate::compiler::ast::{UntypedAst, OpCode}; +use rand::Rng; +use rand::prelude::SliceRandom; + +#[derive(Clone, Debug)] +pub enum InstructionAtom { + /// A normal opcode, e.g. `Plus`, `Minus`, `Dup`, etc. + Opcode(OpCode), + /// An ephemeral random constant placeholder. + /// If chosen, we generate a random literal on the spot. + EphemeralInt, + // If you want ephemeral floats, booleans, etc., add more variants +} + +/// A small struct to hold our entire “instruction set.” +#[derive(Clone, Debug)] +pub struct InstructionSet { + pub atoms: Vec, +} + +impl InstructionSet { + pub fn new_default() -> Self { + // Example: Some opcodes + ephemeral constant + // Tweak as you like + use InstructionAtom::*; + use OpCode::*; + + Self { + atoms: vec![ + Opcode(Noop), + Opcode(Plus), + Opcode(Minus), + Opcode(Mult), + Opcode(Dup), + Opcode(Pop), + EphemeralInt, + ], + } + } + + /// Pick a random atom from this set. + /// If it's `EphemeralInt`, we produce `UntypedAst::IntLiteral(...)`. + /// If it's `Opcode(...)`, we produce `UntypedAst::Instruction(...)`. + pub fn random_atom_as_ast(&self, rng: &mut impl Rng) -> UntypedAst { + let idx = rng.gen_range(0..self.atoms.len()); + match &self.atoms[idx] { + InstructionAtom::Opcode(op) => UntypedAst::Instruction(op.clone()), + InstructionAtom::EphemeralInt => { + // For ephemeral int, produce a random literal in some range + let val = rng.gen_range(-10..10); + UntypedAst::IntLiteral(val) + } + } + } +} + +pub fn ranmdom_code_fixed(rng: &mut impl Rng, max_points: usize) -> UntypedAst { + let instr_set = InstructionSet::new_default(); + return random_code(rng, &instr_set, max_points); +} + +/// The "entry point": random_code(max_points). +/// 1) Choose actual_points in [1..=max_points]. +/// 2) Return the result of random_code_with_size. +pub fn random_code(rng: &mut impl Rng, instr_set: &InstructionSet, max_points: usize) -> UntypedAst { + let actual_points = rng.gen_range(1..=max_points); + random_code_with_size(rng, instr_set, actual_points) +} + +/// The main logic: +/// If points == 1 => pick a single instruction/ephemeral +/// Else => +/// - We "decompose" (points - 1) among sub-codes +/// - For each sub-points, we recursively call random_code_with_size +/// - We return a Sublist of those children, possibly in random order +pub fn random_code_with_size( + rng: &mut impl Rng, + instr_set: &InstructionSet, + points: usize, +) -> UntypedAst { + use UntypedAst::*; + + // Base case + if points == 1 { + // Choose a random "atom" from instr_set + return instr_set.random_atom_as_ast(rng); + } + + // If `points > 1`, let's produce a Sublist + // We'll break (points - 1) into sub-points via `decompose` + let subpoints_list = decompose(rng, points - 1, points - 1); + // subpoints_list is e.g. [2, 3, 5] and sums to (points-1) + + // Then for each "subpoints", we do random_code_with_size + let mut sub_asts: Vec = subpoints_list + .into_iter() + .map(|sp| random_code_with_size(rng, instr_set, sp)) + .collect(); + + // The spec says "Return a list containing the results, in random order" + // so let's shuffle sub_asts + sub_asts.shuffle(rng); + + Sublist(sub_asts) +} + +/// Decompose a number into random parts. +/// +/// - If number is 1 or max_parts is 1 => return [number]. +/// - Otherwise pick a random split "this_part" and recurse on the remainder. +fn decompose(rng: &mut impl Rng, number: usize, max_parts: usize) -> Vec { + if number == 1 || max_parts == 1 { + return vec![number]; + } + // pick a random "this_part" in [1 .. (number-1)] + let this_part = rng.gen_range(1..number); + let mut remainder = decompose(rng, number - this_part, max_parts - 1); + let mut result = vec![this_part]; + result.append(&mut remainder); + result +} diff --git a/offchain/src/gp/mod.rs b/offchain/src/gp/mod.rs index 3681485..3b107c3 100644 --- a/offchain/src/gp/mod.rs +++ b/offchain/src/gp/mod.rs @@ -1,3 +1,5 @@ pub mod population; pub mod genetic_ops; pub mod generate; +pub mod generate_spec; +pub mod mutation; diff --git a/offchain/src/gp/mutation.rs b/offchain/src/gp/mutation.rs new file mode 100644 index 0000000..0b02133 --- /dev/null +++ b/offchain/src/gp/mutation.rs @@ -0,0 +1,86 @@ +use rand::Rng; +use crate::compiler::ast::UntypedAst; +use crate::gp::generate_spec::ranmdom_code_fixed; // or push3-based generator + +/// A "path" is a list of indices leading from the root to a child. +/// For example, [] is the root, [0] is the root's first child, [0,1] is that child's second child, etc. +pub type Path = Vec; + +/// Enumerate all nodes in a DFS order (root first). +/// For each node, we store the `Path` (list of child indices). +pub fn enum_nodes_dfs(ast: &UntypedAst) -> Vec { + let mut paths = Vec::new(); + dfs_helper(ast, &mut paths, &mut vec![]); + paths +} + +/// Recursive helper: `current_path` is a stack we push child indices onto. +/// `paths` is the global list of final results. +fn dfs_helper(ast: &UntypedAst, paths: &mut Vec, current_path: &mut Vec) { + // Record the current path as a valid node + paths.push(current_path.clone()); + + match ast { + UntypedAst::Sublist(children) => { + // For each child, push its index, recurse, then pop + for (i, child) in children.iter().enumerate() { + current_path.push(i); + dfs_helper(child, paths, current_path); + current_path.pop(); + } + } + UntypedAst::IntLiteral(_) | UntypedAst::Instruction(_) => { + // Leaf node => no children + } + } +} + +/// Replace the node at `path` in `original` with `replacement`, returning a new AST. +/// If `path` is empty => we replace the root entirely. +pub fn replace_subtree( + original: &UntypedAst, + path: &[usize], + replacement: UntypedAst +) -> UntypedAst { + if path.is_empty() { + // means we’re replacing the root + return replacement; + } + // otherwise, we need to walk the sublist chain + match original { + UntypedAst::Sublist(children) => { + // let path_head = path[0], path_tail = path[1..] + let (first_idx, tail_path) = (path[0], &path[1..]); + let mut new_children = children.clone(); + new_children[first_idx] = replace_subtree(&children[first_idx], tail_path, replacement); + UntypedAst::Sublist(new_children) + } + // If the path is not empty but we’re not in a Sublist => error or do nothing + UntypedAst::IntLiteral(_) | UntypedAst::Instruction(_) => { + // Possibly, if the path is invalid, we ignore. Or we treat it as "replace anyway." + // Here, we might treat it as an error or a no-op. + original.clone() + } + } +} + +/// Produces a new AST by choosing exactly one node in `original` at random +/// (by enumerating them), and replacing it with a new random subtree. +pub fn mutate_by_index( + original: &UntypedAst, + rng: &mut impl Rng, + max_points: usize, +) -> UntypedAst { + // 1) Enumerate all nodes => get a vector of `Path` + let all_paths = enum_nodes_dfs(original); + // pick a random path + let idx = rng.gen_range(0..all_paths.len()); + let chosen_path = &all_paths[idx]; + + // 2) Generate a new subtree with our "fixed" random code generator + let new_subtree = ranmdom_code_fixed(rng, max_points); + + // 3) Replace the subtree at `chosen_path` in `original` with `new_subtree` + replace_subtree(original, chosen_path, new_subtree) +} + -- 2.34.1 From eeb5dd4141d3cc843cdf6358178d4c20a60c30c9 Mon Sep 17 00:00:00 2001 From: zjkree Date: Tue, 14 Jan 2025 05:48:42 +0100 Subject: [PATCH 09/10] Some modifications to the regression experiment. --- offchain/src/bin/symreg_experiment.rs | 123 ++++++++++++++++---------- offchain/src/gp/generate_spec.rs | 2 +- offchain/src/gp/mutation.rs | 61 +++++++++++++ 3 files changed, 137 insertions(+), 49 deletions(-) diff --git a/offchain/src/bin/symreg_experiment.rs b/offchain/src/bin/symreg_experiment.rs index 116c4e7..dd57de5 100644 --- a/offchain/src/bin/symreg_experiment.rs +++ b/offchain/src/bin/symreg_experiment.rs @@ -2,20 +2,25 @@ use anyhow::Result; use rand::{thread_rng, Rng}; + +// Our GP + compiler modules (adjust paths as needed) use offchain::compiler::ast::{UntypedAst, Push3Ast}; use offchain::helpers::artifact::get_creation_code; use offchain::runner::revm_runner::{ EvmRunner, - Push3InterpreterInputs, - Push3InterpreterOutputs + Push3InterpreterInputs, }; -use offchain::gp::generate_spec::{ranmdom_code_fixed}; -use offchain::gp::mutation::mutate_by_index; use offchain::compiler::push3_describtor::make_sublist_descriptor; + +// Our GP operators +use offchain::gp::generate_spec::ranmdom_code_fixed; +use offchain::gp::mutation::{mutate_by_index, crossover_by_index}; + +// Ethers + ABI use ethers::types::U256; use ethers::abi::{encode, Token}; -// 1) Generate (x, y) samples for f(x) = 3x^2 + x + 3 +/// 1) Generate (x, y) samples for f(x)=3x^2 + x + 3 fn generate_samples() -> Vec<(i32, i32)> { let mut samples = Vec::new(); for x in -5..=5 { @@ -25,8 +30,9 @@ fn generate_samples() -> Vec<(i32, i32)> { samples } -// 2) Evaluate a single AST on a single input `x`, returning the integer -// that ends up on top of the final int stack (or 0 if empty). +/// 2) Evaluate a single AST on a single input `x` by +/// pushing `x` onto the int stack, running in EVM, +/// and reading the final top of the int stack. fn evaluate_ast_on_x( runner: &mut EvmRunner, ast: &UntypedAst, @@ -64,7 +70,7 @@ fn evaluate_ast_on_x( } } -// 3) Evaluate an AST on all (x, y) samples => compute MSE +/// 3) Evaluate an AST on all (x, y) samples => compute MSE fn evaluate_fitness( runner: &mut EvmRunner, ast: &UntypedAst, @@ -80,30 +86,33 @@ fn evaluate_fitness( } fn main() -> Result<()> { - // A) Generate samples for f(x)=3x^2 + x + 3 + // 1) Generate samples for f(x)=3x^2 + x + 3 let samples = generate_samples(); - // B) Create an ephemeral EVM runner (Push3Interpreter) + // 2) Create ephemeral EVM runner for the interpreter let creation_hex_filename = "../onchain/out/Push3Interpreter.sol/Push3Interpreter.json"; let creation_bytes = get_creation_code(creation_hex_filename)?; let mut runner = EvmRunner::new(creation_bytes)?; - // C) Setup GP parameters - let pop_size = 1000; // population size - let max_points = 15; // max "size" for random code - let generations = 100; // how many generations we run - let early_stop_threshold = 1.0; // if error < this => we can stop + // 3) GP parameters + let pop_size = 1000; // must be divisible by 4 for our scheme + let generations = 30; + let early_stop_threshold = 1.0; + let max_points = 15; + + assert_eq!(pop_size % 4, 0, "pop_size must be multiple of 4 for our scheme"); + let quarter = pop_size / 4; let mut rng = thread_rng(); - // D) Initialize random population + // 4) Initialize population (random) let mut population: Vec = (0..pop_size) .map(|_| ranmdom_code_fixed(&mut rng, max_points)) .collect(); - // E) Main GP Loop + // 5) Main GP loop for gen in 0..generations { - // 1) Evaluate each => store (ast, error) + // (a) Evaluate let mut scored: Vec<(UntypedAst, f64)> = population.into_iter() .map(|ast| { let err = evaluate_fitness(&mut runner, &ast, &samples); @@ -111,59 +120,77 @@ fn main() -> Result<()> { }) .collect(); - // 2) Sort ascending by error + // (b) Sort ascending by error scored.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); - // 3) Print best error + // (c) Print generation summary let best_err = scored[0].1; - println!("Generation {gen}, best error = {best_err}"); + println!("\n=== Generation {gen} ==="); + println!("Best error = {best_err}"); - // 4) Check if best is below threshold => early stop + // Print top 5 subjects in pretty format + let top_n = 5.min(scored.len()); + println!("Top {top_n} subjects:"); + for i in 0..top_n { + println!( + " #{i}, err={}, AST:\n{:#?}", + scored[i].1, + scored[i].0 + ); + } + + // early stop? if best_err < early_stop_threshold { println!("Best error < {early_stop_threshold}, stopping early!"); + // we can keep 'scored' for final if we want population = scored.into_iter().map(|(a, _)| a).collect(); break; } - // 5) Keep best half - let half = scored.len() / 2; - let survivors = &scored[..half]; + // (d) Reproduction => build new population + let mut new_pop = Vec::with_capacity(pop_size); - // 6) Refill population: half mutated, half fresh random - let mut new_pop = Vec::with_capacity(scored.len()); - // a) keep survivors - for &(ref ast, _) in survivors { - new_pop.push(ast.clone()); + // keep best quarter + for i in 0..quarter { + new_pop.push(scored[i].0.clone()); } - // b) how many to add? - let remainder_size = pop_size - new_pop.len(); - // we do half mutated, half new random - let mutated_count = remainder_size / 2; - let random_count = remainder_size - mutated_count; - - // c) add mutated - for _ in 0..mutated_count { - let idx = rng.gen_range(0..half); - let mutated = mutate_by_index(&survivors[idx].0, &mut rng, max_points); - new_pop.push(mutated); - } - - // d) add brand-new random - for _ in 0..random_count { + // add random quarter + for _ in 0..quarter { let fresh = ranmdom_code_fixed(&mut rng, max_points); new_pop.push(fresh); } - // store for next generation + // crossover quarter + let top_half_count = scored.len() / 2; + let crossover_pairs = quarter / 2; // each yields 2 kids => quarter total + for _ in 0..crossover_pairs { + let idx1 = rng.gen_range(0..top_half_count); + let idx2 = rng.gen_range(0..top_half_count); + let (child1, child2) = crossover_by_index( + &scored[idx1].0, + &scored[idx2].0, + &mut rng + ); + new_pop.push(child1); + new_pop.push(child2); + } + + // mutate quarter + while new_pop.len() < pop_size { + let idx = rng.gen_range(0..top_half_count); + let mutated = mutate_by_index(&scored[idx].0, &mut rng, max_points); + new_pop.push(mutated); + } + population = new_pop; } - // F) Final Print + // 6) Final population => we can evaluate & print println!("\n=== Final Population ==="); for (i, ast) in population.iter().enumerate() { let err = evaluate_fitness(&mut runner, ast, &samples); - println!("Subject #{i}, err={err}, ast={:?}", ast); + println!("Subject #{i}, err={err}, AST:\n{:#?}", ast); } Ok(()) diff --git a/offchain/src/gp/generate_spec.rs b/offchain/src/gp/generate_spec.rs index 15a2100..3004403 100644 --- a/offchain/src/gp/generate_spec.rs +++ b/offchain/src/gp/generate_spec.rs @@ -47,7 +47,7 @@ impl InstructionSet { InstructionAtom::Opcode(op) => UntypedAst::Instruction(op.clone()), InstructionAtom::EphemeralInt => { // For ephemeral int, produce a random literal in some range - let val = rng.gen_range(-10..10); + let val = rng.gen_range(-100..100); UntypedAst::IntLiteral(val) } } diff --git a/offchain/src/gp/mutation.rs b/offchain/src/gp/mutation.rs index 0b02133..2e15996 100644 --- a/offchain/src/gp/mutation.rs +++ b/offchain/src/gp/mutation.rs @@ -84,3 +84,64 @@ pub fn mutate_by_index( replace_subtree(original, chosen_path, new_subtree) } +/// Return the subtree of `original` at `path`, +/// cloning it as a `UntypedAst`. +/// If `path` is empty => returns the entire `original`. +pub fn get_subtree(original: &UntypedAst, path: &[usize]) -> UntypedAst { + if path.is_empty() { + // The entire AST is the subtree + return original.clone(); + } + + match original { + UntypedAst::Sublist(children) => { + let (first_idx, tail_path) = (path[0], &path[1..]); + if first_idx >= children.len() { + // If path index is out of range, just clone the entire AST or + // do something fallback + return original.clone(); + } + get_subtree(&children[first_idx], tail_path) + } + UntypedAst::IntLiteral(_) | UntypedAst::Instruction(_) => { + // If path is non-empty but this is a leaf, + // fallback: just return the leaf. + original.clone() + } + } +} + +/// Perform a subtree crossover between two ASTs. +/// 1) We pick a random node in `a` and a random node in `b`, +/// 2) We swap those subtrees, +/// 3) Return the two new ASTs. +/// +/// Example usage: +/// ```rust +/// let (childA, childB) = crossover_by_index(&parentA, &parentB, &mut rng); +/// ``` +pub fn crossover_by_index( + a: &UntypedAst, + b: &UntypedAst, + rng: &mut impl Rng, +) -> (UntypedAst, UntypedAst) { + // 1) enumerate nodes in a + let paths_a = enum_nodes_dfs(a); + let idx_a = rng.gen_range(0..paths_a.len()); + let chosen_a = &paths_a[idx_a]; + + // 2) enumerate nodes in b + let paths_b = enum_nodes_dfs(b); + let idx_b = rng.gen_range(0..paths_b.len()); + let chosen_b = &paths_b[idx_b]; + + // 3) get subtree from a, from b + let subtree_a = get_subtree(a, chosen_a); + let subtree_b = get_subtree(b, chosen_b); + + // 4) replace them + let new_a = replace_subtree(a, chosen_a, subtree_b); + let new_b = replace_subtree(b, chosen_b, subtree_a); + + (new_a, new_b) +} -- 2.34.1 From c2343edc6bed5a60061ba318a8f91bdcdc1fb658 Mon Sep 17 00:00:00 2001 From: zjkree Date: Tue, 21 Jan 2025 08:59:21 +0100 Subject: [PATCH 10/10] Add more local mutation --- offchain/Cargo.toml | 4 + offchain/src/bin/symreg_experiment.rs | 72 ++++--- offchain/src/bin/symreg_experiment_local.rs | 202 ++++++++++++++++++++ offchain/src/gp/generate_spec.rs | 2 +- offchain/src/gp/local_mutation.rs | 114 +++++++++++ offchain/src/gp/mod.rs | 1 + 6 files changed, 371 insertions(+), 24 deletions(-) create mode 100644 offchain/src/bin/symreg_experiment_local.rs create mode 100644 offchain/src/gp/local_mutation.rs diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index 62a6f91..561dd5a 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -15,6 +15,10 @@ path = "src/bin/gp_spec_tester.rs" name = "symreg_experiment" path = "src/bin/symreg_experiment.rs" +[[bin]] +name = "symreg_experiment_local" +path = "src/bin/symreg_experiment_local.rs" + [dependencies] serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/offchain/src/bin/symreg_experiment.rs b/offchain/src/bin/symreg_experiment.rs index dd57de5..1c7e1b9 100644 --- a/offchain/src/bin/symreg_experiment.rs +++ b/offchain/src/bin/symreg_experiment.rs @@ -64,7 +64,7 @@ fn evaluate_ast_on_x( // e) If final_int_stack is empty => 0, else top item if outputs.final_int_stack.is_empty() { - 0 + i32::MAX } else { *outputs.final_int_stack.last().unwrap() as i32 } @@ -77,14 +77,22 @@ fn evaluate_fitness( samples: &[(i32, i32)] ) -> f64 { let mut error_sum = 0.0; - for &(x, target_y) in samples { - let predicted = evaluate_ast_on_x(runner, ast, x); - let diff = (predicted - target_y) as f64; - error_sum += diff * diff; + for &(x, target_y32) in samples { + // cast to i64 + let target_y = target_y32 as i64; + + // evaluate in i64 as well + let predicted_i64 = evaluate_ast_on_x(runner, ast, x) as i64; + + let diff = predicted_i64.wrapping_sub(target_y); + // or you could saturating_sub if you prefer + + error_sum += (diff as f64) * (diff as f64); } error_sum / samples.len() as f64 } + fn main() -> Result<()> { // 1) Generate samples for f(x)=3x^2 + x + 3 let samples = generate_samples(); @@ -95,10 +103,10 @@ fn main() -> Result<()> { let mut runner = EvmRunner::new(creation_bytes)?; // 3) GP parameters - let pop_size = 1000; // must be divisible by 4 for our scheme - let generations = 30; + let pop_size = 4000; // must be divisible by 4 for our scheme + let generations = 100; let early_stop_threshold = 1.0; - let max_points = 15; + let max_points = 20; assert_eq!(pop_size % 4, 0, "pop_size must be multiple of 4 for our scheme"); let quarter = pop_size / 4; @@ -129,15 +137,15 @@ fn main() -> Result<()> { println!("Best error = {best_err}"); // Print top 5 subjects in pretty format - let top_n = 5.min(scored.len()); - println!("Top {top_n} subjects:"); - for i in 0..top_n { - println!( - " #{i}, err={}, AST:\n{:#?}", - scored[i].1, - scored[i].0 - ); - } + // let top_n = 5.min(scored.len()); + // println!("Top {top_n} subjects:"); + // for i in 0..top_n { + // println!( + // " #{i}, err={}, AST:\n{:#?}", + // scored[i].1, + // scored[i].0 + // ); + // } // early stop? if best_err < early_stop_threshold { @@ -186,12 +194,30 @@ fn main() -> Result<()> { population = new_pop; } - // 6) Final population => we can evaluate & print - println!("\n=== Final Population ==="); - for (i, ast) in population.iter().enumerate() { - let err = evaluate_fitness(&mut runner, ast, &samples); - println!("Subject #{i}, err={err}, AST:\n{:#?}", ast); - } + // 6) Final population => evaluate & sort, then print only top 10 + println!("\n=== Final Population (Top 10) ==="); + // a) Evaluate each item in the final population + let mut final_scored: Vec<(UntypedAst, f64)> = population + .into_iter() + .map(|ast| { + let err = evaluate_fitness(&mut runner, &ast, &samples); + (ast, err) + }) + .collect(); + + // b) Sort ascending by error + final_scored.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); + + // c) Print the top 10 (or fewer if the population is smaller) + let top_n = 10.min(final_scored.len()); + for i in 0..top_n { + let (ref ast, err) = final_scored[i]; + println!( + "Subject #{i}, err={err}, AST:\n{:#?}", + ast + ); + } + Ok(()) } diff --git a/offchain/src/bin/symreg_experiment_local.rs b/offchain/src/bin/symreg_experiment_local.rs new file mode 100644 index 0000000..58df871 --- /dev/null +++ b/offchain/src/bin/symreg_experiment_local.rs @@ -0,0 +1,202 @@ +// src/bin/symreg_experiment_local.rs + +use anyhow::Result; +use rand::{thread_rng, Rng}; + +// Our GP + compiler modules (adjust paths if needed) +use offchain::compiler::ast::{UntypedAst, Push3Ast}; +use offchain::helpers::artifact::get_creation_code; +use offchain::runner::revm_runner::{EvmRunner, Push3InterpreterInputs}; +use offchain::compiler::push3_describtor::make_sublist_descriptor; + +// Our random code and local mutation +use offchain::gp::generate_spec::ranmdom_code_fixed; +use offchain::gp::local_mutation::local_mutation_fixed; + +// Ethers + ABI +use ethers::types::U256; +use ethers::abi::{encode, Token}; + +/// 1) Generate (x, y) samples for f(x) = 3x^2 + x + 3 +fn generate_samples() -> Vec<(i32, i32)> { + let mut samples = Vec::new(); + for x in -5..=5 { + let y = 3 * x * x + x + 3; + samples.push((x, y)); + } + samples +} + +/// 2) Evaluate a single AST on a single input `x`, returning the final top of the int stack. +fn evaluate_ast_on_x( + runner: &mut EvmRunner, + ast: &UntypedAst, + x: i32, +) -> i32 { + // Convert AST => push3 bytecode + let code_bytes = ast.to_bytecode(); + let code_len = code_bytes.len() as u32; + + // Build a sublist descriptor + let descriptor = make_sublist_descriptor(0, code_len); + + // Provide x in `init_int_stack` + let inputs = Push3InterpreterInputs { + code: code_bytes, + init_code_stack: Vec::new(), + init_exec_stack: vec![descriptor], + init_int_stack: vec![x as i128], + }; + + // Run + let outputs = match runner.run_interpreter(&inputs) { + Ok(o) => o, + Err(_) => { + // If revert => 0 + return 0; + } + }; + + if outputs.final_int_stack.is_empty() { + i32::MAX // or 0, or i32::MAX to strongly penalize weird runs + } else { + *outputs.final_int_stack.last().unwrap() as i32 + } +} + +/// 3) Evaluate an AST on all samples => compute MSE +fn evaluate_fitness( + runner: &mut EvmRunner, + ast: &UntypedAst, + samples: &[(i32, i32)] +) -> f64 { + let mut error_sum = 0.0; + for &(x, target_y32) in samples { + // cast to i64 + let target_y = target_y32 as i64; + + // evaluate in i64 + let predicted_i64 = evaluate_ast_on_x(runner, ast, x) as i64; + + // wrapping_sub to avoid panic + let diff = predicted_i64.wrapping_sub(target_y); + error_sum += (diff as f64) * (diff as f64); + } + error_sum / samples.len() as f64 +} + +fn main() -> Result<()> { + // 1) Generate samples + let samples = generate_samples(); + + // 2) Setup ephemeral EVM runner + let creation_hex_filename = "../onchain/out/Push3Interpreter.sol/Push3Interpreter.json"; + let creation_bytes = get_creation_code(creation_hex_filename)?; + let mut runner = EvmRunner::new(creation_bytes)?; + + // 3) GP parameters + let pop_size = 3600; // must be multiple of 3 for our scheme + let generations = 100; + let early_stop_threshold = 1.0; + let max_points = 12; // random code size limit + + // Ensure pop_size is multiple of 3 + assert_eq!(pop_size % 3, 0, "pop_size must be multiple of 3 for our scheme"); + let third = pop_size / 3; + + let mut rng = thread_rng(); + + // 4) Initialize random population + let mut population: Vec = (0..pop_size) + .map(|_| ranmdom_code_fixed(&mut rng, max_points)) + .collect(); + + // 5) Main loop + for gen in 0..generations { + // a) Evaluate + let mut scored: Vec<(UntypedAst, f64)> = population.into_iter() + .map(|ast| { + let err = evaluate_fitness(&mut runner, &ast, &samples); + (ast, err) + }) + .collect(); + + // b) Sort ascending by error + scored.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); + + let best_err = scored[0].1; + println!("\n=== Generation {gen} ==="); + println!("Best error = {best_err}"); + + // (Optionally) Print top 5 in pretty format + let top_n = 5.min(scored.len()); + println!("Top {top_n} subjects:"); + for i in 0..top_n { + println!( + " #{i}, err={}, AST:\n{:#?}", + scored[i].1, + scored[i].0 + ); + } + + // check early stop + if best_err < early_stop_threshold { + println!("Best error < {early_stop_threshold}, stopping early!"); + population = scored.into_iter().map(|(a, _)| a).collect(); + break; + } + + // c) Build new population: + // - 1/3 = best survivors + // - 1/3 = fresh random + // - 1/3 = local mutation + let mut new_pop = Vec::with_capacity(pop_size); + + // keep best third + for i in 0..third { + new_pop.push(scored[i].0.clone()); + } + + // random third + for _ in 0..third { + let fresh = ranmdom_code_fixed(&mut rng, max_points); + new_pop.push(fresh); + } + + // local mutation third + let top_half_count = scored.len() / 2; + // we'll pick parents from top half for local mutation + while new_pop.len() < pop_size { + let idx = rng.gen_range(0..top_half_count); + // we assume you have local_mutation_fixed + // if you prefer passing a custom InstructionSet, do local_mutation(..., &instr_set) + let mutated = offchain::gp::local_mutation::local_mutation_fixed( + &scored[idx].0, + &mut rng + ); + new_pop.push(mutated); + } + + // store for next generation + population = new_pop; + } + + // 6) Final => evaluate & sort => top 10 + println!("\n=== Final Population (Top 10) ==="); + let mut final_scored: Vec<(UntypedAst, f64)> = population + .into_iter() + .map(|ast| { + let err = evaluate_fitness(&mut runner, &ast, &samples); + (ast, err) + }) + .collect(); + final_scored.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); + + let top_n = 10.min(final_scored.len()); + for i in 0..top_n { + let (ref ast, err) = final_scored[i]; + println!("Subject #{i}, err={err}, AST:\n{:#?}", ast); + } + + Ok(()) +} diff --git a/offchain/src/gp/generate_spec.rs b/offchain/src/gp/generate_spec.rs index 3004403..0ac4976 100644 --- a/offchain/src/gp/generate_spec.rs +++ b/offchain/src/gp/generate_spec.rs @@ -47,7 +47,7 @@ impl InstructionSet { InstructionAtom::Opcode(op) => UntypedAst::Instruction(op.clone()), InstructionAtom::EphemeralInt => { // For ephemeral int, produce a random literal in some range - let val = rng.gen_range(-100..100); + let val = rng.gen_range(-30..30); UntypedAst::IntLiteral(val) } } diff --git a/offchain/src/gp/local_mutation.rs b/offchain/src/gp/local_mutation.rs new file mode 100644 index 0000000..5170924 --- /dev/null +++ b/offchain/src/gp/local_mutation.rs @@ -0,0 +1,114 @@ +//! src/gp/local_mutation.rs +//! A localized mutation operator that makes small tweaks depending on node type. + +use rand::Rng; +use crate::compiler::ast::{UntypedAst, OpCode}; +use crate::gp::mutation::{ + enum_nodes_dfs, get_subtree, replace_subtree, +}; +use crate::gp::generate_spec::{ + InstructionAtom, InstructionSet, +}; + +/// A top-level function to perform a localized mutation with a chosen `InstructionSet`. +pub fn local_mutation( + original: &UntypedAst, + rng: &mut impl Rng, + instr_set: &InstructionSet, +) -> UntypedAst { + let all_paths = enum_nodes_dfs(original); + let idx = rng.gen_range(0..all_paths.len()); + let chosen_path = &all_paths[idx]; + + let old_subtree = get_subtree(original, chosen_path); + let new_subtree = local_mutation_node(&old_subtree, rng, instr_set); + replace_subtree(original, chosen_path, new_subtree) +} + +/// A convenience wrapper that always uses `InstructionSet::new_default()`. +pub fn local_mutation_fixed( + original: &UntypedAst, + rng: &mut impl Rng, +) -> UntypedAst { + let instr_set = InstructionSet::new_default(); + local_mutation(original, rng, &instr_set) +} + +fn local_mutation_node( + subtree: &UntypedAst, + rng: &mut impl Rng, + instr_set: &InstructionSet, +) -> UntypedAst { + match subtree { + UntypedAst::IntLiteral(val) => { + let delta = rng.gen_range(-5..=5); + let new_val = val.saturating_add(delta); + UntypedAst::IntLiteral(new_val) + } + UntypedAst::Instruction(op) => { + let mut new_op = pick_random_opcode(rng, instr_set); + for _ in 0..3 { + if &new_op != op { + break; + } + new_op = pick_random_opcode(rng, instr_set); + } + UntypedAst::Instruction(new_op) + } + UntypedAst::Sublist(children) => { + let choice = rng.gen_range(0..3); + let mut new_children = children.clone(); + + match choice { + 0 => { + // remove one child if possible + if !new_children.is_empty() { + let i = rng.gen_range(0..new_children.len()); + new_children.remove(i); + } + } + 1 => { + // insert a new small node + let i = rng.gen_range(0..=new_children.len()); + let node = create_small_node(rng, instr_set); + new_children.insert(i, node); + } + 2 => { + // reorder two children + if new_children.len() > 1 { + let i = rng.gen_range(0..new_children.len()); + let j = rng.gen_range(0..new_children.len()); + new_children.swap(i, j); + } + } + _ => {} + } + + UntypedAst::Sublist(new_children) + } + } +} + +fn pick_random_opcode(rng: &mut impl Rng, instr_set: &InstructionSet) -> OpCode { + use crate::compiler::ast::OpCode; + + let mut opcode_list: Vec<&OpCode> = Vec::new(); + for atom in &instr_set.atoms { + if let InstructionAtom::Opcode(ref op) = atom { + opcode_list.push(op); + } + } + if opcode_list.is_empty() { + // fallback => default to Noop + return OpCode::Noop; + } + let i = rng.gen_range(0..opcode_list.len()); + opcode_list[i].clone() +} + +fn create_small_node( + rng: &mut impl Rng, + instr_set: &InstructionSet, +) -> UntypedAst { + instr_set.random_atom_as_ast(rng) +} diff --git a/offchain/src/gp/mod.rs b/offchain/src/gp/mod.rs index 3b107c3..91c726c 100644 --- a/offchain/src/gp/mod.rs +++ b/offchain/src/gp/mod.rs @@ -3,3 +3,4 @@ pub mod genetic_ops; pub mod generate; pub mod generate_spec; pub mod mutation; +pub mod local_mutation; -- 2.34.1