diff --git a/Cargo.lock b/Cargo.lock index 3ae0611a81..427a4bfce6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -189,9 +189,9 @@ dependencies = [ [[package]] name = "alloy-rlp" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d58d9f5da7b40e9bfff0b7e7816700be4019db97d4b6359fe7f94a9e22e42ac" +checksum = "b155716bab55763c95ba212806cf43d05bcc70e5f35b02bad20cf5ec7fe11fed" dependencies = [ "alloy-rlp-derive", "arrayvec", @@ -200,13 +200,13 @@ dependencies = [ [[package]] name = "alloy-rlp-derive" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a047897373be4bbb0224c1afdabca92648dc57a9c9ef6e7b0be3aff7a859c83" +checksum = "8037e03c7f462a063f28daec9fda285a9a89da003c552f8637a80b9c8fd96241" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -294,9 +294,23 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef9a94a27345fb31e3fcb5f5e9f592bb4847493b07fa1e47dd9fde2222f2e28" +checksum = "7dbd17d67f3e89478c8a634416358e539e577899666c927bc3d2b1328ee9b6ca" +dependencies = [ + "alloy-sol-macro-expander", + "alloy-sol-macro-input", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "alloy-sol-macro-expander" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6da95adcf4760bb4b108fefa51d50096c5e5fdd29ee72fed3e86ee414f2e34" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -305,31 +319,31 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", "syn-solidity", "tiny-keccak", ] [[package]] name = "alloy-sol-macro-input" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31fe73cd259527e24dc2dbfe64bc95e5ddfcd2b2731f670a11ff72b2be2c25b" +checksum = "32c8da04c1343871fb6ce5a489218f9c85323c8340a36e9106b5fc98d4dd59d5" dependencies = [ "const-hex", "dunce", "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", "syn-solidity", ] [[package]] name = "alloy-sol-types" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afaffed78bfb17526375754931e045f96018aa810844b29c7aef823266dd4b4b" +checksum = "40a64d2d2395c1ac636b62419a7b17ec39031d6b2367e66e9acbf566e6055e9c" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -384,47 +398,48 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -432,9 +447,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "ark-ff" @@ -585,7 +600,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -596,9 +611,15 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "aurora-engine-modexp" version = "1.1.0" @@ -617,20 +638,20 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" dependencies = [ "addr2line", "cc", @@ -649,9 +670,9 @@ checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" [[package]] name = "base64" -version = "0.22.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" @@ -752,9 +773,9 @@ dependencies = [ [[package]] name = "c-kzg" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3130f3d8717cc02e668a896af24984d5d5d4e8bf12e278e982e0f1bd88a0f9af" +checksum = "cdf100c4cea8f207e883ff91ca886d621d8a166cb04971dfaa9bb8fd99ed95df" dependencies = [ "blst", "cc", @@ -766,9 +787,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.95" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" [[package]] name = "cfg-if" @@ -807,7 +828,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -818,15 +839,25 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "command-fds" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "7bb11bd1378bf3731b182997b40cefe00aba6a6cc74042c8318c1b271d3badf7" +dependencies = [ + "nix", + "thiserror", +] [[package]] name = "const-hex" -version = "1.11.3" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba00838774b4ab0233e355d26710fbfc8327a05c017f6dc4873f876d1f79f78" +checksum = "94fb8a24a26d37e1ffd45343323dc9fe6654ceea44c12f2fcb3d7ac29e610bc6" dependencies = [ "cfg-if", "cpufeatures", @@ -996,9 +1027,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "elliptic-curve" @@ -1036,7 +1067,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -1047,9 +1078,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1057,9 +1088,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fastrlp" @@ -1186,7 +1217,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -1238,9 +1269,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -1249,9 +1280,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "glob" @@ -1272,15 +1303,15 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" dependencies = [ + "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "futures-util", "http", "indexmap", "slab", @@ -1291,9 +1322,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", @@ -1420,9 +1451,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" dependencies = [ "bytes", "futures-channel", @@ -1484,6 +1515,12 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itertools" version = "0.10.5" @@ -1532,14 +1569,23 @@ dependencies = [ [[package]] name = "keccak-asm" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb8515fff80ed850aea4a1595f2e519c003e2a00a82fe168ebf5269196caf444" +checksum = "47a3633291834c4fbebf8673acbc1b04ec9d151418ff9b8e26dcd79129928758" dependencies = [ "digest 0.10.7", "sha3-asm", ] +[[package]] +name = "kona-client" +version = "0.1.0" +dependencies = [ + "cfg-if", + "kona-common", + "kona-common-proc", +] + [[package]] name = "kona-common" version = "0.0.1" @@ -1558,7 +1604,7 @@ dependencies = [ "kona-common", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -1599,10 +1645,23 @@ dependencies = [ name = "kona-host" version = "0.1.0" dependencies = [ + "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=e3f2f07)", + "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=e3f2f07)", "alloy-primitives", + "alloy-provider", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-transport-http", "anyhow", "clap", + "command-fds", + "kona-common", + "kona-mpt", + "kona-preimage", + "reqwest", + "revm", "serde", + "tempfile", "tokio", "tracing", "tracing-subscriber", @@ -1686,9 +1745,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libm" @@ -1707,9 +1766,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -1759,9 +1818,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -1779,11 +1838,10 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "lazy_static", "libc", "log", "openssl", @@ -1795,6 +1853,17 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "libc", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1807,9 +1876,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ "num-bigint", "num-complex", @@ -1821,20 +1890,19 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] @@ -1850,9 +1918,9 @@ dependencies = [ [[package]] name = "num-iter" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", @@ -1861,11 +1929,10 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", @@ -1873,9 +1940,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", @@ -1903,9 +1970,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" dependencies = [ "memchr", ] @@ -1952,7 +2019,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -1981,9 +2048,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parity-scale-codec" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" dependencies = [ "arrayvec", "bitvec", @@ -1995,9 +2062,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.9" +version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2007,9 +2074,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -2030,9 +2097,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "percent-encoding" @@ -2042,9 +2109,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.9" +version = "2.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" dependencies = [ "memchr", "thiserror", @@ -2068,7 +2135,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -2118,11 +2185,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.2" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_datetime", "toml_edit", ] @@ -2152,9 +2218,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] @@ -2307,6 +2373,8 @@ dependencies = [ "dyn-clone", "revm-interpreter", "revm-precompile", + "serde", + "serde_json", ] [[package]] @@ -2316,6 +2384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a58182c7454179826f9dad2ca577661963092ce9d0fd0c9d682c1e9215a72e70" dependencies = [ "revm-primitives 4.0.0", + "serde", ] [[package]] @@ -2325,10 +2394,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc8af9aa737eef0509a50d9f3cc1a631557a00ef2e70a3aa8a75d9ee0ed275bb" dependencies = [ "aurora-engine-modexp", + "blst", + "c-kzg", "k256", "once_cell", "revm-primitives 4.0.0", "ripemd", + "secp256k1", "sha2", "substrate-bn", ] @@ -2364,11 +2436,15 @@ dependencies = [ "auto_impl", "bitflags 2.5.0", "bitvec", + "c-kzg", "cfg-if", + "derive_more", "dyn-clone", "enumn", "hashbrown", "hex", + "once_cell", + "serde", ] [[package]] @@ -2432,9 +2508,9 @@ checksum = "f86854cf50259291520509879a5c294c3c9a4c334e9ff65071c51e42ef1e2343" [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hex" @@ -2457,7 +2533,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.22", + "semver 1.0.23", ] [[package]] @@ -2485,9 +2561,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.5.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rusty-fork" @@ -2503,9 +2579,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" @@ -2536,13 +2612,32 @@ dependencies = [ "zeroize", ] +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "rand", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -2551,9 +2646,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -2570,9 +2665,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "semver-parser" @@ -2585,30 +2680,31 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.198" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ + "indexmap", "itoa", "ryu", "serde", @@ -2639,9 +2735,9 @@ dependencies = [ [[package]] name = "sha3-asm" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac61da6b35ad76b195eb4771210f947734321a8d81d7738e1580d953bc7a15e" +checksum = "a9b57fd861253bff08bb1919e995f90ba8f4889de2726091c8876f3a4e823b40" dependencies = [ "cc", "cfg-if", @@ -2704,9 +2800,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -2790,9 +2886,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -2801,14 +2897,14 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70aba06097b6eda3c15f6eebab8a6339e121475bcf08bbe6758807e716c372a1" +checksum = "b8db114c44cf843a8bacd37a146e37987a0b823a0e8bc4fdc610c9c72ab397a5" dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -2858,22 +2954,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -2946,7 +3042,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -2973,29 +3069,28 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" [[package]] name = "toml_edit" -version = "0.20.2" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" dependencies = [ "indexmap", "toml_datetime", @@ -3050,7 +3145,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] @@ -3231,7 +3326,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -3265,7 +3360,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3477,29 +3572,29 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ "zeroize_derive", ] @@ -3512,5 +3607,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.66", ] diff --git a/Cargo.toml b/Cargo.toml index a0ce8870a9..3c710d029b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = ["crates/*", "bin/host", "bin/programs/*"] -exclude = ["fpvm-tests/cannon-rs-tests", "bin/programs/optimism"] +exclude = ["fpvm-tests/cannon-rs-tests"] resolver = "2" [workspace.package] diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index 2edbc0a7c1..2e7aac8609 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -13,8 +13,24 @@ exclude.workspace = true anyhow.workspace = true tracing.workspace = true alloy-primitives = { workspace = true, features = ["serde"] } +revm = { workspace = true, features = ["std", "c-kzg", "secp256k1", "portable", "blst"] } +# local +kona-common = { path = "../../crates/common", version = "0.0.1" } +kona-preimage = { path = "../../crates/preimage", version = "0.0.1" } +kona-mpt = { path = "../../crates/mpt", version = "0.0.1" } + +# external +alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" } +alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" } +alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" } +alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" } +alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" } +alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" } +reqwest = "0.12" tokio = { version = "1.37.0", features = ["full"] } clap = { version = "4.5.4", features = ["derive", "env"] } serde = { version = "1.0.198", features = ["derive"] } tracing-subscriber = "0.3.18" +command-fds = "0.3.0" +tempfile = "3.10" diff --git a/bin/host/src/cli/mod.rs b/bin/host/src/cli/mod.rs index bc95895542..24a306deec 100644 --- a/bin/host/src/cli/mod.rs +++ b/bin/host/src/cli/mod.rs @@ -9,7 +9,7 @@ mod parser; pub(crate) use parser::parse_b256; mod types; -pub(crate) use types::{Network, RpcKind}; +pub(crate) use types::Network; mod tracing_util; pub(crate) use tracing_util::init_tracing_subscriber; @@ -31,7 +31,7 @@ pub struct HostCli { pub data_dir: Option, /// Address of L2 JSON-RPC endpoint to use (eth and debug namespace required). #[clap(long)] - pub l2_node_address: String, + pub l2_node_address: Option, /// Hash of the L1 head block. Derivation stops after this block is processed. #[clap(long, value_parser = parse_b256)] pub l1_head: B256, @@ -52,23 +52,23 @@ pub struct HostCli { pub l2_genesis_path: PathBuf, /// Address of L1 JSON-RPC endpoint to use (eth namespace required) #[clap(long)] - pub l1_node_address: String, + pub l1_node_address: Option, /// Address of the L1 Beacon API endpoint to use. #[clap(long)] - pub l1_beacon_address: String, - /// Trust the L1 RPC, sync faster at risk of malicious/buggy RPC providing bad or inconsistent - /// L1 data - #[clap(long)] - pub l1_trust_rpc: bool, - /// The kind of RPC provider, used to inform optimal transactions receipts fetching, and thus - /// reduce costs. - #[clap(long)] - pub l1_rpc_provider_kind: RpcKind, + pub l1_beacon_address: Option, /// Run the specified client program as a separate process detached from the host. Default is /// to run the client program in the host process. #[clap(long)] pub exec: String, - /// Run in pre-image server mode without executing any client program. + /// Run in pre-image server mode without executing any client program. Defaults to `false`. #[clap(long)] pub server: bool, } + +impl HostCli { + pub fn is_offline(&self) -> bool { + self.l1_node_address.is_none() || + self.l2_node_address.is_none() || + self.l1_beacon_address.is_none() + } +} diff --git a/bin/host/src/cli/types.rs b/bin/host/src/cli/types.rs index f48efb366f..aa3b292e68 100644 --- a/bin/host/src/cli/types.rs +++ b/bin/host/src/cli/types.rs @@ -6,11 +6,6 @@ use serde::Serialize; pub enum Network { /// Optimism Mainnet Optimism, -} - -/// Available RPC provider types. -#[derive(Debug, Clone, ValueEnum, Serialize)] -pub enum RpcKind { - /// debug alloy provider - DebugRpc, + /// Optimism Sepolia + OptimismSepolia, } diff --git a/bin/host/src/fetcher/hint.rs b/bin/host/src/fetcher/hint.rs new file mode 100644 index 0000000000..54990c4a94 --- /dev/null +++ b/bin/host/src/fetcher/hint.rs @@ -0,0 +1,72 @@ +//! This module contains the [HintType] enum. + +use std::fmt::Display; + +/// The [HintType] enum is used to specify the type of hint that was received. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub enum HintType { + /// A hint that specifies the block header of a layer 1 block. + L1BlockHeader, + /// A hint that specifies the transactions of a layer 1 block. + L1Transactions, + /// A hint that specifies the state node of a layer 1 block. + L1Receipts, + /// A hint that specifies a blob in the layer 1 beacon chain. + L1Blob, + /// A hint that specifies a precompile call on layer 1. + L1Precompile, + /// A hint that specifies the block header of a layer 2 block. + L2BlockHeader, + /// A hint that specifies the transactions of a layer 2 block. + L2Transactions, + /// A hint that specifies the state node in the L2 state trie. + L2StateNode, + /// A hint that specifies the code of a contract on layer 2. + L2Code, + /// A hint that specifies the output root of a block on layer 2. + L2Output, +} + +impl TryFrom<&str> for HintType { + type Error = anyhow::Error; + + fn try_from(value: &str) -> Result { + match value { + "l1-block-header" => Ok(HintType::L1BlockHeader), + "l1-transactions" => Ok(HintType::L1Transactions), + "l1-receipts" => Ok(HintType::L1Receipts), + "l1-blob" => Ok(HintType::L1Blob), + "l1-precompile" => Ok(HintType::L1Precompile), + "l2-block-header" => Ok(HintType::L2BlockHeader), + "l2-transactions" => Ok(HintType::L2Transactions), + "l2-state-node" => Ok(HintType::L2StateNode), + "l2-code" => Ok(HintType::L2Code), + "l2-output" => Ok(HintType::L2Output), + _ => anyhow::bail!("Invalid hint type: {value}"), + } + } +} + +impl From for &str { + fn from(value: HintType) -> Self { + match value { + HintType::L1BlockHeader => "l1-block-header", + HintType::L1Transactions => "l1-transactions", + HintType::L1Receipts => "l1-receipts", + HintType::L1Blob => "l1-blob", + HintType::L1Precompile => "l1-precompile", + HintType::L2BlockHeader => "l2-block-header", + HintType::L2Transactions => "l2-transactions", + HintType::L2StateNode => "l2-state-node", + HintType::L2Code => "l2-code", + HintType::L2Output => "l2-output", + } + } +} + +impl Display for HintType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s: &str = (*self).into(); + write!(f, "{}", s) + } +} diff --git a/bin/host/src/fetcher/mod.rs b/bin/host/src/fetcher/mod.rs new file mode 100644 index 0000000000..f8031a57ca --- /dev/null +++ b/bin/host/src/fetcher/mod.rs @@ -0,0 +1,236 @@ +//! This module contains the [Fetcher] struct, which is responsible for fetching preimages from a +//! remote source. + +use crate::{kv::KeyValueStore, util}; +use alloy_consensus::TxEnvelope; +use alloy_eips::eip2718::Encodable2718; +use alloy_primitives::{keccak256, Address, Bytes, B256}; +use alloy_provider::{Provider, ReqwestProvider}; +use alloy_rpc_types::{Block, BlockTransactions}; +use anyhow::{anyhow, Result}; +use kona_preimage::{PreimageKey, PreimageKeyType}; +use std::sync::Arc; +use tokio::sync::RwLock; +use tracing::debug; + +mod hint; +pub use hint::HintType; + +mod precompiles; + +/// The [Fetcher] struct is responsible for fetching preimages from a remote source. +pub struct Fetcher +where + KV: KeyValueStore, +{ + /// Key-value store for preimages. + kv_store: Arc>, + /// L1 chain provider. + l1_provider: ReqwestProvider, + /// L2 chain provider. + /// TODO: OP provider, N = Optimism + #[allow(unused)] + l2_provider: ReqwestProvider, + /// The last hint that was received. [None] if no hint has been received yet. + last_hint: Option, +} + +impl Fetcher +where + KV: KeyValueStore, +{ + /// Create a new [Fetcher] with the given [KeyValueStore]. + pub fn new( + kv_store: Arc>, + l1_provider: ReqwestProvider, + l2_provider: ReqwestProvider, + ) -> Self { + Self { kv_store, l1_provider, l2_provider, last_hint: None } + } + + /// Set the last hint to be received. + pub fn hint(&mut self, hint: &str) { + debug!(target: "fetcher", "Received hint: {hint}"); + self.last_hint = Some(hint.to_string()); + } + + /// Get the preimage for the given key. + pub async fn get_preimage(&self, key: B256) -> Result> { + debug!(target: "fetcher", "Pre-image requested. Key: {key}"); + + // Acquire a read lock on the key-value store. + let kv_lock = self.kv_store.read().await; + let mut preimage = kv_lock.get(key).cloned(); + + // Drop the read lock before beginning the loop. + drop(kv_lock); + + // Use a loop to keep retrying the prefetch as long as the key is not found + while preimage.is_none() && self.last_hint.is_some() { + let hint = self.last_hint.as_ref().expect("Cannot be None"); + self.prefetch(hint).await?; + + let kv_lock = self.kv_store.read().await; + preimage = kv_lock.get(key).cloned(); + } + + preimage.ok_or_else(|| anyhow!("Preimage not found.")) + } + + /// Fetch the preimage for the given hint and insert it into the key-value store. + async fn prefetch(&self, hint: &str) -> Result<()> { + let (hint_type, hint_data) = util::parse_hint(hint)?; + debug!(target: "fetcher", "Fetching hint: {hint_type} {hint_data}"); + + match hint_type { + HintType::L1BlockHeader => { + // Validate the hint data length. + if hint_data.len() != 32 { + anyhow::bail!("Invalid hint data length: {}", hint_data.len()); + } + + // Fetch the raw header from the L1 chain provider. + let hash: B256 = hint_data + .as_ref() + .try_into() + .map_err(|e| anyhow!("Failed to convert bytes to B256: {e}"))?; + let raw_header: Bytes = self + .l1_provider + .client() + .request("debug_getRawHeader", [hash]) + .await + .map_err(|e| anyhow!(e))?; + + // Acquire a lock on the key-value store and set the preimage. + let mut kv_lock = self.kv_store.write().await; + kv_lock.set( + PreimageKey::new(*hash, PreimageKeyType::Keccak256).into(), + raw_header.into(), + ); + } + HintType::L1Transactions => { + // Validate the hint data length. + if hint_data.len() != 32 { + anyhow::bail!("Invalid hint data length: {}", hint_data.len()); + } + + // Fetch the block from the L1 chain provider and store the transactions within its + // body in the key-value store. + let hash: B256 = hint_data + .as_ref() + .try_into() + .map_err(|e| anyhow!("Failed to convert bytes to B256: {e}"))?; + let Block { transactions, .. } = self + .l1_provider + .get_block_by_hash(hash, true) + .await + .map_err(|e| anyhow!("Failed to fetch block: {e}"))? + .ok_or(anyhow!("Block not found."))?; + self.store_transactions(transactions).await?; + } + HintType::L1Receipts => { + // Validate the hint data length. + if hint_data.len() != 32 { + anyhow::bail!("Invalid hint data length: {}", hint_data.len()); + } + + // Fetch the receipts from the L1 chain provider and store the receipts within the + // key-value store. + let hash: B256 = hint_data + .as_ref() + .try_into() + .map_err(|e| anyhow!("Failed to convert bytes to B256: {e}"))?; + let raw_receipts: Vec = self + .l1_provider + .client() + .request("debug_getRawReceipts", [hash]) + .await + .map_err(|e| anyhow!(e))?; + self.store_trie_nodes(raw_receipts.as_slice()).await?; + } + HintType::L1Blob => todo!(), + HintType::L1Precompile => { + // Validate the hint data length. + if hint_data.len() < 20 { + anyhow::bail!("Invalid hint data length: {}", hint_data.len()); + } + + // Fetch the precompile address from the hint data. + let precompile_address = Address::from_slice(&hint_data.as_ref()[..20]); + let precompile_input = hint_data[20..].to_vec(); + let input_hash = keccak256(hint_data.as_ref()); + + let result = match precompiles::execute(precompile_address, precompile_input) { + Ok(raw_res) => { + let mut res = Vec::with_capacity(1 + raw_res.len()); + res.push(0x01); // success type byte + res.extend_from_slice(&raw_res); + res + } + Err(_) => { + // failure type byte + vec![0u8; 1] + } + }; + + // Acquire a lock on the key-value store and set the preimages. + let mut kv_lock = self.kv_store.write().await; + kv_lock.set( + PreimageKey::new(*input_hash, PreimageKeyType::Keccak256).into(), + hint_data.into(), + ); + kv_lock + .set(PreimageKey::new(*input_hash, PreimageKeyType::Precompile).into(), result); + } + HintType::L2BlockHeader => todo!(), + HintType::L2Transactions => todo!(), + HintType::L2StateNode => todo!(), + HintType::L2Code => todo!(), + HintType::L2Output => todo!(), + } + + Ok(()) + } + + /// Stores a list of [BlockTransactions] in the key-value store. + async fn store_transactions(&self, transactions: BlockTransactions) -> Result<()> { + match transactions { + BlockTransactions::Full(transactions) => { + let encoded_transactions = transactions + .into_iter() + .map(|tx| { + let envelope: TxEnvelope = tx.try_into().map_err(|e| { + anyhow!( + "Failed to convert RPC transaction into consensus envelope: {e}" + ) + })?; + + Ok::<_, anyhow::Error>(envelope.encoded_2718()) + }) + .collect::>>()?; + + self.store_trie_nodes(encoded_transactions.as_slice()).await + } + _ => anyhow::bail!("Only BlockTransactions::Full are supported."), + } + } + + /// Stores intermediate trie nodes in the key-value store. Assumes that all nodes passed are + /// raw, RLP encoded trie nodes. + async fn store_trie_nodes>(&self, nodes: &[T]) -> Result<()> { + let mut hb = kona_mpt::ordered_trie_with_encoder(nodes, |node, buf| { + buf.put_slice(node.as_ref()); + }); + let intermediates = hb.take_proofs(); + + let mut kv_write_lock = self.kv_store.write().await; + for (_, value) in intermediates.into_iter() { + let value_hash = keccak256(value.as_ref()); + let key = PreimageKey::new(*value_hash, PreimageKeyType::Keccak256); + + kv_write_lock.set(key.into(), value.into()); + } + + Ok(()) + } +} diff --git a/bin/host/src/fetcher/precompiles.rs b/bin/host/src/fetcher/precompiles.rs new file mode 100644 index 0000000000..d0b4f5f18d --- /dev/null +++ b/bin/host/src/fetcher/precompiles.rs @@ -0,0 +1,42 @@ +//! Accelerated precompile runner for the host program. + +use alloy_primitives::{Address, Bytes}; +use anyhow::{anyhow, Result}; +use revm::{ + precompile::{self, PrecompileWithAddress}, + primitives::{Env, Precompile}, +}; + +/// List of precompiles that are accelerated by the host program. +pub(crate) const ACCELERATED_PRECOMPILES: &[PrecompileWithAddress] = &[ + precompile::secp256k1::ECRECOVER, // ecRecover + precompile::bn128::pair::ISTANBUL, // ecPairing + precompile::kzg_point_evaluation::POINT_EVALUATION, // KZG point evaluation +]; + +/// Executes an accelerated precompile on [revm]. +pub(crate) fn execute>(address: Address, input: T) -> Result> { + if let Some(precompile) = + ACCELERATED_PRECOMPILES.iter().find(|precompile| precompile.0 == address) + { + match precompile.1 { + Precompile::Standard(std_precompile) => { + // Standard precompile execution - no access to environment required. + let (_, result) = std_precompile(&input.into(), u64::MAX) + .map_err(|e| anyhow!("Failed precompile execution: {e}"))?; + + Ok(result.to_vec()) + } + Precompile::Env(env_precompile) => { + // Use default environment for KZG point evaluation. + let (_, result) = env_precompile(&input.into(), u64::MAX, &Env::default()) + .map_err(|e| anyhow!("Failed precompile execution: {e}"))?; + + Ok(result.to_vec()) + } + _ => anyhow::bail!("Precompile not accelerated"), + } + } else { + anyhow::bail!("Precompile not accelerated"); + } +} diff --git a/bin/host/src/kv/mem.rs b/bin/host/src/kv/mem.rs new file mode 100644 index 0000000000..d7f2a30b7a --- /dev/null +++ b/bin/host/src/kv/mem.rs @@ -0,0 +1,30 @@ +//! Contains a concrete implementation of the [KeyValueStore] trait that stores data in memory. + +use alloy_primitives::B256; + +use super::KeyValueStore; +use std::collections::HashMap; + +/// A simple, synchronous key-value store that stores data in memory. This is useful for testing and +/// development purposes. +#[derive(Default, Clone, Debug, Eq, PartialEq)] +pub struct MemoryKeyValueStore { + store: HashMap>, +} + +impl MemoryKeyValueStore { + /// Create a new [MemoryKeyValueStore] with an empty store. + pub fn new() -> Self { + Self { store: HashMap::new() } + } +} + +impl KeyValueStore for MemoryKeyValueStore { + fn get(&self, key: B256) -> Option<&Vec> { + self.store.get(&key) + } + + fn set(&mut self, key: B256, value: Vec) { + self.store.insert(key, value); + } +} diff --git a/bin/host/src/kv/mod.rs b/bin/host/src/kv/mod.rs new file mode 100644 index 0000000000..babec0ee6d --- /dev/null +++ b/bin/host/src/kv/mod.rs @@ -0,0 +1,15 @@ +//! This module contains the [KeyValueStore] trait and concrete implementations of it. + +use alloy_primitives::B256; + +mod mem; +pub use mem::MemoryKeyValueStore; + +/// Describes the interface of a simple, synchronous key-value store. +pub trait KeyValueStore { + /// Get the value associated with the given key. + fn get(&self, key: B256) -> Option<&Vec>; + + /// Set the value associated with the given key. + fn set(&mut self, key: B256, value: Vec); +} diff --git a/bin/host/src/main.rs b/bin/host/src/main.rs index 39adb427e8..2fc5871015 100644 --- a/bin/host/src/main.rs +++ b/bin/host/src/main.rs @@ -1,13 +1,127 @@ -use crate::cli::{init_tracing_subscriber, HostCli}; -use anyhow::Result; +use crate::{ + cli::{init_tracing_subscriber, HostCli}, + kv::MemoryKeyValueStore, + server::PreimageServer, +}; +use anyhow::{anyhow, Result}; use clap::Parser; +use command_fds::{CommandFdExt, FdMapping}; +use fetcher::Fetcher; +use kona_common::FileDescriptor; +use kona_preimage::{HintReader, OracleServer, PipeHandle}; +use std::{ + io::{stderr, stdin, stdout}, + os::fd::AsFd, + process::Command, + sync::Arc, +}; +use tokio::sync::RwLock; +use tracing::{error, info}; mod cli; +mod fetcher; +mod kv; +mod server; +mod util; #[tokio::main] async fn main() -> Result<()> { - let HostCli { v: tracing_verbosity, .. } = HostCli::parse(); - let _ = init_tracing_subscriber(tracing_verbosity); - tracing::info!("host telemetry initialized"); + let cfg = HostCli::parse(); + init_tracing_subscriber(cfg.v)?; + + if cfg.server { + start_server(cfg).await?; + } else { + start_server_and_native_client(cfg).await?; + } + + info!("Exiting host program."); + Ok(()) +} + +/// Starts the [PreimageServer] in the primary thread. In this mode, the host program has been +/// invoked by the Fault Proof VM and the client program is running in the parent process. +async fn start_server(cfg: HostCli) -> Result<()> { + let (preimage_pipe, hint_pipe) = ( + PipeHandle::new(FileDescriptor::PreimageRead, FileDescriptor::PreimageWrite), + PipeHandle::new(FileDescriptor::HintRead, FileDescriptor::HintWrite), + ); + let oracle_server = OracleServer::new(preimage_pipe); + let hint_reader = HintReader::new(hint_pipe); + + // TODO: Optional disk store if `cli.data_dir` is set. + let mem_kv_store = Arc::new(RwLock::new(MemoryKeyValueStore::new())); + + let fetcher = (!cfg.is_offline()).then(|| { + let l1_provider = util::http_provider(&cfg.l1_node_address.expect("Provider must be set")); + let l2_provider = util::http_provider(&cfg.l2_node_address.expect("Provider must be set")); + Arc::new(RwLock::new(Fetcher::new(mem_kv_store.clone(), l1_provider, l2_provider))) + }); + + // Start the server and wait for it to complete. + info!("Starting preimage server."); + let server = PreimageServer::new(oracle_server, hint_reader, mem_kv_store, fetcher); + server.start().await?; + info!("Preimage server has exited."); + + Ok(()) +} + +/// Starts the [PreimageServer] and the client program in separate threads. The client program is +/// ran natively in this mode. +async fn start_server_and_native_client(cfg: HostCli) -> Result<()> { + let (preimage_pipe, hint_pipe, mut files) = util::create_native_pipes()?; + let oracle_server = OracleServer::new(preimage_pipe); + let hint_reader = HintReader::new(hint_pipe); + + // TODO: Optional disk store if `cli.data_dir` is set. + let mem_kv_store = Arc::new(RwLock::new(MemoryKeyValueStore::new())); + + let fetcher = (!cfg.is_offline()).then(|| { + let l1_provider = util::http_provider(&cfg.l1_node_address.expect("Provider must be set")); + let l2_provider = util::http_provider(&cfg.l2_node_address.expect("Provider must be set")); + Arc::new(RwLock::new(Fetcher::new(mem_kv_store.clone(), l1_provider, l2_provider))) + }); + + // Create the server and start it. + let server = PreimageServer::new(oracle_server, hint_reader, mem_kv_store, fetcher); + let server_task = tokio::task::spawn(server.start()); + + // Start the client program in a separate child process. + let program_task = tokio::task::spawn(async move { + let mut command = Command::new(cfg.exec); + + // Map the file descriptors to the standard streams and the preimage oracle and hint + // reader's special file descriptors. + command + .fd_mappings(vec![ + FdMapping { parent_fd: stdin().as_fd().try_clone_to_owned().unwrap(), child_fd: 0 }, + FdMapping { + parent_fd: stdout().as_fd().try_clone_to_owned().unwrap(), + child_fd: 1, + }, + FdMapping { + parent_fd: stderr().as_fd().try_clone_to_owned().unwrap(), + child_fd: 2, + }, + FdMapping { parent_fd: files.remove(3).into(), child_fd: 3 }, + FdMapping { parent_fd: files.remove(2).into(), child_fd: 4 }, + FdMapping { parent_fd: files.remove(1).into(), child_fd: 5 }, + FdMapping { parent_fd: files.remove(0).into(), child_fd: 6 }, + ]) + .expect("No errors may occur when mapping file descriptors."); + + Ok(command.status().map_err(|e| anyhow!(e))?.success()) + }); + + info!("Starting preimage server and client program."); + let (server_res, program_res) = + tokio::try_join!(server_task, program_task).map_err(|e| anyhow!(e))?; + server_res?; + if !program_res? { + error!("Client program exited with a non-zero status."); + } + info!("Preimage server and client program have exited."); + Ok(()) } diff --git a/bin/host/src/server.rs b/bin/host/src/server.rs new file mode 100644 index 0000000000..7fc4c44c46 --- /dev/null +++ b/bin/host/src/server.rs @@ -0,0 +1,128 @@ +//! This module contains the [PreimageServer] struct and its implementation. + +use crate::{fetcher::Fetcher, kv::KeyValueStore}; +use anyhow::{anyhow, Result}; +use kona_preimage::{HintReaderServer, PreimageKey, PreimageOracleServer}; +use std::{future::Future, pin::Pin, sync::Arc}; +use tokio::sync::RwLock; +use tracing::debug; + +/// The [PreimageServer] is responsible for waiting for incoming preimage requests and +/// serving them to the client. +pub struct PreimageServer +where + P: PreimageOracleServer, + H: HintReaderServer, + KV: KeyValueStore, +{ + /// The oracle server. + oracle_server: P, + /// The hint router. + hint_reader: H, + /// Key-value store for preimages. + kv_store: Arc>, + /// The fetcher for fetching preimages from a remote source. If [None], the server will only + /// serve preimages that are already in the key-value store. + fetcher: Option>>>, +} + +impl PreimageServer +where + P: PreimageOracleServer + Send + Sync + 'static, + H: HintReaderServer + Send + Sync + 'static, + KV: KeyValueStore + Send + Sync + 'static, +{ + /// Create a new [PreimageServer] with the given [PreimageOracleServer], + /// [HintReaderServer], and [KeyValueStore]. Holds onto the file descriptors for the pipes + /// that are created, so that the pipes are not closed until the server is dropped. + pub fn new( + oracle_server: P, + hint_reader: H, + kv_store: Arc>, + fetcher: Option>>>, + ) -> Self { + Self { oracle_server, hint_reader, kv_store, fetcher } + } + + /// Starts the [PreimageServer] and waits for incoming requests. + pub async fn start(self) -> Result<()> { + // Create the futures for the oracle server and hint router. + let server_fut = + Self::start_oracle_server(self.kv_store, self.fetcher.clone(), self.oracle_server); + let hinter_fut = Self::start_hint_router(self.hint_reader, self.fetcher); + + // Spawn tasks for the futures and wait for them to complete. + let server = tokio::task::spawn(server_fut); + let hint_router = tokio::task::spawn(hinter_fut); + tokio::try_join!(server, hint_router).map_err(|e| anyhow!(e))?; + + Ok(()) + } + + /// Starts the oracle server, which waits for incoming preimage requests and serves them to the + /// client. + async fn start_oracle_server( + kv_store: Arc>, + fetcher: Option>>>, + oracle_server: P, + ) { + #[allow(clippy::type_complexity)] + let get_preimage = + |key: PreimageKey| -> Pin>> + Send>> { + if let Some(fetcher) = fetcher.as_ref() { + // If a fetcher is present, use it to fetch the preimage. + Box::pin(async move { + let fetcher = fetcher.read().await; + fetcher.get_preimage(key.into()).await + }) + } else { + // Otherwise, use the key-value store to fetch the preimage when in offline + // mode. + let kv_store = kv_store.as_ref(); + Box::pin(async move { + kv_store + .read() + .await + .get(key.into()) + .ok_or_else(|| anyhow!("Preimage not found")) + .cloned() + }) + } + }; + + loop { + // TODO: More granular error handling. Some errors here are expected, such as the client + // closing the pipe, while others are not and should throw. + if oracle_server.next_preimage_request(get_preimage).await.is_err() { + break; + } + } + } + + /// Starts the hint router, which waits for incoming hints and routes them to the appropriate + /// handler. + async fn start_hint_router(hint_reader: H, fetcher: Option>>>) { + let route_hint = |hint: String| -> Pin> + Send>> { + if let Some(fetcher) = fetcher.as_ref() { + let fetcher = Arc::clone(fetcher); + Box::pin(async move { + fetcher.write().await.hint(&hint); + Ok(()) + }) + } else { + Box::pin(async move { + debug!(target: "preimage_server", "Received hint in offline mode: {}", &hint); + Ok(()) + }) + } + }; + + loop { + // TODO: More granular error handling. Some errors here are expected, such as the client + // closing the pipe, while others are not and should throw. + if hint_reader.next_hint(route_hint).await.is_err() { + break; + } + } + } +} diff --git a/bin/host/src/util.rs b/bin/host/src/util.rs new file mode 100644 index 0000000000..9b2459a4c7 --- /dev/null +++ b/bin/host/src/util.rs @@ -0,0 +1,69 @@ +//! Contains utility functions and helpers for the host program. + +use crate::fetcher::HintType; +use alloy_primitives::{hex, Bytes}; +use alloy_provider::ReqwestProvider; +use alloy_rpc_client::RpcClient; +use alloy_transport_http::Http; +use anyhow::{anyhow, Result}; +use kona_common::FileDescriptor; +use kona_preimage::PipeHandle; +use reqwest::Client; +use std::{fs::File, os::fd::AsRawFd}; +use tempfile::tempfile; + +/// Parses a hint from a string. +/// +/// Hints are of the format ` `, where `` is a string that +/// represents the type of hint, and `` is the data associated with the hint +/// (bytes encoded as hex UTF-8). +pub(crate) fn parse_hint(s: &str) -> Result<(HintType, Bytes)> { + let mut parts = s.split(' ').collect::>(); + + if parts.len() != 2 { + anyhow::bail!("Invalid hint format: {}", s); + } + + let hint_type = HintType::try_from(parts.remove(0))?; + let hint_data = hex::decode(parts.remove(0)).map_err(|e| anyhow!(e))?.into(); + + Ok((hint_type, hint_data)) +} + +/// Creates two temporary files that are connected by a pipe. +pub(crate) fn create_temp_files() -> Result<(File, File)> { + let (read, write) = (tempfile().map_err(|e| anyhow!(e))?, tempfile().map_err(|e| anyhow!(e))?); + Ok((read, write)) +} + +/// Create a pair of pipes for the preimage oracle and hint reader. Also returns the files that are +/// used to create the pipes, which must be kept alive until the pipes are closed. +pub(crate) fn create_native_pipes() -> Result<(PipeHandle, PipeHandle, Vec)> { + let (po_reader, po_writer) = create_temp_files()?; + let (hint_reader, hint_writer) = create_temp_files()?; + let preimage_pipe = PipeHandle::new( + FileDescriptor::Wildcard( + po_reader.as_raw_fd().try_into().map_err(|e| anyhow!("Failed to get raw FD: {e}"))?, + ), + FileDescriptor::Wildcard( + po_writer.as_raw_fd().try_into().map_err(|e| anyhow!("Failed to get raw FD: {e}"))?, + ), + ); + let hint_pipe = PipeHandle::new( + FileDescriptor::Wildcard( + hint_reader.as_raw_fd().try_into().map_err(|e| anyhow!("Failed to get raw FD: {e}"))?, + ), + FileDescriptor::Wildcard( + hint_writer.as_raw_fd().try_into().map_err(|e| anyhow!("Failed to get raw FD: {e}"))?, + ), + ); + + Ok((preimage_pipe, hint_pipe, vec![po_reader, po_writer, hint_reader, hint_writer])) +} + +/// Returns an HTTP provider for the given URL. +pub(crate) fn http_provider(url: &str) -> ReqwestProvider { + let url = url.parse().unwrap(); + let http = Http::::new(url); + ReqwestProvider::new(RpcClient::new(http, true)) +} diff --git a/bin/programs/client/Cargo.toml b/bin/programs/client/Cargo.toml new file mode 100644 index 0000000000..f52d1606a2 --- /dev/null +++ b/bin/programs/client/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "kona-client" +version = "0.1.0" +edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true + +[dependencies] +cfg-if.workspace = true +kona-common = { path = "../../../crates/common" } +kona-common-proc = { path = "../../../crates/common-proc" } diff --git a/bin/programs/client/README.md b/bin/programs/client/README.md new file mode 100644 index 0000000000..96377ce995 --- /dev/null +++ b/bin/programs/client/README.md @@ -0,0 +1,3 @@ +# `kona-client` + +This binary contains the client program for executing the Optimism rollup state transition. diff --git a/bin/programs/client/src/main.rs b/bin/programs/client/src/main.rs new file mode 100644 index 0000000000..015eaa605b --- /dev/null +++ b/bin/programs/client/src/main.rs @@ -0,0 +1,12 @@ +#![no_std] +#![cfg_attr(any(target_arch = "mips", target_arch = "riscv64"), no_main)] + +use kona_common::io; +use kona_common_proc::client_entry; + +extern crate alloc; + +#[client_entry(0x77359400)] +fn main() { + io::print("Hello, world!\n"); +} diff --git a/bin/programs/optimism/.gitkeep b/bin/programs/optimism/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bin/programs/optimism/README.md b/bin/programs/optimism/README.md deleted file mode 100644 index b02ed7f3c9..0000000000 --- a/bin/programs/optimism/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# `kona-optimism` - -This binary contains the client program for executing the Optimism rollup state transition. - -## Modes - -The `kona-optimism` program supports several different modes, each with a separate purpose: - -| Name | Description | -| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `online` | Directly fetches external data from trusted providers. To be invoked without the `host` program on native hardware. | -| `fault` | Fetches in external data over the wire through the [`PreimageOracle` ABI][preimage-oracle-abi], supported by the `kona-host` program. Can run on native hardware or one of the supported [Fault Proof VM][fpvm] soft-CPUs. | - -[preimage-oracle-abi]: https://specs.optimism.io/experimental/fault-proof/index.html#pre-image-oracle -[fpvm]: https://static.optimism.io/kona/fpp-dev/targets.html diff --git a/crates/common/src/types.rs b/crates/common/src/types.rs index 1c7952d68d..6a5e43157d 100644 --- a/crates/common/src/types.rs +++ b/crates/common/src/types.rs @@ -17,7 +17,7 @@ pub enum FileDescriptor { PreimageRead, /// Write-only. Used to request pre-images. PreimageWrite, - /// Other file descriptor, usually used for testing purposes. + /// Other file descriptor. Wildcard(usize), } diff --git a/crates/mpt/src/lib.rs b/crates/mpt/src/lib.rs index 60fdbda3a1..628f5a1bc6 100644 --- a/crates/mpt/src/lib.rs +++ b/crates/mpt/src/lib.rs @@ -15,5 +15,8 @@ pub use node::TrieNode; mod list_walker; pub use list_walker::OrderedListWalker; +mod util; +pub use util::ordered_trie_with_encoder; + #[cfg(test)] mod test_util; diff --git a/crates/mpt/src/list_walker.rs b/crates/mpt/src/list_walker.rs index 68bd676a52..7671eb227c 100644 --- a/crates/mpt/src/list_walker.rs +++ b/crates/mpt/src/list_walker.rs @@ -147,9 +147,9 @@ impl Iterator for OrderedListWalker { #[cfg(test)] mod test { use super::*; - use crate::test_util::{ - get_live_derivable_receipts_list, get_live_derivable_transactions_list, + use crate::{ ordered_trie_with_encoder, + test_util::{get_live_derivable_receipts_list, get_live_derivable_transactions_list}, }; use alloc::{collections::BTreeMap, string::String, vec::Vec}; use alloy_consensus::{ReceiptEnvelope, TxEnvelope}; diff --git a/crates/mpt/src/node.rs b/crates/mpt/src/node.rs index 653ce2350c..a34edabaad 100644 --- a/crates/mpt/src/node.rs +++ b/crates/mpt/src/node.rs @@ -364,7 +364,7 @@ fn rlp_list_element_length(buf: &mut &[u8]) -> alloy_rlp::Result { #[cfg(test)] mod test { use super::*; - use crate::{test_util::ordered_trie_with_encoder, TrieNode}; + use crate::{ordered_trie_with_encoder, TrieNode}; use alloc::{collections::BTreeMap, vec, vec::Vec}; use alloy_primitives::{b256, bytes, hex, keccak256, Bytes, B256}; use alloy_rlp::{Decodable, Encodable, EMPTY_STRING_CODE}; diff --git a/crates/mpt/src/test_util.rs b/crates/mpt/src/test_util.rs index 454dc59ed3..9b6812478d 100644 --- a/crates/mpt/src/test_util.rs +++ b/crates/mpt/src/test_util.rs @@ -2,64 +2,17 @@ extern crate std; +use crate::ordered_trie_with_encoder; use alloc::{collections::BTreeMap, vec::Vec}; use alloy_consensus::{Receipt, ReceiptEnvelope, ReceiptWithBloom, TxEnvelope, TxType}; use alloy_primitives::{keccak256, Bytes, Log, B256}; use alloy_provider::{network::eip2718::Encodable2718, Provider, ProviderBuilder}; -use alloy_rlp::{BufMut, Encodable}; use alloy_rpc_types::BlockTransactions; -use alloy_trie::{HashBuilder, Nibbles}; use anyhow::{anyhow, Result}; use reqwest::Url; const RPC_URL: &str = "https://docs-demo.quiknode.pro/"; -/// Compute a trie root of the collection of items with a custom encoder. -pub(crate) fn ordered_trie_with_encoder(items: &[T], mut encode: F) -> HashBuilder -where - F: FnMut(&T, &mut dyn BufMut), -{ - let mut index_buffer = Vec::new(); - let mut value_buffer = Vec::new(); - let items_len = items.len(); - - // Store preimages for all intermediates - let path_nibbles = (0..items_len) - .map(|i| { - let i = adjust_index_for_rlp(i, items_len); - index_buffer.clear(); - i.encode(&mut index_buffer); - Nibbles::unpack(&index_buffer) - }) - .collect::>(); - - let mut hb = HashBuilder::default().with_proof_retainer(path_nibbles); - for i in 0..items_len { - let index = adjust_index_for_rlp(i, items_len); - - index_buffer.clear(); - index.encode(&mut index_buffer); - - value_buffer.clear(); - encode(&items[index], &mut value_buffer); - - hb.add_leaf(Nibbles::unpack(&index_buffer), &value_buffer); - } - - hb -} - -/// Adjust the index of an item for rlp encoding. -pub(crate) const fn adjust_index_for_rlp(i: usize, len: usize) -> usize { - if i > 0x7f { - i - } else if i == 0x7f || i + 1 == len { - 0 - } else { - i + 1 - } -} - /// Grabs a live merkleized receipts list within a block header. pub(crate) async fn get_live_derivable_receipts_list( ) -> Result<(B256, BTreeMap, Vec)> { diff --git a/crates/mpt/src/util.rs b/crates/mpt/src/util.rs new file mode 100644 index 0000000000..e7c15201cb --- /dev/null +++ b/crates/mpt/src/util.rs @@ -0,0 +1,51 @@ +//! Utilities for `kona-mpt` + +use alloc::vec::Vec; +use alloy_rlp::{BufMut, Encodable}; +use alloy_trie::{HashBuilder, Nibbles}; + +/// Compute a trie root of the collection of items with a custom encoder. +pub fn ordered_trie_with_encoder(items: &[T], mut encode: F) -> HashBuilder +where + F: FnMut(&T, &mut dyn BufMut), +{ + let mut index_buffer = Vec::new(); + let mut value_buffer = Vec::new(); + let items_len = items.len(); + + // Store preimages for all intermediates + let path_nibbles = (0..items_len) + .map(|i| { + let i = adjust_index_for_rlp(i, items_len); + index_buffer.clear(); + i.encode(&mut index_buffer); + Nibbles::unpack(&index_buffer) + }) + .collect::>(); + + let mut hb = HashBuilder::default().with_proof_retainer(path_nibbles); + for i in 0..items_len { + let index = adjust_index_for_rlp(i, items_len); + + index_buffer.clear(); + index.encode(&mut index_buffer); + + value_buffer.clear(); + encode(&items[index], &mut value_buffer); + + hb.add_leaf(Nibbles::unpack(&index_buffer), &value_buffer); + } + + hb +} + +/// Adjust the index of an item for rlp encoding. +pub(crate) const fn adjust_index_for_rlp(i: usize, len: usize) -> usize { + if i > 0x7f { + i + } else if i == 0x7f || i + 1 == len { + 0 + } else { + i + 1 + } +} diff --git a/crates/preimage/src/hint.rs b/crates/preimage/src/hint.rs index 35a2f07b88..49f871588c 100644 --- a/crates/preimage/src/hint.rs +++ b/crates/preimage/src/hint.rs @@ -61,7 +61,7 @@ impl HintReader { #[async_trait::async_trait] impl HintReaderServer for HintReader { - async fn next_hint(&mut self, mut route_hint: F) -> Result<()> + async fn next_hint(&self, mut route_hint: F) -> Result<()> where F: FnMut(String) -> Fut + Send, Fut: Future> + Send, @@ -141,7 +141,7 @@ mod test { const MOCK_DATA: &str = "test-hint 0xfacade"; let sys = client_and_host(); - let (hint_writer, mut hint_reader) = (sys.hint_writer, sys.hint_reader); + let (hint_writer, hint_reader) = (sys.hint_writer, sys.hint_reader); let incoming_hints = Arc::new(Mutex::new(Vec::new())); let client = tokio::task::spawn(async move { hint_writer.write(MOCK_DATA) }); diff --git a/crates/preimage/src/key.rs b/crates/preimage/src/key.rs index c6ebe0d72c..b0a05b4d85 100644 --- a/crates/preimage/src/key.rs +++ b/crates/preimage/src/key.rs @@ -91,6 +91,13 @@ impl From for [u8; 32] { } } +impl From for B256 { + fn from(value: PreimageKey) -> Self { + let raw: [u8; 32] = value.into(); + B256::from(raw) + } +} + impl TryFrom<[u8; 32]> for PreimageKey { type Error = anyhow::Error; diff --git a/crates/preimage/src/oracle.rs b/crates/preimage/src/oracle.rs index 2fa6eb3c45..87494d231f 100644 --- a/crates/preimage/src/oracle.rs +++ b/crates/preimage/src/oracle.rs @@ -1,5 +1,5 @@ use crate::{PipeHandle, PreimageKey, PreimageOracleClient, PreimageOracleServer}; -use alloc::{boxed::Box, sync::Arc, vec::Vec}; +use alloc::{boxed::Box, vec::Vec}; use anyhow::{bail, Result}; use core::future::Future; use tracing::debug; @@ -88,10 +88,10 @@ impl OracleServer { #[async_trait::async_trait] impl PreimageOracleServer for OracleServer { - async fn next_preimage_request(&mut self, mut get_preimage: F) -> Result<()> + async fn next_preimage_request(&self, mut get_preimage: F) -> Result<()> where F: FnMut(PreimageKey) -> Fut + Send, - Fut: Future>>> + Send, + Fut: Future>> + Send, { // Read the preimage request from the client, and throw early if there isn't is any. let mut buf = [0u8; 32]; @@ -123,6 +123,7 @@ mod test { use super::*; use crate::PreimageKeyType; + use alloc::sync::Arc; use alloy_primitives::keccak256; use core::pin::Pin; use kona_common::FileDescriptor; @@ -174,13 +175,13 @@ mod test { let preimages = { let mut preimages = HashMap::new(); - preimages.insert(key_a, Arc::new(MOCK_DATA_A.to_vec())); - preimages.insert(key_b, Arc::new(MOCK_DATA_B.to_vec())); + preimages.insert(key_a, MOCK_DATA_A.to_vec()); + preimages.insert(key_b, MOCK_DATA_B.to_vec()); Arc::new(Mutex::new(preimages)) }; let sys = client_and_host(); - let (oracle_reader, mut oracle_server) = (sys.oracle_reader, sys.oracle_server); + let (oracle_reader, oracle_server) = (sys.oracle_reader, sys.oracle_server); let client = tokio::task::spawn(async move { let contents_a = oracle_reader.get(key_a).unwrap(); @@ -194,20 +195,19 @@ mod test { }); let host = tokio::task::spawn(async move { #[allow(clippy::type_complexity)] - let get_preimage = move |key: PreimageKey| -> Pin< - Box>>> + Send>, - > { - let preimages = Arc::clone(&preimages); - Box::pin(async move { - // Simulate fetching preimage data - preimages - .lock() - .await - .get(&key) - .ok_or(anyhow::anyhow!("Preimage not available")) - .cloned() - }) - }; + let get_preimage = + move |key: PreimageKey| -> Pin>> + Send>> { + let preimages = Arc::clone(&preimages); + Box::pin(async move { + // Simulate fetching preimage data + preimages + .lock() + .await + .get(&key) + .ok_or(anyhow::anyhow!("Preimage not available")) + .cloned() + }) + }; loop { if oracle_server.next_preimage_request(&get_preimage).await.is_err() { diff --git a/crates/preimage/src/pipe.rs b/crates/preimage/src/pipe.rs index a6dabe208c..4fa8ea8ba6 100644 --- a/crates/preimage/src/pipe.rs +++ b/crates/preimage/src/pipe.rs @@ -49,4 +49,14 @@ impl PipeHandle { } Ok(written) } + + /// Returns the read handle for the pipe. + pub fn read_handle(&self) -> FileDescriptor { + self.read_handle + } + + /// Returns the write handle for the pipe. + pub fn write_handle(&self) -> FileDescriptor { + self.write_handle + } } diff --git a/crates/preimage/src/traits.rs b/crates/preimage/src/traits.rs index 88f79ef0ce..bede547e22 100644 --- a/crates/preimage/src/traits.rs +++ b/crates/preimage/src/traits.rs @@ -1,5 +1,5 @@ use crate::PreimageKey; -use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}; +use alloc::{boxed::Box, string::String, vec::Vec}; use anyhow::Result; use core::future::Future; @@ -44,10 +44,10 @@ pub trait PreimageOracleServer { /// # Returns /// - `Ok(())` if the data was successfully written into the client pipe. /// - `Err(_)` if the data could not be written to the client. - async fn next_preimage_request(&mut self, get_preimage: F) -> Result<()> + async fn next_preimage_request(&self, get_preimage: F) -> Result<()> where F: FnMut(PreimageKey) -> Fut + Send, - Fut: Future>>> + Send; + Fut: Future>> + Send; } /// A [HintReaderServer] is a high-level interface to read preimage hints from the @@ -60,7 +60,7 @@ pub trait HintReaderServer { /// - `Ok(())` if the hint was received and the client was notified of the host's /// acknowledgement. /// - `Err(_)` if the hint was not received correctly. - async fn next_hint(&mut self, route_hint: F) -> Result<()> + async fn next_hint(&self, route_hint: F) -> Result<()> where F: FnMut(String) -> Fut + Send, Fut: Future> + Send;