diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2800e842..66e497538 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: profile: minimal toolchain: nightly-2024-01-25 override: true - - run: cargo test -p raiko-lib --features=taiko,std + - run: cargo test -p raiko-lib --features=std clippy: name: clippy @@ -93,5 +93,3 @@ jobs: - uses: actions/checkout@v4 - uses: risc0/risc0/.github/actions/rustup@release-0.19 - run: cargo fmt --all --check - - diff --git a/Cargo.lock b/Cargo.lock index 4facd5783..ec76445e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,20 +80,21 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-eips", - "alloy-network", "alloy-primitives", "alloy-rlp", + "alloy-serde", "serde", + "sha2", ] [[package]] name = "alloy-dyn-abi" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2919acdad13336bc5dc26b636cdd6892c2f27fb0d4a58320a00c2713cf6a4e9a" +checksum = "872f239c15befa27cc4f0d3d82a70b3365c2d0202562bf906eb93b299fa31882" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -107,19 +108,31 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "alloy-rlp", + "alloy-serde", + "c-kzg", + "once_cell", + "serde", +] + +[[package]] +name = "alloy-genesis" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "alloy-serde", "serde", - "thiserror", ] [[package]] name = "alloy-json-abi" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ed0f2a6c3a1c947b4508522a53a190dba8f94dcd4e3e1a5af945a498e78f2f" +checksum = "83a35ddfd27576474322a5869e4c123e5f3e7b2177297c18e4e82ea501cb125b" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -129,7 +142,7 @@ dependencies = [ [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "serde", @@ -140,20 +153,25 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-consensus", "alloy-eips", "alloy-json-rpc", "alloy-primitives", - "alloy-rlp", + "alloy-rpc-types", + "alloy-signer", + "async-trait", + "futures-utils-wasm", "serde", + "thiserror", ] [[package]] name = "alloy-primitives" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "600d34d8de81e23b6d909c094e23b3d357e01ca36b78a8c5424c501eedbe86f0" +checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" dependencies = [ "alloy-rlp", "bytes", @@ -172,10 +190,11 @@ dependencies = [ ] [[package]] -name = "alloy-providers" +name = "alloy-provider" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-json-rpc", "alloy-network", "alloy-primitives", "alloy-rpc-client", @@ -186,13 +205,14 @@ dependencies = [ "async-stream", "async-trait", "auto_impl", + "dashmap", "futures", "lru", - "reqwest", - "serde", - "thiserror", + "reqwest 0.12.2", + "serde_json", "tokio", "tracing", + "url", ] [[package]] @@ -214,20 +234,20 @@ checksum = "1a047897373be4bbb0224c1afdabca92648dc57a9c9ef6e7b0be3aff7a859c83" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] name = "alloy-rpc-client" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-json-rpc", "alloy-transport", "alloy-transport-http", "futures", "pin-project", - "reqwest", + "reqwest 0.12.2", "serde", "serde_json", "tokio", @@ -240,10 +260,11 @@ dependencies = [ [[package]] name = "alloy-rpc-trace-types" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "alloy-rpc-types", + "alloy-serde", "serde", "serde_json", ] @@ -251,62 +272,106 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-genesis", "alloy-primitives", "alloy-rlp", + "alloy-serde", + "alloy-sol-types", "itertools 0.12.1", "serde", "serde_json", "thiserror", ] +[[package]] +name = "alloy-serde" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-signer" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "async-trait", + "auto_impl", + "elliptic-curve", + "k256", + "thiserror", +] + [[package]] name = "alloy-sol-macro" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86ec0a47740b20bc5613b8712d0d321d031c4efc58e9645af96085d5cccfc27" +checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" dependencies = [ + "alloy-sol-macro-input", "const-hex", - "dunce", "heck 0.4.1", "indexmap 2.2.6", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", "syn-solidity", "tiny-keccak", ] +[[package]] +name = "alloy-sol-macro-input" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.57", + "syn-solidity", +] + [[package]] name = "alloy-sol-type-parser" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0045cc89524e1451ccf33e8581355b6027ac7c6e494bb02959d4213ad0d8e91d" +checksum = "715f4d09a330cc181fc7c361b5c5c2766408fa59a0bac60349dcb7baabd404cc" dependencies = [ "winnow 0.6.5", ] [[package]] name = "alloy-sol-types" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad09ec5853fa700d12d778ad224dcdec636af424d29fad84fb9a2f16a5b0ef09" +checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" dependencies = [ "alloy-primitives", "alloy-sol-macro", "const-hex", - "serde", ] [[package]] name = "alloy-transport" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-json-rpc", - "base64 0.21.7", + "base64 0.22.0", + "futures-util", + "futures-utils-wasm", "serde", "serde_json", "thiserror", @@ -319,11 +384,11 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-json-rpc", "alloy-transport", - "reqwest", + "reqwest 0.12.2", "serde_json", "tower", "url", @@ -696,7 +761,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -707,7 +772,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -750,7 +815,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -801,6 +866,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64-serde" version = "0.7.0" @@ -930,7 +1001,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f0a6b186dce8b2f945bd3ecc5d35a36280400200ed57878c7c3f2aeb01632e" dependencies = [ - "reqwest", + "reqwest 0.11.27", "serde", "thiserror", "tokio", @@ -982,7 +1053,7 @@ checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1148,7 +1219,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1349,7 +1420,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1419,7 +1490,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1430,7 +1501,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1586,7 +1657,7 @@ dependencies = [ "digest 0.10.7", "futures", "rand", - "reqwest", + "reqwest 0.11.27", "thiserror", "tokio", ] @@ -1684,7 +1755,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1803,7 +1874,7 @@ dependencies = [ "regex", "serde", "serde_json", - "syn 2.0.55", + "syn 2.0.57", "toml 0.7.8", "walkdir", ] @@ -1820,7 +1891,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -1845,7 +1916,7 @@ dependencies = [ "serde", "serde_json", "strum 0.25.0", - "syn 2.0.55", + "syn 2.0.57", "tempfile", "thiserror", "tiny-keccak", @@ -1869,12 +1940,12 @@ dependencies = [ "futures-timer", "futures-util", "hashers", - "http", + "http 0.2.12", "instant", "jsonwebtoken", "once_cell", "pin-project", - "reqwest", + "reqwest 0.11.27", "serde", "serde_json", "thiserror", @@ -2027,7 +2098,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -2113,7 +2184,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -2156,6 +2227,12 @@ dependencies = [ "slab", ] +[[package]] +name = "futures-utils-wasm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" + [[package]] name = "fxhash" version = "0.2.1" @@ -2255,7 +2332,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", "indexmap 2.2.6", "slab", "tokio", @@ -2388,6 +2465,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -2395,7 +2483,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -2428,8 +2539,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -2441,6 +2552,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -2448,8 +2578,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "rustls", "tokio", "tokio-rustls", @@ -2462,12 +2592,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.28", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -2712,7 +2878,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -2762,13 +2928,12 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libredox" -version = "0.0.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.5.0", "libc", - "redox_syscall", ] [[package]] @@ -3011,7 +3176,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3105,7 +3270,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3196,7 +3361,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3592,14 +3757,14 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -3681,7 +3846,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" dependencies = [ "proc-macro2", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3821,7 +3986,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.55", + "syn 2.0.57", "tempfile", "which", ] @@ -3836,7 +4001,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -3900,22 +4065,26 @@ name = "raiko-host" version = "0.1.0" dependencies = [ "alloy-consensus", + "alloy-network", "alloy-primitives", - "alloy-providers", + "alloy-provider", "alloy-rlp", "alloy-rlp-derive", + "alloy-rpc-client", "alloy-rpc-types", "alloy-sol-types", "alloy-transport-http", "anyhow", "assert_cmd", + "bincode", + "bytemuck", "c-kzg", "cfg-if", "clap 4.5.4", "ethers-core", "flate2", "hashbrown 0.14.3", - "hyper", + "hyper 0.14.28", "lazy_static", "lru_time_cache", "once_cell", @@ -3923,7 +4092,7 @@ dependencies = [ "proptest", "raiko-lib", "raiko-primitives", - "reqwest", + "reqwest 0.11.27", "revm", "risc0-prover", "rlp", @@ -3959,7 +4128,6 @@ dependencies = [ "alloy-sol-types", "anyhow", "bincode", - "bytes", "chrono", "flate2", "hashbrown 0.14.3", @@ -3969,8 +4137,6 @@ dependencies = [ "once_cell", "raiko-primitives", "revm", - "rlp", - "ruint", "serde", "serde_json", "serde_with", @@ -3993,16 +4159,12 @@ dependencies = [ "alloy-sol-types", "anyhow", "bincode", - "bytes", "c-kzg", "hashbrown 0.14.3", - "hex", "hex-literal", - "k256", "once_cell", "revm-primitives", "rlp", - "ruint", "serde", "serde_json", "sha2", @@ -4087,9 +4249,9 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ "getrandom", "libredox", @@ -4158,11 +4320,11 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", - "hyper", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", - "hyper-tls", + "hyper-tls 0.5.0", "ipnet", "js-sys", "log", @@ -4190,10 +4352,49 @@ dependencies = [ "winreg", ] +[[package]] +name = "reqwest" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d66674f2b6fb864665eea7a3c1ac4e3dfacd2fda83cf6f935a612e01b0e3338" +dependencies = [ + "base64 0.21.7", + "bytes", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.2.0", + "hyper-tls 0.6.0", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "revm" version = "7.2.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "auto_impl", "cfg-if", @@ -4206,7 +4407,7 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "3.4.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "revm-primitives", "serde", @@ -4215,7 +4416,7 @@ dependencies = [ [[package]] name = "revm-precompile" version = "5.1.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "aurora-engine-modexp", "k256", @@ -4230,7 +4431,7 @@ dependencies = [ [[package]] name = "revm-primitives" version = "3.1.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "alloy-primitives", "auto_impl", @@ -4618,7 +4819,7 @@ dependencies = [ "regex", "relative-path", "rustc_version 0.4.0", - "syn 2.0.55", + "syn 2.0.57", "unicode-ident", ] @@ -4854,9 +5055,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -4867,9 +5068,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ "core-foundation-sys", "libc", @@ -4931,7 +5132,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -4993,7 +5194,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5018,7 +5219,7 @@ checksum = "b93fb4adc70021ac1b47f7d45e8cc4169baaa7ea58483bc5b721d19a26202212" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5056,7 +5257,6 @@ dependencies = [ "serde_json", "serde_with", "tokio", - "tracing", ] [[package]] @@ -5287,7 +5487,7 @@ dependencies = [ [[package]] name = "sp1-precompiles" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git#14bd4b2e9a2fdafc5667bfb0472dd382046e2521" +source = "git+https://github.com/succinctlabs/sp1.git#fe8df5e28ca1cb232edfb0729a2af2bf9b5a645f" dependencies = [ "anyhow", "bincode", @@ -5458,7 +5658,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5471,7 +5671,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5506,9 +5706,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35" dependencies = [ "proc-macro2", "quote", @@ -5517,14 +5717,14 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3d0961cd53c23ea94eeec56ba940f636f6394788976e9f16ca5ee0aca7464a" +checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5604,7 +5804,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5728,7 +5928,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -5922,7 +6122,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -6024,7 +6224,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http", + "http 0.2.12", "httparse", "log", "rand", @@ -6072,7 +6272,7 @@ checksum = "ac73887f47b9312552aa90ef477927ff014d63d1920ca8037c6c1951eab64bb1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -6273,7 +6473,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", "wasm-bindgen-shared", ] @@ -6307,7 +6507,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6588,7 +6788,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] @@ -6608,7 +6808,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.57", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 75d6bf704..5aae1e31a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,17 +24,102 @@ lto = true [profile.release.build-override] opt-level = 3 - [workspace.dependencies] -hashbrown = { version = "0.14", features = ["inline-more"] } -revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "unstable", default-features = false } -revm = { git = "https://github.com/taikoxyz/revm.git", branch = "unstable", default-features = false, features = [ + +# raiko +raiko-lib = { path = "./lib", features = ["std"] } +raiko-primitives = { path = "./primitives" } + +# revm +revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "fix-ecrecover", default-features = false } +revm = { git = "https://github.com/taikoxyz/revm.git", branch = "fix-ecrecover", default-features = false, features = [ "serde", + "taiko", ] } + +# risc zero +risc0-zkvm = { version = "0.20.1", features = ["prove", "getrandom"]} +bonsai-sdk = { version = "0.6.0", features = ["async"]} +risc0-build = { version = "0.20.1" } + +# SP1 sp1-core = { git = "https://github.com/succinctlabs/sp1.git", rev = "cb43fd74b24fad8ed24a4885499159de3680c89f" } sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", rev = "cb43fd74b24fad8ed24a4885499159de3680c89f" } sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", rev = "cb43fd74b24fad8ed24a4885499159de3680c89f" } -# for eip-4844 +# alloy +alloy-rlp = { version = "0.3", default-features = false } +alloy-rlp-derive = { version = "0.3", default-features = false } +alloy-core = { version = "0.7.0", default-features = false } +alloy-dyn-abi = { version = "0.7.0", default-features = false } +alloy-json-abi = { version = "0.7.0", default-features = false } +alloy-primitives = { version = "0.7.0", default-features = false } +alloy-sol-types = { version = "0.7.0", default-features = false } +alloy-rpc-types = { git = "https://github.com/brechtpd/alloy", branch = "175" } +alloy-rpc-client = { git = "https://github.com/brechtpd/alloy", branch = "175" } +alloy-consensus = { git = "https://github.com/brechtpd/alloy", branch = "175", features = ["serde"] } +alloy-network = { git = "https://github.com/brechtpd/alloy", branch = "175", features = ["k256"] } +alloy-eips = { git = "https://github.com/brechtpd/alloy", branch = "175", features = ["serde"] } +alloy-provider = { git = "https://github.com/brechtpd/alloy", branch = "175" } +alloy-transport-http = { git = "https://github.com/brechtpd/alloy", branch = "175" } + +# ethers (TODO: remove) +ethers-contract = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" } +ethers-core = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" } +ethers-providers = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" } + +# serde +serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] } +serde_json = { version = "1.0", default-features = false, features = ["alloc"] } +serde_with = { version = "3.0" } + +# tracing +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } +tracing-appender = "0.2" + +# misc +hashbrown = { version = "0.14", features = ["inline-more"] } c-kzg = "1.0.0" tempfile = "3.8" +anyhow = "1.0" +bincode = "1.3.3" +bytemuck = "1.13" +clap = { version = "4.4.6", features = ["derive", "string"] } +structopt = "0.3.26" +structopt-toml = "0.5.1" +flate2 = "1.0.28" +tokio = { version = "^1.23", features = ["full"] } +hyper = { version = "0.14.27", features = ["server"] } +tower = { version = "0.4.13", features = ["full"] } +lru_time_cache = "0.11.11" +prometheus = "0.13.3" +lazy_static = "1.4.0" +once_cell = "1.8.0" +thiserror = "1.0" +reqwest = { version = "0.11.22", features = ["json"] } +sha2 = "0.10.8" +proptest = "1.4.0" +rlp = "0.5.2" +url = "2.5.0" +cfg-if = "1.0.0" +libflate = { version = "2.0.0" } +sha3 = { version = "0.10", default-features = false } +log = { version = "0.4" } +typetag = { version = "0.2.15" } +hex = { version = "0.4.3" } +thiserror-no-std = "2.0.2" +chrono = { version = "0.4", default-features = false } +hex-literal = "0.4" +assert_cmd = "2.0" +rstest = "0.18" +rand = "0.8.5" +rand_core = "0.6.4" +base64-serde = "0.7.0" +base64 = "0.21.7" +dirs = "5.0.1" +secp256k1 = { version = "0.27.0", features = [ + 'global-context', + "rand", + "recovery", +] } diff --git a/host/Cargo.toml b/host/Cargo.toml index 7f38fc40c..f7b4f4dc6 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -5,55 +5,64 @@ edition = "2021" default-run = "raiko-host" [dependencies] -anyhow = "1.0" -alloy-rlp = { version = "0.3", default-features = false } -alloy-rlp-derive = { version = "0.3", default-features = false } -alloy-sol-types = { version = "0.6" } -alloy-primitives = { version = "0.6", default-features = false } -alloy-rpc-types = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -alloy-providers = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -alloy-transport-http = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -alloy-consensus = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -clap = { version = "4.0", features = ["derive"] } -structopt = "0.3.26" -structopt-toml = "0.5.1" -flate2 = "1.0.28" -revm = { workspace = true } -serde = "1.0" -serde_with = "3.4.0" -tokio = { version = "^1.23", features = ["full"] } -raiko-lib = { path = "../lib", features = ["taiko", "std"] } -raiko-primitives = { path = "../primitives", features = ["taiko", "c-kzg"] } -serde_json = "1.0" -hyper = { version = "0.14.27", features = ["server"] } -hashbrown = { workspace = true } -tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } -tracing-appender = "0.2" -tower = { version = "0.4.13", features = ["full"] } -lru_time_cache = "0.11.11" -prometheus = "0.13.3" -lazy_static = "1.4.0" -once_cell = "1.8.0" -thiserror = "1.0" -reqwest = "0.11.22" -sha2 = "0.10.8" -proptest = "1.4.0" -c-kzg = "1.0.0" -rlp = "0.5.2" -url = "2.5.0" -cfg-if = "1.0.0" # provers sp1-prover = { path = "../provers/sp1/prover", optional = true} risc0-prover = { path = "../provers/risc0", optional = true} sgx-prover = { path = "../provers/sgx/prover", optional = true} -[dev-dependencies] -assert_cmd = "2.0" -rstest = "0.18" -ethers-core = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10"} +# raiko +raiko-lib = { workspace = true } +raiko-primitives = { workspace = true, features = ["c-kzg"] } +# alloy +alloy-rlp = { workspace = true } +alloy-rlp-derive = { workspace = true } +alloy-sol-types = { workspace = true } +alloy-primitives = { workspace = true } +alloy-rpc-types = { workspace = true } +alloy-provider = { workspace = true } +alloy-transport-http = { workspace = true } +alloy-consensus = { workspace = true } +alloy-network = { workspace = true } +alloy-rpc-client = { workspace = true } + +# misc +anyhow = { workspace = true } +bincode = { workspace = true } +bytemuck = { workspace = true } +clap = { workspace = true } +structopt = { workspace = true } +structopt-toml = { workspace = true } +flate2 = { workspace = true } +revm = { workspace = true } +serde = { workspace = true } +serde_with = { workspace = true } +serde_json = { workspace = true } +tokio = { workspace = true } +hyper = { workspace = true } +hashbrown = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } +tracing-appender = { workspace = true } +tower = { workspace = true } +lru_time_cache = { workspace = true } +prometheus = { workspace = true } +lazy_static = { workspace = true } +once_cell = { workspace = true } +thiserror = { workspace = true } +reqwest = { workspace = true } +sha2 = { workspace = true } +proptest = { workspace = true } +c-kzg = { workspace = true } +rlp = { workspace = true } +url = { workspace = true } +cfg-if = { workspace = true } + +[dev-dependencies] +assert_cmd = { workspace = true } +rstest = { workspace = true } +ethers-core = { workspace = true } [build-dependencies] sp1-helper = { workspace = true } @@ -72,4 +81,4 @@ risc0 = [ sgx = [ "dep:sgx-prover", "sgx-prover/enable", -] \ No newline at end of file +] diff --git a/host/src/host/host.rs b/host/src/host/host.rs index 136ab5ef1..3921338fd 100644 --- a/host/src/host/host.rs +++ b/host/src/host/host.rs @@ -1,8 +1,12 @@ use std::sync::Arc; +use alloy_consensus::{ + SignableTransaction, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, TxLegacy, +}; pub use alloy_primitives::*; -use alloy_providers::tmp::{HttpProvider, TempProvider}; +use alloy_provider::{Provider, ProviderBuilder, ReqwestProvider, RootProvider}; pub use alloy_rlp as rlp; +use alloy_rpc_client::RpcClient; use alloy_rpc_types::{ Block as AlloyBlock, BlockTransactions, Filter, Transaction as AlloyRpcTransaction, }; @@ -29,128 +33,124 @@ use url::Url; use crate::host::provider_db::ProviderDb; -pub trait RlpBytes { - /// Returns the RLP-encoding. - fn to_rlp(&self) -> Vec; -} - -impl RlpBytes for T -where - T: rlp::Encodable, -{ - #[inline] - fn to_rlp(&self) -> Vec { - let rlp_length = self.length(); - let mut out = Vec::with_capacity(rlp_length); - self.encode(&mut out); - debug_assert_eq!(out.len(), rlp_length); - out - } -} - pub fn preflight( - l1_rpc_url: Option, - l2_rpc_url: Option, - l2_block_no: u64, + rpc_url: Option, + block_no: u64, network: Network, prover_data: TaikoProverData, + l1_rpc_url: Option, beacon_rpc_url: Option, ) -> Result { - let http_l2 = Http::new(Url::parse(&l2_rpc_url.clone().unwrap()).expect("invalid rpc url")); - let provider_l2: HttpProvider = HttpProvider::new(http_l2); + let http = Http::new(Url::parse(&rpc_url.clone().unwrap()).expect("invalid rpc url")); + let provider = ProviderBuilder::new().provider(RootProvider::new(RpcClient::new(http, true))); - let http_l1 = Http::new(Url::parse(&l1_rpc_url.clone().unwrap()).expect("invalid rpc url")); - let provider_l1: HttpProvider = HttpProvider::new(http_l1); - - let block = get_block(&provider_l2, l2_block_no, true).unwrap(); - let parent_block = get_block(&provider_l2, l2_block_no - 1, false).unwrap(); - - // Decode the anchor tx to find out which L1 blocks we need to fetch - let anchor_tx = match &block.transactions { - BlockTransactions::Full(txs) => txs[0].to_owned(), - _ => unreachable!(), - }; - let anchor_call = decode_anchor(anchor_tx.input.as_ref())?; - // The L1 blocks we need - let l1_state_block_no = anchor_call.l1BlockId; - let l1_inclusion_block_no = l1_state_block_no + 1; + let block = get_block(&provider, block_no, true).unwrap(); + let parent_block = get_block(&provider, block_no - 1, false).unwrap(); println!("block.hash: {:?}", block.header.hash.unwrap()); println!("block.parent_hash: {:?}", block.header.parent_hash); - println!("anchor L1 block id: {:?}", anchor_call.l1BlockId); - println!("anchor L1 state root: {:?}", anchor_call.l1StateRoot); - - // Get the L1 state block header so that we can prove the L1 state root - let l1_inclusion_block = get_block(&provider_l1, l1_inclusion_block_no, false).unwrap(); - let l1_state_block = get_block(&provider_l1, l1_state_block_no, false).unwrap(); - println!( - "l1_state_root_block hash: {:?}", - l1_state_block.header.hash.unwrap() - ); + println!("Block transactions: {:?}", block.transactions.len()); - // Get the block proposal data - let (proposal_tx, proposal_event) = get_block_proposed_event( - l1_rpc_url.clone().unwrap(), - network, - l1_inclusion_block.header.hash.unwrap(), - l2_block_no, - )?; - - // Fetch the tx list - let (tx_list, tx_blob_hash) = if proposal_event.meta.blobUsed { - println!("blob active"); - // Get the blob hashes attached to the propose tx - let blob_hashs = proposal_tx.blob_versioned_hashes; - assert!(!blob_hashs.is_empty()); - // Currently the protocol enforces the first blob hash to be used - let blob_hash = blob_hashs[0]; - - let l2_chain_spec = get_network_spec(network); - let slot_id = block_time_to_block_slot( - l1_inclusion_block.header.timestamp.as_limbs()[0], - l2_chain_spec.genesis_time, - l2_chain_spec.seconds_per_slot, + let taiko_guest_input = if network != Network::Ethereum { + let http_l1 = Http::new(Url::parse(&l1_rpc_url.clone().unwrap()).expect("invalid rpc url")); + let provider_l1 = + ProviderBuilder::new().provider(RootProvider::new(RpcClient::new(http_l1, true))); + + // Decode the anchor tx to find out which L1 blocks we need to fetch + let anchor_tx = match &block.transactions { + BlockTransactions::Full(txs) => txs[0].to_owned(), + _ => unreachable!(), + }; + let anchor_call = decode_anchor(anchor_tx.input.as_ref())?; + // The L1 blocks we need + let l1_state_block_no = anchor_call.l1BlockId; + let l1_inclusion_block_no = l1_state_block_no + 1; + + println!("anchor L1 block id: {:?}", anchor_call.l1BlockId); + println!("anchor L1 state root: {:?}", anchor_call.l1StateRoot); + + // Get the L1 state block header so that we can prove the L1 state root + let l1_inclusion_block = get_block(&provider_l1, l1_inclusion_block_no, false).unwrap(); + let l1_state_block = get_block(&provider_l1, l1_state_block_no, false).unwrap(); + println!( + "l1_state_root_block hash: {:?}", + l1_state_block.header.hash.unwrap() + ); + + // Get the block proposal data + let (proposal_tx, proposal_event) = get_block_proposed_event( + &provider_l1, + network, + l1_inclusion_block.header.hash.unwrap(), + block_no, )?; - // Get the blob data for this block - let blobs = get_blob_data(&beacon_rpc_url.clone().unwrap(), slot_id)?; - assert!(!blobs.data.is_empty(), "blob data not available anymore"); - // Get the blob data for the blob storing the tx list - let tx_blobs: Vec = blobs - .data - .iter() - .filter(|blob: &&GetBlobData| { - // calculate from plain blob - blob_hash == &calc_blob_versioned_hash(&blob.blob) - }) - .cloned() - .collect::>(); - assert!(!tx_blobs.is_empty()); - (blob_to_bytes(&tx_blobs[0].blob), Some(blob_hash)) - } else { - // Get the tx list data directly from the propose transaction data - let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false).unwrap(); - (proposal_call.txList.clone(), None) - }; - // Create the transactions from the proposed tx list - let transactions = - generate_transactions(proposal_event.meta.blobUsed, &tx_list, anchor_tx.clone()); - // Do a sanity check using the transactions returned by the node - println!("Block transactions: {:?}", block.transactions.len()); - assert!( - transactions.len() >= block.transactions.len(), - "unexpected number of transactions" - ); + // Fetch the tx list + let (tx_list, tx_blob_hash) = if proposal_event.meta.blobUsed { + println!("blob active"); + // Get the blob hashes attached to the propose tx + let blob_hashs = proposal_tx.blob_versioned_hashes.unwrap_or_default(); + assert!(!blob_hashs.is_empty()); + // Currently the protocol enforces the first blob hash to be used + let blob_hash = blob_hashs[0]; + let l2_chain_spec = get_network_spec(network); + // Get the blob data for this block + let slot_id = block_time_to_block_slot( + l1_inclusion_block.header.timestamp.as_limbs()[0], + l2_chain_spec.genesis_time, + l2_chain_spec.seconds_per_slot, + )?; + let blobs = get_blob_data(&beacon_rpc_url.clone().unwrap(), slot_id)?; + assert!(!blobs.data.is_empty(), "blob data not available anymore"); + // Get the blob data for the blob storing the tx list + let tx_blobs: Vec = blobs + .data + .iter() + .filter(|blob: &&GetBlobData| { + // calculate from plain blob + blob_hash == calc_blob_versioned_hash(&blob.blob) + }) + .cloned() + .collect::>(); + assert!(!tx_blobs.is_empty()); + (blob_to_bytes(&tx_blobs[0].blob), Some(blob_hash)) + } else { + // Get the tx list data directly from the propose transaction data + let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false).unwrap(); + (proposal_call.txList.as_ref().to_owned(), None) + }; + + // Create the transactions from the proposed tx list + let transactions = generate_transactions( + proposal_event.meta.blobUsed, + &tx_list, + Some(anchor_tx.clone()), + ); + // Do a sanity check using the transactions returned by the node + assert!( + transactions.len() >= block.transactions.len(), + "unexpected number of transactions" + ); - // Create the input struct without the block data set - let taiko_guest_input = TaikoGuestInput { - l1_header: to_header(&l1_state_block.header), - tx_list, - anchor_tx: serde_json::to_string(&anchor_tx).unwrap(), - tx_blob_hash, - block_proposed: proposal_event, - prover_data, + // Create the input struct without the block data set + TaikoGuestInput { + l1_header: to_header(&l1_state_block.header), + tx_list, + anchor_tx: serde_json::to_string(&anchor_tx).unwrap(), + tx_blob_hash, + block_proposed: proposal_event, + prover_data, + } + } else { + println!("block header: {:?}", block.header); + // For Ethereum blocks we just convert the block transactions in a tx_list + // so that we don't have to supports separate paths. + TaikoGuestInput { + tx_list: alloy_rlp::encode(&get_transactions_from_block(&block)), + ..Default::default() + } }; + let input = GuestInput { network, block_hash: block.header.hash.unwrap().0.into(), @@ -166,12 +166,23 @@ pub fn preflight( parent_header: to_header(&parent_block.header), ancestor_headers: Default::default(), base_fee_per_gas: block.header.base_fee_per_gas.unwrap().try_into().unwrap(), + blob_gas_used: if block.header.blob_gas_used.is_some() { + Some(block.header.blob_gas_used.unwrap().try_into().unwrap()) + } else { + None + }, + excess_blob_gas: if block.header.excess_blob_gas.is_some() { + Some(block.header.excess_blob_gas.unwrap().try_into().unwrap()) + } else { + None + }, + parent_beacon_block_root: block.header.parent_beacon_block_root, taiko: taiko_guest_input, }; // Create the block builder, run the transactions and extract the DB let provider_db = ProviderDb::new( - provider_l2, + provider, parent_block.header.number.unwrap().try_into().unwrap(), ); let mut builder = BlockBuilder::new(&input) @@ -228,7 +239,7 @@ fn block_time_to_block_slot( fn blob_to_bytes(blob_str: &str) -> Vec { match hex::decode(blob_str.to_lowercase().trim_start_matches("0x")) { Ok(b) => b, - Err(_) => return Vec::new(), + Err(_) => Vec::new(), } } @@ -287,7 +298,7 @@ pub struct GetBlobsResponse { pub data: Vec, } -pub fn get_block(provider: &HttpProvider, block_number: u64, full: bool) -> Result { +pub fn get_block(provider: &ReqwestProvider, block_number: u64, full: bool) -> Result { let tokio_handle = tokio::runtime::Handle::current(); let response = tokio_handle.block_on(async { provider @@ -301,13 +312,11 @@ pub fn get_block(provider: &HttpProvider, block_number: u64, full: bool) -> Resu } pub fn get_block_proposed_event( - rpc_url: String, + provider: &ReqwestProvider, network: Network, block_hash: B256, l2_block_no: u64, ) -> Result<(AlloyRpcTransaction, BlockProposed)> { - let http = Http::new(Url::parse(&rpc_url).expect("invalid rpc url")); - let provider: HttpProvider = HttpProvider::new(http); let tokio_handle = tokio::runtime::Handle::current(); // Get the address that emited the event @@ -325,14 +334,19 @@ pub fn get_block_proposed_event( .at_block_hash(block_hash) .event_signature(event_signature); // Now fetch the events - let logs = tokio_handle.block_on(async { provider.get_logs(filter).await })?; + let logs = tokio_handle.block_on(async { provider.get_logs(&filter).await })?; // Run over the logs returned to find the matching event for the specified L2 block number // (there can be multiple blocks proposed in the same block and even same tx) for log in logs { if network == Network::TaikoA6 { let event = TestnetBlockProposed::decode_log( - &Log::new(log.address, log.topics, log.data).unwrap(), + &Log::new( + log.address(), + log.topics().to_vec(), + log.data().data.clone(), + ) + .unwrap(), false, ) .unwrap(); @@ -348,7 +362,12 @@ pub fn get_block_proposed_event( } } else { let event = BlockProposed::decode_log( - &Log::new(log.address, log.topics, log.data).unwrap(), + &Log::new( + log.address(), + log.topics().to_vec(), + log.data().data.clone(), + ) + .unwrap(), false, ) .unwrap(); @@ -367,6 +386,102 @@ pub fn get_block_proposed_event( bail!("No BlockProposed event found for block {l2_block_no}"); } +fn get_transactions_from_block(block: &AlloyBlock) -> Vec { + let mut transactions: Vec = Vec::new(); + match &block.transactions { + BlockTransactions::Full(txs) => { + for tx in txs { + transactions.push(from_block_tx(tx)); + } + }, + _ => unreachable!("Block is too old, please connect to an archive node or use a block that is at most 128 blocks old."), + }; + assert!( + transactions.len() == block.transactions.len(), + "unexpected number of transactions" + ); + transactions +} + +fn from_block_tx(tx: &AlloyRpcTransaction) -> TxEnvelope { + let signature = Signature::from_rs_and_parity( + tx.signature.unwrap().r, + tx.signature.unwrap().s, + tx.signature.unwrap().v.as_limbs()[0], + ) + .unwrap(); + match tx.transaction_type.unwrap_or_default().as_limbs()[0] { + 0 => TxEnvelope::Legacy( + TxLegacy { + chain_id: tx.chain_id, + nonce: tx.nonce, + gas_price: tx.gas_price.unwrap().try_into().unwrap(), + gas_limit: tx.gas.try_into().unwrap(), + to: if tx.to.is_none() { + TxKind::Create + } else { + TxKind::Call(tx.to.unwrap()) + }, + value: tx.value, + input: tx.input.0.clone().into(), + } + .into_signed(signature), + ), + 1 => TxEnvelope::Eip2930( + TxEip2930 { + chain_id: tx.chain_id.unwrap(), + nonce: tx.nonce, + gas_price: tx.gas_price.unwrap().try_into().unwrap(), + gas_limit: tx.gas.try_into().unwrap(), + to: if tx.to.is_none() { + TxKind::Create + } else { + TxKind::Call(tx.to.unwrap()) + }, + value: tx.value, + input: tx.input.clone(), + access_list: tx.access_list.clone().unwrap_or_default(), + } + .into_signed(signature), + ), + 2 => TxEnvelope::Eip1559( + TxEip1559 { + chain_id: tx.chain_id.unwrap(), + nonce: tx.nonce, + gas_limit: tx.gas.try_into().unwrap(), + max_fee_per_gas: tx.max_fee_per_gas.unwrap().try_into().unwrap(), + max_priority_fee_per_gas: tx.max_priority_fee_per_gas.unwrap().try_into().unwrap(), + to: if tx.to.is_none() { + TxKind::Create + } else { + TxKind::Call(tx.to.unwrap()) + }, + value: tx.value, + access_list: tx.access_list.clone().unwrap_or_default(), + input: tx.input.clone(), + } + .into_signed(signature), + ), + 3 => TxEnvelope::Eip4844( + TxEip4844Variant::TxEip4844(TxEip4844 { + chain_id: tx.chain_id.unwrap(), + nonce: tx.nonce, + gas_limit: tx.gas.try_into().unwrap(), + max_fee_per_gas: tx.max_fee_per_gas.unwrap().try_into().unwrap(), + max_priority_fee_per_gas: tx.max_priority_fee_per_gas.unwrap().try_into().unwrap(), + to: tx.to.unwrap(), + value: tx.value, + access_list: tx.access_list.clone().unwrap_or_default(), + input: tx.input.clone(), + blob_versioned_hashes: tx.blob_versioned_hashes.clone().unwrap_or_default(), + max_fee_per_blob_gas: tx.max_fee_per_blob_gas.unwrap().try_into().unwrap(), + }) + .into_signed(signature), + ), + _ => unimplemented!(), + } +} + #[cfg(test)] mod test { use std::sync::Arc; @@ -613,7 +728,7 @@ mod test { #[test] fn test_slot_block_num_mapping() { - let chain_spec = get_taiko_chain_spec("testnet"); + let chain_spec = get_network_spec(Network::TaikoA6); let expected_slot = 1000u64; let second_per_slot = 12u64; let block_time = chain_spec.genesis_time + expected_slot * second_per_slot; diff --git a/host/src/host/provider_db.rs b/host/src/host/provider_db.rs index f13274225..10a900471 100644 --- a/host/src/host/provider_db.rs +++ b/host/src/host/provider_db.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. use alloy_consensus::Header as AlloyConsensusHeader; -use alloy_providers::tmp::{HttpProvider, TempProvider}; +use alloy_provider::{Provider, ReqwestProvider}; use alloy_rpc_types::{BlockId, EIP1186AccountProofResponse}; use raiko_lib::{mem_db::MemDb, taiko_utils::to_header}; use raiko_primitives::{Address, B256, U256}; @@ -25,7 +25,7 @@ use tokio::runtime::Handle; use crate::host::host::get_block; pub struct ProviderDb { - pub provider: HttpProvider, + pub provider: ReqwestProvider, pub block_number: u64, pub initial_db: MemDb, pub current_db: MemDb, @@ -33,7 +33,7 @@ pub struct ProviderDb { } impl ProviderDb { - pub fn new(provider: HttpProvider, block_number: u64) -> Self { + pub fn new(provider: ReqwestProvider, block_number: u64) -> Self { ProviderDb { provider, block_number, @@ -130,7 +130,7 @@ impl Database for ProviderDb { })?; let code = self.async_executor.block_on(async { self.provider - .get_code_at(address, Some(BlockId::from(self.block_number))) + .get_code_at(address, BlockId::from(self.block_number)) .await })?; diff --git a/host/src/main.rs b/host/src/main.rs index f004fc820..689f2486e 100644 --- a/host/src/main.rs +++ b/host/src/main.rs @@ -1,10 +1,6 @@ -#![feature(path_file_prefix)] +// Required for SP1 #![feature(generic_const_exprs)] -#![feature(absolute_path)] -#![feature(offset_of)] - -// // TODO(Cecilia): sp1 need this due to compiler versioning, fix toolchain condition on -// guest type #![feature(generic_const_exprs)] +#![allow(incomplete_features)] // Copyright 2023 RISC Zero, Inc. // diff --git a/host/src/metrics.rs b/host/src/metrics.rs index c6d139ffc..d551e0660 100644 --- a/host/src/metrics.rs +++ b/host/src/metrics.rs @@ -30,7 +30,7 @@ lazy_static! { .unwrap(); } -pub fn observe_sgx_gen(block: u64, time: i64) { +pub fn _observe_sgx_gen(block: u64, time: i64) { let bid = &block.to_string()[..]; let label = labels! { "blockid" => bid, @@ -38,7 +38,7 @@ pub fn observe_sgx_gen(block: u64, time: i64) { SGX_PROOF_GEN_TIME.with(&label).set(time); } -pub fn inc_sgx_success(block: u64) { +pub fn _inc_sgx_success(block: u64) { let bid = &block.to_string()[..]; let label = labels! { "blockid" => bid, @@ -46,7 +46,7 @@ pub fn inc_sgx_success(block: u64) { SGX_PROOF_SUCCESS_COUNTER.with(&label).inc(); } -pub fn inc_sgx_error(block: u64) { +pub fn _inc_sgx_error(block: u64) { let bid = &block.to_string()[..]; let label = labels! { "blockid" => bid, diff --git a/host/src/prover/context.rs b/host/src/prover/context.rs index 865e998cc..d9077c3ea 100644 --- a/host/src/prover/context.rs +++ b/host/src/prover/context.rs @@ -45,7 +45,7 @@ impl Context { self.l2_cache_file = Some(self.host_cache.join(file_name)); } } - pub async fn remove_cache_file(&self) -> Result<()> { + pub async fn _remove_cache_file(&self) -> Result<()> { if let Some(file) = &self.l1_cache_file { tokio::fs::remove_file(file).await?; } @@ -55,13 +55,3 @@ impl Context { Ok(()) } } - -#[cfg(test)] -mod tests { - #[test] - fn test_file_prefix() { - let path = std::path::Path::new("/tmp/ethereum/1234.l1.json.gz"); - let prefix = path.file_prefix().unwrap(); - assert_eq!(prefix, "1234"); - } -} diff --git a/host/src/prover/execution.rs b/host/src/prover/execution.rs index 0b783aef5..7095393d7 100644 --- a/host/src/prover/execution.rs +++ b/host/src/prover/execution.rs @@ -1,9 +1,9 @@ -use std::{fmt::Debug, str::FromStr, time::Instant}; +use std::{str::FromStr, time::Instant}; use raiko_lib::{ builder::{BlockBuilderStrategy, TaikoStrategy}, consts::Network, - input::{GuestInput, GuestOutput, TaikoProverData}, + input::{GuestInput, GuestOutput, TaikoProverData, WrappedHeader}, protocol_instance::{assemble_protocol_instance, ProtocolInstance}, prover::{Prover, ProverResult}, taiko_utils::HeaderHasher, @@ -35,7 +35,12 @@ pub async fn execute( let pi = D::instance_hash(assemble_protocol_instance(&input, header)?); // Make sure the blockhash from the node matches the one from the builder assert_eq!(header.hash().0, input.block_hash, "block hash unexpected"); - GuestOutput::Success((header.clone(), pi)) + GuestOutput::Success(( + WrappedHeader { + header: header.clone(), + }, + pi, + )) } Err(_) => { warn!("Proving bad block construction!"); @@ -51,24 +56,21 @@ pub async fn execute( } /// prepare input data for provers -pub async fn prepare_input

(ctx: &mut Context, req: &ProofRequest

) -> Result { - // Todo(Cecilia): should contract address as args, curently hardcode - let _l1_cache = ctx.l1_cache_file.clone(); - let _l2_cache = ctx.l2_cache_file.clone(); +pub async fn prepare_input

(_ctx: &mut Context, req: &ProofRequest

) -> Result { let block_number = req.block_number; + let rpc = req.rpc.clone(); let l1_rpc = req.l1_rpc.clone(); - let l2_rpc = req.l2_rpc.clone(); let beacon_rpc = req.beacon_rpc.clone(); let chain = req.chain.clone(); let graffiti = req.graffiti; let prover = req.prover; tokio::task::spawn_blocking(move || { preflight( - Some(l1_rpc), - Some(l2_rpc), + Some(rpc), block_number, Network::from_str(&chain).unwrap(), TaikoProverData { graffiti, prover }, + Some(l1_rpc), Some(beacon_rpc), ) .expect("Failed to fetch required data for block") diff --git a/host/src/prover/mod.rs b/host/src/prover/mod.rs index 511d85e3b..997fee3e5 100644 --- a/host/src/prover/mod.rs +++ b/host/src/prover/mod.rs @@ -1,4 +1,4 @@ -pub mod cache; +// pub mod cache; pub mod context; pub mod error; pub mod execution; diff --git a/host/src/prover/request.rs b/host/src/prover/request.rs index 37c65afda..b5f83b805 100644 --- a/host/src/prover/request.rs +++ b/host/src/prover/request.rs @@ -16,10 +16,10 @@ pub enum ProofType { #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ProofRequest

{ - /// the l2 block number + /// the block number pub block_number: u64, - /// l2 node for get block by number - pub l2_rpc: String, + /// node for get block by number + pub rpc: String, /// l1 node for signal root verify and get txlist info from proposed transaction. pub l1_rpc: String, /// beacon node for data blobs diff --git a/host/src/prover/server.rs b/host/src/prover/server.rs index e13cd6e37..716c7ab15 100644 --- a/host/src/prover/server.rs +++ b/host/src/prover/server.rs @@ -13,7 +13,6 @@ use tower::ServiceBuilder; use tracing::info; use crate::prover::{ - cache::Cache, context::Context, error::HostError, execution::execute, @@ -95,7 +94,7 @@ fn set_headers(headers: &mut hyper::HeaderMap, extended: bool) { #[derive(Clone)] struct Handler { ctx: Context, - cache: Cache, + // cache: Cache, } impl Handler { @@ -103,12 +102,12 @@ impl Handler { guest_elf: PathBuf, host_cache: PathBuf, _l2_contracts: String, - capacity: usize, + _capacity: usize, max_caches: usize, ) -> Self { Self { ctx: Context::new(guest_elf, host_cache, max_caches, None), - cache: Cache::new(capacity), + // cache: Cache::new(capacity), } } @@ -226,28 +225,27 @@ impl Handler { // enqueues a task for computating proof for any given block "proof" => { let options = params.first().expect("params must not be empty"); - let mut res = Err(HostError::GuestError("Execution failed to run".to_string())); cfg_if::cfg_if! { if #[cfg(feature = "sp1")] { use sp1_prover::Sp1Prover; let req: ProofRequest<::ProofParam> = serde_json::from_value(options.to_owned()).map_err(Into::::into)?; - res = execute::(&mut self.ctx, &req).await; + let res = execute::(&mut self.ctx, &req).await; } else if #[cfg(feature = "risc0")] { use risc0_prover::Risc0Prover; let req: ProofRequest<::ProofParam> = serde_json::from_value(options.to_owned()).map_err(Into::::into)?; - res = execute::(&mut self.ctx, &req).await; + let res = execute::(&mut self.ctx, &req).await; } else if #[cfg(feature = "sgx")] { use sgx_prover::SgxProver; let req: ProofRequest<::ProofParam> = serde_json::from_value(options.to_owned()).map_err(Into::::into)?; - res = execute::(&mut self.ctx, &req).await; + let res = execute::(&mut self.ctx, &req).await; } else { use crate::prover::execution::NativeDriver; let req: ProofRequest<::ProofParam> = serde_json::from_value(options.to_owned()).map_err(Into::::into)?; - res = execute::(&mut self.ctx, &req).await; + let res = execute::(&mut self.ctx, &req).await; } }; res.and_then(|res| serde_json::to_value(res).map_err(Into::into)) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 728bbd48f..4b765214c 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -4,44 +4,38 @@ version = "0.1.0" edition = "2021" [dependencies] -anyhow = { version = "1.0", default-features = false } -alloy-rlp = { version = "0.3", default-features = false } -alloy-rlp-derive = { version = "0.3", default-features = false } -rlp = "0.5.2" -alloy-sol-types = { version = "0.6", default-features = false } -alloy-primitives = { version = "0.6", default-features = false, features = [ - "rlp", - "serde", - "std", - "tiny-keccak", -] } -alloy-rpc-types = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -alloy-consensus = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -alloy-network = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize", features = ["k256"] } -bytes = {version = "1.5", default-features = false} +raiko-primitives = { workspace = true } + +alloy-rlp = { workspace = true } +alloy-rlp-derive = { workspace = true } +alloy-sol-types = { workspace = true } +alloy-primitives = { workspace = true } +alloy-rpc-types = { workspace = true } +alloy-consensus = { workspace = true } +alloy-network = { workspace = true } + +anyhow = { workspace = true } hashbrown = { workspace = true } -libflate = { version = "2.0.0" } -once_cell = { version = "1.18", default-features = false } -revm = { workspace = true, default-features = false } -ruint = { version = "1.10", default-features = false } -serde = { version = "1.0", default-features = false, features = ["alloc"] } -thiserror-no-std = "2.0.2" -raiko-primitives = { path = "../primitives", default-features = false} -hex = { version = "0.4.3", default-features = false, optional = true } -url = "2.5.0" +libflate = { workspace = true } +once_cell = { workspace = true } +revm = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true, optional = true } +serde_with = { workspace = true, optional = true } +thiserror-no-std = { workspace = true } +url = { workspace = true } +hex = { workspace = true } # [target.'cfg(feature = "std")'.dependencies] -thiserror = {version = "1.0", optional = true} -flate2 = {version = "1.0.26", optional = true} -log = {version = "0.4", optional = true} -serde_json = { version = "1.0", default-features = false, features = ["alloc"] , optional = true} -serde_with = {version = "3.0", optional = true} -tokio = { version = "1.23", features = ["full"], optional = true} -chrono = { version = "0.4", default-features = false, optional = true } +thiserror = { workspace = true, optional = true } +flate2 = { workspace = true, optional = true } +log = { workspace = true, optional = true } + +tokio = { workspace = true, optional = true } +chrono = { workspace = true, optional = true } [dev-dependencies] bincode = "1.3" -serde_with = "3.1" [features] std = [ @@ -56,8 +50,3 @@ std = [ "dep:serde_with", # "dep:tokio", ] -taiko = [ - "raiko-primitives/taiko", - "revm/taiko", - "dep:hex", - ] diff --git a/lib/src/builder/execute.rs b/lib/src/builder/execute.rs index 0b00dd816..656c339f1 100644 --- a/lib/src/builder/execute.rs +++ b/lib/src/builder/execute.rs @@ -14,19 +14,23 @@ use core::{fmt::Debug, mem::take, str::from_utf8}; -use alloy_consensus::{TxEnvelope, TxKind}; -use anyhow::{anyhow, bail, Context, Error, Result}; +use alloy_consensus::{constants::BEACON_ROOTS_ADDRESS, TxEnvelope}; +use alloy_primitives::{TxKind, U256}; +use anyhow::{anyhow, bail, ensure, Context, Error, Result}; #[cfg(feature = "std")] use log::debug; -use raiko_primitives::{mpt::MptNode, receipt::Receipt, Bloom, Rlp2718Bytes, RlpBytes}; +use raiko_primitives::{ + alloy_eips::eip4788::SYSTEM_ADDRESS, mpt::MptNode, receipt::Receipt, Bloom, Rlp2718Bytes, + RlpBytes, +}; use revm::{ interpreter::Host, primitives::{ Account, Address, EVMError, HandlerCfg, ResultAndState, SpecId, TransactTo, TxEnv, + MAX_BLOB_GAS_PER_BLOCK, }, taiko, Database, DatabaseCommit, Evm, }; -use ruint::aliases::U256; use super::TxExecStrategy; use crate::{ @@ -36,8 +40,8 @@ use crate::{ taiko_utils::{check_anchor_tx, generate_transactions}, }; -/// Minimum supported protocol version: Bedrock (Block no. 105235063). -const MIN_SPEC_ID: SpecId = SpecId::SHANGHAI /*change*/; +/// Minimum supported protocol version: SHANGHAI +const MIN_SPEC_ID: SpecId = SpecId::SHANGHAI; pub struct TkoTxExecStrategy {} @@ -52,22 +56,36 @@ impl TxExecStrategy for TkoTxExecStrategy { .as_mut() .expect("Header is not initialized"); // Compute the spec id - let spec_id = block_builder.chain_spec.spec_id(header.number); + let spec_id = block_builder + .chain_spec + .active_fork(header.number, header.timestamp) + .unwrap(); if !SpecId::enabled(spec_id, MIN_SPEC_ID) { bail!("Invalid protocol version: expected >= {MIN_SPEC_ID:?}, got {spec_id:?}") } let chain_id = block_builder.chain_spec.chain_id(); + println!("spec_id: {:?}", spec_id); + + let network = block_builder.input.network; + let is_taiko = network != Network::Ethereum; // generate the transactions from the tx list + // For taiko blocks, insert the anchor tx as the first transaction + let anchor_tx = if block_builder.input.network == Network::Ethereum { + None + } else { + Some(serde_json::from_str(&block_builder.input.taiko.anchor_tx.clone()).unwrap()) + }; let mut transactions = generate_transactions( block_builder.input.taiko.block_proposed.meta.blobUsed, &block_builder.input.taiko.tx_list, - serde_json::from_str(&block_builder.input.taiko.anchor_tx.clone()).unwrap(), + anchor_tx, ); - let mut evm = Evm::builder() + // Setup the EVM environment + let evm = Evm::builder() .with_db(block_builder.db.take().unwrap()) - .with_handler_cfg(HandlerCfg::new_with_taiko(spec_id, true)) + .with_handler_cfg(HandlerCfg::new_with_taiko(spec_id, is_taiko)) .modify_cfg_env(|cfg_env| { // set the EVM configuration cfg_env.chain_id = chain_id; @@ -81,63 +99,100 @@ impl TxExecStrategy for TkoTxExecStrategy { blk_env.prevrandao = Some(header.mix_hash); blk_env.basefee = header.base_fee_per_gas.unwrap().try_into().unwrap(); blk_env.gas_limit = block_builder.input.gas_limit.try_into().unwrap(); - }) - .append_handler_register(taiko::handler_register::taiko_handle_register) - .build(); + if let Some(excess_blob_gas) = header.excess_blob_gas { + blk_env.set_blob_excess_gas_and_price(excess_blob_gas) + } + }); + let evm = if is_taiko { + evm.append_handler_register(taiko::handler_register::taiko_handle_register) + } else { + evm + }; + let mut evm = evm.build(); + + // Set the beacon block root in the EVM + if spec_id >= SpecId::CANCUN { + let parent_beacon_block_root = header.parent_beacon_block_root.unwrap(); + + // From EIP-4788 Beacon block root in the EVM (Cancun): + // "Call BEACON_ROOTS_ADDRESS as SYSTEM_ADDRESS with the 32-byte input of + // header.parent_beacon_block_root, a gas limit of 30_000_000, and 0 value." + evm.env_mut().tx = TxEnv { + transact_to: TransactTo::Call(BEACON_ROOTS_ADDRESS), + caller: SYSTEM_ADDRESS, + data: parent_beacon_block_root.0.into(), + gas_limit: 30_000_000, + value: U256::ZERO, + ..Default::default() + }; + + let tmp = evm.env_mut().block.clone(); + + // disable block gas limit validation and base fee checks + evm.block_mut().gas_limit = U256::from(evm.tx().gas_limit); + evm.block_mut().basefee = U256::ZERO; + + let ResultAndState { mut state, .. } = + evm.transact().expect("beacon roots contract call failed"); + evm.env_mut().block = tmp; + + // commit only the changes to the beacon roots contract + state.remove(&SYSTEM_ADDRESS); + state.remove(&evm.block().coinbase); + evm.context.evm.db.commit(state); + } // bloom filter over all transaction logs let mut logs_bloom = Bloom::default(); // keep track of the gas used over all transactions let mut cumulative_gas_used = 0u64; + let mut blob_gas_used = 0_u64; // process all the transactions let mut tx_trie = MptNode::default(); let mut receipt_trie = MptNode::default(); // track the actual tx number to use in the tx/receipt trees as the key let mut actual_tx_no = 0usize; + let num_transactions = transactions.len(); for (tx_no, tx) in take(&mut transactions).into_iter().enumerate() { + println!("tx {tx_no}/{num_transactions}"); // anchor transaction always the first transaction - let is_anchor = tx_no == 0; - - // TODO(Brecht): use optimized recover - let (tx_gas_limit, from) = match &tx { - TxEnvelope::Legacy(tx) => (tx.gas_limit, tx.recover_signer()), - TxEnvelope::TaggedLegacy(tx) => (tx.gas_limit, tx.recover_signer()), - TxEnvelope::Eip2930(tx) => (tx.gas_limit, tx.recover_signer()), - TxEnvelope::Eip1559(tx) => (tx.gas_limit, tx.recover_signer()), - TxEnvelope::Eip4844(tx) => (tx.tx().tx().gas_limit, tx.recover_signer()), - }; - // Get the tx type as a number - let tx_type = match tx.tx_type() { - alloy_consensus::TxType::Legacy => 0, - alloy_consensus::TxType::Eip2930 => 1, - alloy_consensus::TxType::Eip1559 => 2, - alloy_consensus::TxType::Eip4844 => 3, - }; + let is_anchor = is_taiko && tx_no == 0; + + // setup the EVM environment + let tx_env = &mut evm.env_mut().tx; + fill_eth_tx_env(tx_env, &tx)?; + // Set and check some taiko specific values + if network != Network::Ethereum { + // set if the tx is the anchor tx + tx_env.taiko.is_anchor = is_anchor; + // set the treasury address + tx_env.taiko.treasury = get_network_spec(network).l2_contract.unwrap_or_default(); + + // Data blobs are not allowed on L2 + ensure!(tx_env.blob_hashes.len() == 0); + } - // verify the transaction signature - let tx_from = match from { - Ok(tx_from) => tx_from, - Err(err) => { - if is_anchor { - bail!("Error recovering anchor signature: {}", err); - } - #[cfg(feature = "std")] - debug!( - "Error recovering address for transaction {}, error: {}", - tx_no, err - ); - // If the signature is not valid, skip the transaction - continue; + // if the sigature was not valid, the caller address will have been set to zero + if tx_env.caller == Address::ZERO { + if is_anchor { + bail!("Error recovering anchor signature"); } - }; + #[cfg(feature = "std")] + debug!("Error recovering address for transaction {}", tx_no); + if !is_taiko { + bail!("invalid signature"); + } + // If the signature is not valid, skip the transaction + continue; + } // verify the anchor tx if is_anchor { check_anchor_tx( &block_builder.input, &tx, - &tx_from, + &tx_env.caller, block_builder.input.network, ) .expect("invalid anchor tx"); @@ -145,27 +200,36 @@ impl TxExecStrategy for TkoTxExecStrategy { // verify transaction gas let block_available_gas = block_builder.input.gas_limit - cumulative_gas_used; - if block_available_gas < tx_gas_limit.try_into().unwrap() { + if block_available_gas < tx_env.gas_limit { if is_anchor { bail!("Error at transaction {}: gas exceeds block limit", tx_no); } #[cfg(feature = "std")] debug!("Error at transaction {}: gas exceeds block limit", tx_no); + if !is_taiko { + bail!("gas exceeds block limit"); + } continue; } - // setup the transaction - fill_eth_tx_env( - block_builder.input.network, - &mut evm.env_mut().tx, - &tx, - tx_from, - is_anchor, - )?; + // verify blob gas + if let TxEnvelope::Eip4844(blob_tx) = &tx { + let tx = blob_tx.tx().tx(); + blob_gas_used = blob_gas_used.checked_add(tx.blob_gas()).unwrap(); + ensure!( + blob_gas_used <= MAX_BLOB_GAS_PER_BLOCK, + "Error at transaction {}: total blob gas spent exceeds the limit", + tx_no + ); + } + // process the transaction let ResultAndState { result, state } = match evm.transact() { Ok(result) => result, Err(err) => { + if !is_taiko { + bail!("tx failed to execute successfully: {:?}", err); + } if is_anchor { bail!("Anchor tx failed to execute successfully: {:?}", err); } @@ -197,19 +261,15 @@ impl TxExecStrategy for TkoTxExecStrategy { } // keep track of all the gas used in the block - let gas_used = result.gas_used().try_into().unwrap(); + let gas_used = result.gas_used(); cumulative_gas_used = cumulative_gas_used.checked_add(gas_used).unwrap(); // create the receipt from the EVM result let receipt = Receipt::new( - tx_type, + tx.tx_type() as u8, result.is_success(), cumulative_gas_used.try_into().unwrap(), - result - .logs() - .into_iter() - .map(|log| log.clone().into()) - .collect(), + result.logs().iter().map(|log| log.clone().into()).collect(), ); // update the state @@ -219,7 +279,7 @@ impl TxExecStrategy for TkoTxExecStrategy { logs_bloom.accrue_bloom(&receipt.payload.logs_bloom); // Add receipt and tx to tries - let trie_key = actual_tx_no.to_rlp(); + let trie_key = alloy_rlp::encode(actual_tx_no); // Add to tx trie tx_trie.insert_rlp_encoded(&trie_key, tx.to_rlp_2718())?; // Add to receipt trie @@ -254,12 +314,13 @@ impl TxExecStrategy for TkoTxExecStrategy { header.transactions_root = tx_trie.hash(); header.receipts_root = receipt_trie.hash(); header.logs_bloom = logs_bloom; - header.gas_used = cumulative_gas_used.try_into().unwrap(); - header.withdrawals_root = if spec_id < SpecId::SHANGHAI { - None - } else { - Some(withdrawals_trie.hash()) + header.gas_used = cumulative_gas_used; + if spec_id >= SpecId::SHANGHAI { + header.withdrawals_root = Some(withdrawals_trie.hash()); }; + if spec_id >= SpecId::CANCUN { + header.blob_gas_used = Some(blob_gas_used); + } // Leak memory, save cycles guest_mem_forget([tx_trie, receipt_trie, withdrawals_trie]); @@ -268,37 +329,18 @@ impl TxExecStrategy for TkoTxExecStrategy { } } -pub fn fill_eth_tx_env( - network: Network, - tx_env: &mut TxEnv, - tx: &TxEnvelope, - caller: Address, - is_anchor: bool, -) -> Result<(), Error> { - // claim the anchor - tx_env.taiko.is_anchor = is_anchor; - // set the treasury address - tx_env.taiko.treasury = get_network_spec(network).l2_contract.unwrap(); - - tx_env.caller = caller; +pub fn fill_eth_tx_env(tx_env: &mut TxEnv, tx: &TxEnvelope) -> Result<(), Error> { + // Clear values that may not be set + tx_env.access_list.clear(); + tx_env.blob_hashes.clear(); + tx_env.max_fee_per_blob_gas.take(); + // Get the data from the tx + // TODO(Brecht): use optimized recover match tx { TxEnvelope::Legacy(tx) => { - tx_env.gas_limit = tx.gas_limit.try_into().unwrap(); - tx_env.gas_price = tx.gas_price.try_into().unwrap(); - tx_env.gas_priority_fee = None; - tx_env.transact_to = if let TxKind::Call(to_addr) = tx.to { - TransactTo::Call(to_addr) - } else { - TransactTo::create() - }; - tx_env.value = tx.value; - tx_env.data = tx.input.clone(); - tx_env.chain_id = tx.chain_id; - tx_env.nonce = Some(tx.nonce); - tx_env.access_list.clear(); - } - TxEnvelope::TaggedLegacy(tx) => { - tx_env.gas_limit = tx.gas_limit.try_into().unwrap(); + tx_env.caller = tx.recover_signer().unwrap_or_default(); + let tx = tx.tx(); + tx_env.gas_limit = tx.gas_limit; tx_env.gas_price = tx.gas_price.try_into().unwrap(); tx_env.gas_priority_fee = None; tx_env.transact_to = if let TxKind::Call(to_addr) = tx.to { @@ -313,7 +355,9 @@ pub fn fill_eth_tx_env( tx_env.access_list.clear(); } TxEnvelope::Eip2930(tx) => { - tx_env.gas_limit = tx.gas_limit.try_into().unwrap(); + tx_env.caller = tx.recover_signer().unwrap_or_default(); + let tx = tx.tx(); + tx_env.gas_limit = tx.gas_limit; tx_env.gas_price = tx.gas_price.try_into().unwrap(); tx_env.gas_priority_fee = None; tx_env.transact_to = if let TxKind::Call(to_addr) = tx.to { @@ -325,11 +369,12 @@ pub fn fill_eth_tx_env( tx_env.data = tx.input.clone(); tx_env.chain_id = Some(tx.chain_id); tx_env.nonce = Some(tx.nonce); - tx_env.access_list = tx.access_list.clone().into_flattened(); + tx_env.access_list = tx.access_list.flattened(); } TxEnvelope::Eip1559(tx) => { - tx_env.caller = caller; - tx_env.gas_limit = tx.gas_limit.try_into().unwrap(); + tx_env.caller = tx.recover_signer().unwrap_or_default(); + let tx = tx.tx(); + tx_env.gas_limit = tx.gas_limit; tx_env.gas_price = tx.max_fee_per_gas.try_into().unwrap(); tx_env.gas_priority_fee = Some(tx.max_priority_fee_per_gas.try_into().unwrap()); tx_env.transact_to = if let TxKind::Call(to_addr) = tx.to { @@ -341,26 +386,22 @@ pub fn fill_eth_tx_env( tx_env.data = tx.input.clone(); tx_env.chain_id = Some(tx.chain_id); tx_env.nonce = Some(tx.nonce); - tx_env.access_list = tx.access_list.clone().into_flattened(); + tx_env.access_list = tx.access_list.flattened(); } TxEnvelope::Eip4844(tx) => { + tx_env.caller = tx.recover_signer().unwrap_or_default(); let tx = tx.tx().tx(); - tx_env.gas_limit = tx.gas_limit.try_into().unwrap(); + tx_env.gas_limit = tx.gas_limit; tx_env.gas_price = tx.max_fee_per_gas.try_into().unwrap(); tx_env.gas_priority_fee = Some(tx.max_priority_fee_per_gas.try_into().unwrap()); - tx_env.transact_to = if let TxKind::Call(to_addr) = tx.to { - TransactTo::Call(to_addr) - } else { - TransactTo::create() - }; + tx_env.transact_to = TransactTo::Call(tx.to); tx_env.value = tx.value; tx_env.data = tx.input.clone(); tx_env.chain_id = Some(tx.chain_id); tx_env.nonce = Some(tx.nonce); - tx_env.access_list = tx.access_list.clone().into_flattened(); - - // Data blobs are not allowed on L2 - bail!(tx.blob_versioned_hashes.is_empty()); + tx_env.access_list = tx.access_list.flattened(); + tx_env.blob_hashes = tx.blob_versioned_hashes.clone(); + tx_env.max_fee_per_blob_gas = Some(U256::from(tx.max_fee_per_blob_gas)); } }; Ok(()) diff --git a/lib/src/builder/prepare.rs b/lib/src/builder/prepare.rs index 7e3d632cf..73c0d91e4 100644 --- a/lib/src/builder/prepare.rs +++ b/lib/src/builder/prepare.rs @@ -36,7 +36,7 @@ impl HeaderPrepStrategy for TaikoHeaderPrepStrategy { ::Error: Debug, { // Validate timestamp - let timestamp: u64 = block_builder.input.timestamp.try_into().unwrap(); + let timestamp: u64 = block_builder.input.timestamp; if timestamp < block_builder.input.parent_header.timestamp { bail!( "Invalid timestamp: expected >= {}, got {}", @@ -68,6 +68,9 @@ impl HeaderPrepStrategy for TaikoHeaderPrepStrategy { timestamp: block_builder.input.timestamp, mix_hash: block_builder.input.mix_hash, extra_data: block_builder.input.extra_data.clone(), + blob_gas_used: block_builder.input.blob_gas_used, + excess_blob_gas: block_builder.input.excess_blob_gas, + parent_beacon_block_root: block_builder.input.parent_beacon_block_root, // do not fill the remaining fields ..Default::default() }); diff --git a/lib/src/consts.rs b/lib/src/consts.rs index bcdbc435f..6e2beb7c4 100644 --- a/lib/src/consts.rs +++ b/lib/src/consts.rs @@ -17,7 +17,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, str::FromStr}; use alloy_primitives::Address; -use anyhow::bail; +use anyhow::{bail, Result}; use once_cell::unsync::Lazy; use raiko_primitives::{uint, BlockNumber, ChainId, U256}; use revm::primitives::SpecId; @@ -44,12 +44,13 @@ pub const GWEI_TO_WEI: U256 = uint!(1_000_000_000_U256); pub const ETH_MAINNET_CHAIN_SPEC: Lazy = Lazy::new(|| { ChainSpec { chain_id: 1, + max_spec_id: SpecId::CANCUN, hard_forks: BTreeMap::from([ (SpecId::FRONTIER, ForkCondition::Block(0)), // previous versions not supported (SpecId::MERGE, ForkCondition::Block(15537394)), (SpecId::SHANGHAI, ForkCondition::Block(17034870)), - (SpecId::CANCUN, ForkCondition::TBD), + (SpecId::CANCUN, ForkCondition::Timestamp(1710338135)), ]), eip_1559_constants: Eip1559Constants { base_fee_change_denominator: uint!(8_U256), @@ -68,6 +69,7 @@ pub const ETH_MAINNET_CHAIN_SPEC: Lazy = Lazy::new(|| { /// The Taiko A6 specification. pub const TAIKO_A6_CHAIN_SPEC: Lazy = Lazy::new(|| ChainSpec { chain_id: 167008, + max_spec_id: SpecId::SHANGHAI, hard_forks: BTreeMap::from([ (SpecId::SHANGHAI, ForkCondition::Block(0)), (SpecId::CANCUN, ForkCondition::TBD), @@ -90,6 +92,7 @@ pub const TAIKO_A6_CHAIN_SPEC: Lazy = Lazy::new(|| ChainSpec { /// The Taiko A7 specification. pub const TAIKO_A7_CHAIN_SPEC: Lazy = Lazy::new(|| ChainSpec { chain_id: 167009, + max_spec_id: SpecId::SHANGHAI, hard_forks: BTreeMap::from([ (SpecId::SHANGHAI, ForkCondition::Block(0)), (SpecId::CANCUN, ForkCondition::TBD), @@ -111,9 +114,9 @@ pub const TAIKO_A7_CHAIN_SPEC: Lazy = Lazy::new(|| ChainSpec { pub fn get_network_spec(network: Network) -> ChainSpec { match network { + Network::Ethereum => ETH_MAINNET_CHAIN_SPEC.clone(), Network::TaikoA6 => TAIKO_A6_CHAIN_SPEC.clone(), Network::TaikoA7 => TAIKO_A7_CHAIN_SPEC.clone(), - _ => unimplemented!("invalid chain name: {:?}", network), } } @@ -122,15 +125,18 @@ pub fn get_network_spec(network: Network) -> ChainSpec { pub enum ForkCondition { /// The fork is activated with a certain block. Block(BlockNumber), + /// The fork is activated with a specific timestamp. + Timestamp(u64), /// The fork is not yet active. TBD, } impl ForkCondition { /// Returns whether the condition has been met. - pub fn active(&self, block_number: BlockNumber) -> bool { + pub fn active(&self, block_number: BlockNumber, timestamp: u64) -> bool { match self { ForkCondition::Block(block) => *block <= block_number, + ForkCondition::Timestamp(ts) => *ts <= timestamp, ForkCondition::TBD => false, } } @@ -161,6 +167,7 @@ impl Default for Eip1559Constants { #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct ChainSpec { pub chain_id: ChainId, + pub max_spec_id: SpecId, pub hard_forks: BTreeMap, pub eip_1559_constants: Eip1559Constants, pub l1_contract: Option

, @@ -179,6 +186,7 @@ impl ChainSpec { ) -> Self { ChainSpec { chain_id, + max_spec_id: spec_id, hard_forks: BTreeMap::from([(spec_id, ForkCondition::Block(0))]), eip_1559_constants, l1_contract: None, @@ -192,19 +200,33 @@ impl ChainSpec { pub fn chain_id(&self) -> ChainId { self.chain_id } - /// Returns the revm specification ID for `block_number`. - pub fn spec_id(&self, block_number: BlockNumber) -> SpecId { - for (spec_id, fork) in self.hard_forks.iter().rev() { - if fork.active(block_number) { - return *spec_id; + /// Returns the [SpecId] for a given block number and timestamp or an error if not + /// supported. + pub fn active_fork(&self, block_number: BlockNumber, timestamp: u64) -> Result { + match self.spec_id(block_number, timestamp) { + Some(spec_id) => { + if spec_id > self.max_spec_id { + bail!("expected <= {:?}, got {:?}", self.max_spec_id, spec_id); + } else { + Ok(spec_id) + } } + None => bail!("no supported fork for block {}", block_number), } - unreachable!() } /// Returns the Eip1559 constants pub fn gas_constants(&self) -> &Eip1559Constants { &self.eip_1559_constants } + + fn spec_id(&self, block_number: BlockNumber, timestamp: u64) -> Option { + for (spec_id, fork) in self.hard_forks.iter().rev() { + if fork.active(block_number, timestamp) { + return Some(*spec_id); + } + } + None + } } #[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)] @@ -248,9 +270,18 @@ mod tests { #[test] fn revm_spec_id() { - assert!(ETH_MAINNET_CHAIN_SPEC.spec_id(15537393) < SpecId::MERGE); - assert_eq!(ETH_MAINNET_CHAIN_SPEC.spec_id(15537394), SpecId::MERGE); - assert_eq!(ETH_MAINNET_CHAIN_SPEC.spec_id(17034869), SpecId::MERGE); - assert_eq!(ETH_MAINNET_CHAIN_SPEC.spec_id(17034870), SpecId::SHANGHAI); + assert!(ETH_MAINNET_CHAIN_SPEC.spec_id(15537393, 0) < Some(SpecId::MERGE)); + assert_eq!( + ETH_MAINNET_CHAIN_SPEC.spec_id(15537394, 0), + Some(SpecId::MERGE) + ); + assert_eq!( + ETH_MAINNET_CHAIN_SPEC.spec_id(17034869, 0), + Some(SpecId::MERGE) + ); + assert_eq!( + ETH_MAINNET_CHAIN_SPEC.spec_id(17034870, 0), + Some(SpecId::SHANGHAI) + ); } } diff --git a/lib/src/input.rs b/lib/src/input.rs index 98661469f..00ba85055 100644 --- a/lib/src/input.rs +++ b/lib/src/input.rs @@ -20,10 +20,11 @@ use anyhow::{anyhow, Result}; use raiko_primitives::{mpt::MptNode, Address, Bytes, FixedBytes, B256, U256}; use revm::primitives::HashMap; use serde::{Deserialize, Serialize}; +use serde_with::serde_as; -use crate::consts::Network; #[cfg(not(feature = "std"))] use crate::no_std::*; +use crate::{consts::Network, serde_with::RlpBytes}; /// Represents the state of an account's storage. /// The storage trie together with the used storage slots allow us to reconstruct all the @@ -31,13 +32,15 @@ use crate::no_std::*; pub type StorageEntry = (MptNode, Vec); /// External block input. -#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde_as] +#[derive(Debug, Clone, Default, Deserialize, Serialize)] pub struct GuestInput { /// The network to generate the proof for pub network: Network, /// Block hash - for reference! pub block_hash: B256, /// Previous block header + #[serde_as(as = "RlpBytes")] pub parent_header: AlloyConsensusHeader, /// Address to which all priority fees in this block are transferred. pub beneficiary: Address, @@ -58,15 +61,24 @@ pub struct GuestInput { /// The code of all unique contracts. pub contracts: Vec, /// List of at most 256 previous block headers + #[serde_as(as = "Vec")] pub ancestor_headers: Vec, /// Base fee per gas pub base_fee_per_gas: u64, + + pub blob_gas_used: Option, + pub excess_blob_gas: Option, + pub parent_beacon_block_root: Option, + /// Taiko specific data pub taiko: TaikoGuestInput, } +#[serde_as] #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct TaikoGuestInput { + /// header + #[serde_as(as = "RlpBytes")] pub l1_header: AlloyConsensusHeader, pub tx_list: Vec, pub anchor_tx: String, @@ -83,10 +95,17 @@ pub struct TaikoProverData { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum GuestOutput { - Success((AlloyConsensusHeader, FixedBytes<32>)), + Success((WrappedHeader, FixedBytes<32>)), Failure, } +#[serde_as] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WrappedHeader { + #[serde_as(as = "RlpBytes")] + pub header: AlloyConsensusHeader, +} + sol! { function anchor( bytes32 l1Hash, @@ -306,29 +325,11 @@ impl From for BlockProposed { #[cfg(test)] mod tests { extern crate alloc; - use alloc::vec; - use super::*; #[test] fn input_serde_roundtrip() { - let input = GuestInput { - network: Default::default(), - block_hash: Default::default(), - parent_header: Default::default(), - beneficiary: Default::default(), - gas_limit: Default::default(), - timestamp: Default::default(), - extra_data: Default::default(), - mix_hash: Default::default(), - withdrawals: vec![], - parent_state_trie: Default::default(), - parent_storage: Default::default(), - contracts: vec![], - ancestor_headers: vec![], - base_fee_per_gas: Default::default(), - taiko: Default::default(), - }; + let input = GuestInput::default(); let _: GuestInput = bincode::deserialize(&bincode::serialize(&input).unwrap()).unwrap(); } } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d372d0a36..bcb3c0fe9 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -38,3 +38,60 @@ pub fn guest_mem_forget(_t: T) { #[cfg(target_os = "zkvm")] // TODO: seperate for risc0 core::mem::forget(_t) } + +pub trait RlpBytes: Sized { + /// Decodes the blob into the appropriate type. + /// The input must contain exactly one value and no trailing data. + fn decode_bytes(bytes: impl AsRef<[u8]>) -> Result; +} + +impl RlpBytes for T +where + T: alloy_rlp::Decodable, +{ + #[inline] + fn decode_bytes(bytes: impl AsRef<[u8]>) -> Result { + let mut buf = bytes.as_ref(); + let this = T::decode(&mut buf)?; + if buf.is_empty() { + Ok(this) + } else { + Err(alloy_rlp::Error::Custom("Trailing data")) + } + } +} + +pub mod serde_with { + use serde::{Deserialize, Deserializer, Serialize, Serializer}; + use serde_with::{DeserializeAs, SerializeAs}; + + use super::RlpBytes as _; + + pub struct RlpBytes {} + + impl SerializeAs for RlpBytes + where + T: alloy_rlp::Encodable, + { + fn serialize_as(source: &T, serializer: S) -> Result + where + S: Serializer, + { + let bytes = alloy_rlp::encode(source); + bytes.serialize(serializer) + } + } + + impl<'de, T> DeserializeAs<'de, T> for RlpBytes + where + T: alloy_rlp::Decodable, + { + fn deserialize_as(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let bytes = >::deserialize(deserializer)?; + T::decode_bytes(bytes).map_err(serde::de::Error::custom) + } + } +} diff --git a/lib/src/protocol_instance.rs b/lib/src/protocol_instance.rs index 799994547..8bca14cc6 100644 --- a/lib/src/protocol_instance.rs +++ b/lib/src/protocol_instance.rs @@ -8,7 +8,7 @@ use super::taiko_utils::ANCHOR_GAS_LIMIT; #[cfg(not(feature = "std"))] use crate::no_std::*; use crate::{ - consts::get_network_spec, + consts::{get_network_spec, Network}, input::{BlockMetadata, EthDeposit, GuestInput, Transition}, taiko_utils::HeaderHasher, }; @@ -104,7 +104,7 @@ pub fn assemble_protocol_instance( .collect::>(); let chain_spec = get_network_spec(input.network); - let gas_limit: u64 = header.gas_limit.try_into().unwrap(); + let gas_limit: u64 = header.gas_limit; let pi = ProtocolInstance { transition: Transition { parentHash: header.parent_hash, @@ -121,8 +121,8 @@ pub fn assemble_protocol_instance( coinbase: header.beneficiary, id: header.number, gasLimit: (gas_limit - ANCHOR_GAS_LIMIT) as u32, - timestamp: header.timestamp.try_into().unwrap(), - l1Height: input.taiko.l1_header.number.try_into().unwrap(), + timestamp: header.timestamp, + l1Height: input.taiko.l1_header.number, minTier: input.taiko.block_proposed.meta.minTier, blobUsed: blob_used, parentMetaHash: input.taiko.block_proposed.meta.parentMetaHash, @@ -130,17 +130,19 @@ pub fn assemble_protocol_instance( }, prover: input.taiko.prover_data.prover, chain_id: chain_spec.chain_id, - sgx_verifier_address: chain_spec.sgx_verifier_address.unwrap(), + sgx_verifier_address: chain_spec.sgx_verifier_address.unwrap_or_default(), }; // Sanity check - ensure!( - pi.block_metadata.abi_encode() == input.taiko.block_proposed.meta.abi_encode(), - format!( - "block hash mismatch, expected: {:?}, got: {:?}", - input.taiko.block_proposed.meta, pi.block_metadata - ) - ); + if input.network != Network::Ethereum { + ensure!( + pi.block_metadata.abi_encode() == input.taiko.block_proposed.meta.abi_encode(), + format!( + "block hash mismatch, expected: {:?}, got: {:?}", + input.taiko.block_proposed.meta, pi.block_metadata + ) + ); + } Ok(pi) } diff --git a/lib/src/prover.rs b/lib/src/prover.rs index 9dbc85c95..a0537480a 100644 --- a/lib/src/prover.rs +++ b/lib/src/prover.rs @@ -34,6 +34,7 @@ pub trait Prover { type ProofParam: fmt::Debug + Clone; type ProofResponse: Serialize; + #[allow(async_fn_in_trait)] async fn run( input: GuestInput, output: GuestOutput, diff --git a/lib/src/taiko_utils.rs b/lib/src/taiko_utils.rs index 13264910b..94b3bf2b0 100644 --- a/lib/src/taiko_utils.rs +++ b/lib/src/taiko_utils.rs @@ -2,9 +2,8 @@ use core::str::FromStr; // TODO(Cecilia): fix for no-std use std::io::Read; -use alloy_consensus::{Header as AlloyConsensusHeader, TxEip1559, TxEnvelope, TxKind}; -use alloy_network::Signed; -use alloy_primitives::{uint, Address, Signature, U256}; +use alloy_consensus::{Header as AlloyConsensusHeader, Signed, TxEip1559, TxEnvelope}; +use alloy_primitives::{uint, Address, Signature, TxKind, U256}; use alloy_rlp::*; use alloy_rpc_types::{Header as AlloyHeader, Transaction as AlloyTransaction}; use anyhow::{anyhow, bail, ensure, Context, Result}; @@ -26,13 +25,13 @@ pub const GOLDEN_TOUCH_ACCOUNT: Lazy
= Lazy::new(|| { }); pub fn decode_transactions(tx_list: &[u8]) -> Vec { - alloy_rlp::Decodable::decode(&mut &tx_list.to_owned()[..]).unwrap_or_default() + Vec::::decode(&mut &tx_list.to_owned()[..]).unwrap() } pub fn generate_transactions( is_blob_data: bool, tx_list: &[u8], - anchor_tx: AlloyTransaction, + anchor_tx: Option, ) -> Vec { // Decode the tx list from the raw data posted onchain let tx_list = &if is_blob_data { @@ -44,34 +43,36 @@ pub fn generate_transactions( // Decode the transactions from the tx list let mut transactions = decode_transactions(tx_list); - // Create a tx from the anchor tx that has the same type as the transactions encoded from - // the tx list - let signed_eip1559_tx = Signed::::new_unchecked( - TxEip1559 { - chain_id: anchor_tx.chain_id.unwrap().try_into().unwrap(), - nonce: anchor_tx.nonce.try_into().unwrap(), - gas_limit: anchor_tx.gas.try_into().unwrap(), - max_fee_per_gas: anchor_tx.max_fee_per_gas.unwrap().try_into().unwrap(), - max_priority_fee_per_gas: anchor_tx - .max_priority_fee_per_gas - .unwrap() - .try_into() - .unwrap(), - to: TxKind::Call(anchor_tx.to.unwrap()), - value: anchor_tx.value.try_into().unwrap(), - access_list: Default::default(), - input: anchor_tx.input, - }, - Signature::from_rs_and_parity( - anchor_tx.signature.unwrap().r, - anchor_tx.signature.unwrap().s, - anchor_tx.signature.unwrap().y_parity.unwrap().0, - ) - .unwrap(), - anchor_tx.hash, - ); - // Insert the anchor transactions generated by the node (which needs to be verified!) - transactions.insert(0, TxEnvelope::from(signed_eip1559_tx)); + if let Some(anchor_tx) = anchor_tx { + // Create a tx from the anchor tx that has the same type as the transactions encoded from + // the tx list + let signed_eip1559_tx = Signed::::new_unchecked( + TxEip1559 { + chain_id: anchor_tx.chain_id.unwrap(), + nonce: anchor_tx.nonce, + gas_limit: anchor_tx.gas.try_into().unwrap(), + max_fee_per_gas: anchor_tx.max_fee_per_gas.unwrap().try_into().unwrap(), + max_priority_fee_per_gas: anchor_tx + .max_priority_fee_per_gas + .unwrap() + .try_into() + .unwrap(), + to: TxKind::Call(anchor_tx.to.unwrap()), + value: anchor_tx.value, + access_list: Default::default(), + input: anchor_tx.input, + }, + Signature::from_rs_and_parity( + anchor_tx.signature.unwrap().r, + anchor_tx.signature.unwrap().s, + anchor_tx.signature.unwrap().y_parity.unwrap().0, + ) + .unwrap(), + anchor_tx.hash, + ); + // Insert the anchor transactions generated by the node (which needs to be verified!) + transactions.insert(0, TxEnvelope::from(signed_eip1559_tx)); + } transactions } @@ -232,6 +233,8 @@ pub fn check_anchor_tx( // Check the signature check_anchor_signature(tx).context(anyhow!("failed to check anchor signature"))?; + let tx = tx.tx(); + // Extract the `to` address let to = if let TxKind::Call(to_addr) = tx.to { to_addr diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index efe873fae..9848c3096 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -4,42 +4,34 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy-primitives = { version = "0.6", default-features = false, features = [ - "rlp", - "serde", -] } -alloy-sol-types = { version = "0.6", default-features = false, optional = true } -alloy-dyn-abi = { version = "0.6",default-features = false, optional = true } -alloy-rlp = { version = "0.3", default-features = false } -alloy-rlp-derive = { version = "0.3", default-features = false } -alloy-rpc-types = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -alloy-eips = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } -anyhow = { version = "1.0", default-features = false } -bytes = { version = "1.5", default-features = false } -k256 = { version = "^0.13.3", features = ["ecdsa"], default_features = false } +alloy-primitives = { workspace = true } +alloy-sol-types = { workspace = true } +alloy-dyn-abi = { workspace = true } +alloy-rlp = { workspace = true } +alloy-rlp-derive = { workspace = true } +alloy-rpc-types = { workspace = true } +alloy-eips = { workspace = true } +anyhow = { workspace = true } hashbrown = { workspace = true } -sha2 = { version = "0.10.7", optional = true } +sha2 = { workspace = true, optional = true } tempfile = { workspace = true, optional = true } -revm-primitives = { workspace = true, default-features = false } -rlp = { version = "0.5.2", default-features = false } -serde = { version = "1.0", default-features = false, features = ["derive"] } -sha3 = { version = "0.10", default-features = false} -thiserror = "1.0" +revm-primitives = { workspace = true } +rlp = { workspace = true, features = ["std"] } +serde = { workspace = true } +sha3 = { workspace = true } +thiserror = { workspace = true } -once_cell = { version = "1.18.0", default-features = false, features = ["critical-section"], optional = true } -hex = { version = "0.4", default-features = false} -ruint = { version = "1.10", default-features = false } +once_cell = { workspace = true, features = ["critical-section"], optional = true } # for eip-4844 c-kzg = { workspace = true, features = ["serde"], optional = true } [dev-dependencies] -bincode = "1.3" -hex-literal = "0.4" +bincode = { workspace = true } +hex-literal = { workspace = true } serde_json = { version = "1.0", default-features = false } [features] std = ["anyhow/std", "rlp/std"] -taiko = ["revm-primitives/taiko"] c-kzg = ["dep:c-kzg", "revm-primitives/c-kzg", "dep:sha2", "dep:tempfile", "dep:once_cell"] \ No newline at end of file diff --git a/primitives/src/eip4844.rs b/primitives/src/eip4844.rs index 341da3c53..a5b427211 100644 --- a/primitives/src/eip4844.rs +++ b/primitives/src/eip4844.rs @@ -5,6 +5,7 @@ pub use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas as calculate_ #[cfg(feature = "c-kzg")] use sha2::{Digest, Sha256}; +#[cfg(feature = "c-kzg")] use crate::B256; /// Calculates the versioned hash for a KzgCommitment diff --git a/primitives/src/signature.rs b/primitives/src/signature.rs index 0253ded63..88d34e8bb 100644 --- a/primitives/src/signature.rs +++ b/primitives/src/signature.rs @@ -1,13 +1,13 @@ -use revm_primitives::U256; +// use revm_primitives::U256; -/// The order of the secp256k1 curve, divided by two. Signatures that should be checked -/// according to EIP-2 should have an S value less than or equal to this. -/// -/// `57896044618658097711785492504343953926418782139537452191302581570759080747168` -const SECP256K1N_HALF: U256 = U256::from_be_bytes([ - 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, 0xDF, 0xE9, 0x2F, 0x46, 0x68, 0x1B, 0x20, 0xA0, -]); +// The order of the secp256k1 curve, divided by two. Signatures that should be checked +// according to EIP-2 should have an S value less than or equal to this. +// +// `57896044618658097711785492504343953926418782139537452191302581570759080747168` +// const SECP256K1N_HALF: U256 = U256::from_be_bytes([ +// 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +// 0xFF, 0xFF, 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, 0xDF, 0xE9, 0x2F, 0x46, +// 0x68, 0x1B, 0x20, 0xA0, ]); // Recovers the address of the sender using secp256k1 pubkey recovery. // diff --git a/prove_block.sh b/prove_block.sh index 838373f76..3abd93318 100755 --- a/prove_block.sh +++ b/prove_block.sh @@ -9,16 +9,18 @@ rangeStart="$3" rangeEnd="$4" # Check the caain name and set the corresponding RPC values -if [ "$chain" == "taiko_a6" ]; then - l2Rpc="https://rpc.katla.taiko.xyz" +if [ "$chain" == "ethereum" ]; then + rpc="https://rpc.ankr.com/eth" +elif [ "$chain" == "taiko_a6" ]; then + rpc="https://rpc.katla.taiko.xyz" l1Rpc="https://l1rpc.katla.taiko.xyz" beaconRpc="https://l1beacon.hekla.taiko.xyz" elif [ "$chain" == "taiko_a7" ]; then - l2Rpc="https://rpc.hekla.taiko.xyz/" + rpc="https://rpc.hekla.taiko.xyz/" l1Rpc="https://l1rpc.hekla.taiko.xyz/" beaconRpc="https://l1beacon.hekla.taiko.xyz" else - echo "Invalid chain name. Please use 'taiko_a6' or 'taiko_a7'." + echo "Invalid chain name. Please use 'ethereum', 'taiko_a6' or 'taiko_a7'." exit 1 fi @@ -76,7 +78,7 @@ do \"params\": [ { \"chain\": \"$chain\", - \"l2Rpc\": \"$l2Rpc\", + \"rpc\": \"$rpc\", \"l1Rpc\": \"$l1Rpc\", \"beaconRpc\": \"$beaconRpc\", \"proofParam\": $proofParam, diff --git a/provers/risc0/Cargo.toml b/provers/risc0/Cargo.toml index b0077cf39..3a1534ccc 100644 --- a/provers/risc0/Cargo.toml +++ b/provers/risc0/Cargo.toml @@ -4,28 +4,33 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy-primitives = { version = "0.6", default-features = false , optional = true} -alloy-sol-types = { version = "0.6" , optional = true} -ethers-contract = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" , optional = true} -ethers-core = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" , optional = true} -ethers-providers = { git = "https://github.com/smtmfft/ethers-rs", branch = "ethers-core-2.0.10" , optional = true} -tracing = {version = "0.1", optional = true} -serde = {version = "1.0", optional = true} -once_cell = {version = "1.8.0", optional = true} -hex = {version = "0.4.3", optional = true} -raiko-lib = { path = "../../lib", features = ["taiko", "std"] , optional = true} -raiko-primitives = { path = "../../primitives", features = ["taiko"] , optional = true} -anyhow ={version = "1.0", optional = true} -risc0-zkvm = { version = "0.20.1", features = ["prove", "getrandom"], optional = true} -bonsai-sdk = { version = "0.6.0", features = ["async"], optional = true} -log = {version = "0.4", optional = true} -bincode = {version = "1.3.3", optional = true} -bytemuck = {version = "1.13", optional = true} -typetag = {version = "0.2.15", optional = true} -serde_with = {version = "3.4.0", optional = true} +raiko-lib = { workspace = true, optional = true } +raiko-primitives = { workspace = true, optional = true } + +risc0-zkvm = { workspace = true, optional = true } +bonsai-sdk = { workspace = true, optional = true } + +alloy-primitives = { workspace = true, optional = true } +alloy-sol-types = { workspace = true, optional = true} + +ethers-contract = { workspace = true, optional = true } +ethers-core = { workspace = true, optional = true } +ethers-providers = { workspace = true, optional = true } + +tracing = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +once_cell = { workspace = true, optional = true } +anyhow = { workspace = true, optional = true } + +log = { workspace = true, optional = true } +bincode = { workspace = true, optional = true } +bytemuck = { workspace = true, optional = true } +typetag = { workspace = true, optional = true } +serde_with = { workspace = true, optional = true } +hex = { workspace = true, optional = true } [build-dependencies] -risc0-build = { version = "0.20.1" , optional = true} +risc0-build = { workspace = true, optional = true } [package.metadata.risc0] # does not support paths that contain .. for some reason, so the guest needs to be part of the prover diff --git a/provers/risc0/guest/Cargo.lock b/provers/risc0/guest/Cargo.lock index b574dc445..042cafaeb 100644 --- a/provers/risc0/guest/Cargo.lock +++ b/provers/risc0/guest/Cargo.lock @@ -16,9 +16,9 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "ahash" -version = "0.8.11" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", "once_cell", @@ -35,30 +35,69 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-eips", - "alloy-network", "alloy-primitives", "alloy-rlp", + "alloy-serde", "serde", + "sha2", +] + +[[package]] +name = "alloy-dyn-abi" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872f239c15befa27cc4f0d3d82a70b3365c2d0202562bf906eb93b299fa31882" +dependencies = [ + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-type-parser", + "alloy-sol-types", + "const-hex", + "itoa", + "winnow 0.6.5", ] [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "alloy-rlp", + "alloy-serde", + "c-kzg", + "once_cell", + "serde", +] + +[[package]] +name = "alloy-genesis" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "alloy-serde", + "serde", +] + +[[package]] +name = "alloy-json-abi" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a35ddfd27576474322a5869e4c123e5f3e7b2177297c18e4e82ea501cb125b" +dependencies = [ + "alloy-primitives", + "alloy-sol-type-parser", "serde", - "thiserror", ] [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "serde", @@ -69,20 +108,25 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-consensus", "alloy-eips", "alloy-json-rpc", "alloy-primitives", - "alloy-rlp", + "alloy-rpc-types", + "alloy-signer", + "async-trait", + "futures-utils-wasm", "serde", + "thiserror", ] [[package]] name = "alloy-primitives" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "600d34d8de81e23b6d909c094e23b3d357e01ca36b78a8c5424c501eedbe86f0" +checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" dependencies = [ "alloy-rlp", "bytes", @@ -125,25 +169,53 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-genesis", "alloy-primitives", "alloy-rlp", + "alloy-serde", + "alloy-sol-types", "itertools 0.12.1", "serde", "serde_json", "thiserror", ] +[[package]] +name = "alloy-serde" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-signer" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "async-trait", + "auto_impl", + "elliptic-curve", + "k256", + "thiserror", +] + [[package]] name = "alloy-sol-macro" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86ec0a47740b20bc5613b8712d0d321d031c4efc58e9645af96085d5cccfc27" +checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" dependencies = [ + "alloy-sol-macro-input", "const-hex", - "dunce", - "heck", + "heck 0.4.1", "indexmap 2.2.6", "proc-macro-error", "proc-macro2", @@ -153,11 +225,35 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "alloy-sol-macro-input" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.55", + "syn-solidity", +] + +[[package]] +name = "alloy-sol-type-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715f4d09a330cc181fc7c361b5c5c2766408fa59a0bac60349dcb7baabd404cc" +dependencies = [ + "winnow 0.6.5", +] + [[package]] name = "alloy-sol-types" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad09ec5853fa700d12d778ad224dcdec636af424d29fad84fb9a2f16a5b0ef09" +checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -425,6 +521,17 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-trait" +version = "0.1.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.55", +] + [[package]] name = "aurora-engine-modexp" version = "1.0.0" @@ -986,6 +1093,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures-utils-wasm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" + [[package]] name = "generic-array" version = "0.14.7" @@ -1057,6 +1170,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[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" @@ -1598,7 +1717,6 @@ dependencies = [ "alloy-rpc-types", "alloy-sol-types", "anyhow", - "bytes", "chrono", "flate2", "hashbrown 0.14.3", @@ -1608,8 +1726,6 @@ dependencies = [ "once_cell", "raiko-primitives", "revm", - "rlp", - "ruint", "serde", "serde_json", "serde_with", @@ -1622,19 +1738,17 @@ dependencies = [ name = "raiko-primitives" version = "0.1.0" dependencies = [ + "alloy-dyn-abi", "alloy-eips", "alloy-primitives", "alloy-rlp", "alloy-rlp-derive", "alloy-rpc-types", + "alloy-sol-types", "anyhow", - "bytes", "hashbrown 0.14.3", - "hex", - "k256", "revm-primitives", "rlp", - "ruint", "serde", "sha3", "thiserror", @@ -1688,7 +1802,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "revm" version = "7.2.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "auto_impl", "cfg-if", @@ -1701,7 +1815,7 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "3.4.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "revm-primitives", "serde", @@ -1710,7 +1824,7 @@ dependencies = [ [[package]] name = "revm-precompile" version = "5.1.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "aurora-engine-modexp", "k256", @@ -1725,7 +1839,7 @@ dependencies = [ [[package]] name = "revm-primitives" version = "3.1.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "alloy-primitives", "auto_impl", @@ -2215,9 +2329,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3d0961cd53c23ea94eeec56ba940f636f6394788976e9f16ca5ee0aca7464a" +checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" dependencies = [ "paste", "proc-macro2", @@ -2361,7 +2475,7 @@ checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap 2.2.6", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] @@ -2633,6 +2747,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" + [[package]] name = "wyz" version = "0.5.1" diff --git a/provers/risc0/guest/Cargo.toml b/provers/risc0/guest/Cargo.toml index ee25e094e..a7bc5a33d 100644 --- a/provers/risc0/guest/Cargo.toml +++ b/provers/risc0/guest/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] raiko-primitives = { path = "../../../primitives" } -raiko-lib = { path = "../../../lib", features = ["taiko", "std"] } +raiko-lib = { path = "../../../lib", features = ["std"] } risc0-zkvm = { version = "0.20.1", default-features = false, features = ['std', "getrandom"] } [patch.crates-io] @@ -15,7 +15,6 @@ risc0-zkvm = { version = "0.20.1", default-features = false, features = ['std', crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.2-risczero.0" } k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" } sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" } -alloy-eips = { git = "https://github.com/brechtpd/alloy", branch = "header-serialize" } # DONT do `cargo update` in this package!!! might break r0 build mostly due to compiler requirements on 1.70 # Documented version patch in Carto.toml: diff --git a/provers/risc0/guest/src/main.rs b/provers/risc0/guest/src/main.rs index 584f0b7ec..93219d22f 100644 --- a/provers/risc0/guest/src/main.rs +++ b/provers/risc0/guest/src/main.rs @@ -4,7 +4,7 @@ risc0_zkvm::guest::entry!(main); use raiko_lib::{ builder::{BlockBuilderStrategy, TaikoStrategy}, - input::{GuestInput, GuestOutput}, + input::{GuestInput, GuestOutput, WrappedHeader}, }; use raiko_lib::protocol_instance::assemble_protocol_instance; use raiko_lib::protocol_instance::EvidenceType; @@ -20,7 +20,7 @@ fn main() { let pi = assemble_protocol_instance(&input, &header) .expect("Failed to assemble protocol instance") .instance_hash(EvidenceType::Risc0); - GuestOutput::Success((header.clone(), pi)) + GuestOutput::Success((WrappedHeader {header: header.clone() }, pi)) } Err(_) => { GuestOutput::Failure diff --git a/provers/risc0/src/lib.rs b/provers/risc0/src/lib.rs index 49400f282..330c581e5 100644 --- a/provers/risc0/src/lib.rs +++ b/provers/risc0/src/lib.rs @@ -402,7 +402,7 @@ pub fn prove_locally( fs::create_dir(segment_dir.clone()).unwrap(); exec.run_with_callback(|segment| { - let path = segment_dir + let _path = segment_dir .as_path() .join(format!("{}.bincode", segment.index)); Ok(Box::new(FileSegmentRef::new( @@ -415,7 +415,7 @@ pub fn prove_locally( session.prove().unwrap() } -const NULL_SEGMENT_REF: NullSegmentRef = NullSegmentRef {}; +const _NULL_SEGMENT_REF: NullSegmentRef = NullSegmentRef {}; #[derive(Serialize, Deserialize)] struct NullSegmentRef {} diff --git a/provers/risc0/src/snarks.rs b/provers/risc0/src/snarks.rs index 131c153bf..a2c6d15e5 100644 --- a/provers/risc0/src/snarks.rs +++ b/provers/risc0/src/snarks.rs @@ -16,12 +16,10 @@ use std::{str::FromStr, sync::Arc}; use alloy_primitives::U256; use alloy_sol_types::{sol, SolValue}; -use anyhow::anyhow; use bonsai_sdk::alpha::responses::{Groth16Seal, SnarkReceipt}; use ethers_contract::abigen; -use ethers_core::{abi::AbiDecode, types::H160}; +use ethers_core::types::H160; use ethers_providers::{Http, Provider, RetryClient}; -use once_cell::unsync::Lazy; use risc0_zkvm::sha::{Digest, Digestible}; use tracing::{error as tracing_err, info as tracing_info}; diff --git a/provers/sgx/guest/Cargo.toml b/provers/sgx/guest/Cargo.toml index 72d84dcd9..2463c0be2 100644 --- a/provers/sgx/guest/Cargo.toml +++ b/provers/sgx/guest/Cargo.toml @@ -6,24 +6,19 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -raiko-lib = { path = "../../../lib", default-features = false, features = ["taiko", "std"] } -raiko-primitives = { path = "../../../primitives", features = ["taiko"] } -tokio = { version = "^1.23", features = ["full"] } -anyhow = "1.0" -secp256k1 = { version = "0.27.0", features = [ - 'global-context', - "rand", - "recovery", -] } -rand = "0.8.5" -hex = "0.4.3" -clap = { version = "4.4.6", features = ["derive", "string"] } -rand_core = "0.6.4" -sha3 = "0.10.8" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -base64-serde = "0.7.0" -base64 = "0.21.7" -dirs = "5.0.1" -bincode = "1.3" - +raiko-lib = { workspace = true } +raiko-primitives = { workspace = true } +tokio = { workspace = true } +anyhow = { workspace = true } +secp256k1 = { workspace = true } +serde = { workspace = true } +rand = { workspace = true } +hex = { workspace = true } +clap = { workspace = true } +rand_core = { workspace = true } +sha3 = { workspace = true } +serde_json = { workspace = true } +base64-serde = { workspace = true } +base64 = { workspace = true } +dirs = { workspace = true } +bincode = { workspace = true } diff --git a/provers/sgx/guest/src/main.rs b/provers/sgx/guest/src/main.rs index 9e502e738..d6cdcf154 100644 --- a/provers/sgx/guest/src/main.rs +++ b/provers/sgx/guest/src/main.rs @@ -1,5 +1,3 @@ -#![feature(path_file_prefix)] - mod app_args; mod one_shot; mod signature; diff --git a/provers/sgx/guest/src/one_shot.rs b/provers/sgx/guest/src/one_shot.rs index 5f83c91df..281dbda2a 100644 --- a/provers/sgx/guest/src/one_shot.rs +++ b/provers/sgx/guest/src/one_shot.rs @@ -109,7 +109,7 @@ pub async fn one_shot(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()> // Load the signing data let privkey_path = global_opts.secrets_dir.join(PRIV_KEY_FILENAME); - let prev_privkey = load_private_key(&privkey_path)?; + let prev_privkey = load_private_key(privkey_path)?; // let (new_privkey, new_pubkey) = generate_new_keypair()?; let new_pubkey = public_key(&prev_privkey); let new_instance = public_key_to_address(&new_pubkey); @@ -220,9 +220,9 @@ fn print_sgx_info() -> Result<()> { fn get_sgx_attestation_type() -> Result { let mut attestation_type = String::new(); - if !File::open(ATTESTATION_TYPE_DEVICE_FILE) + if File::open(ATTESTATION_TYPE_DEVICE_FILE) .and_then(|mut file| file.read_to_string(&mut attestation_type)) - .is_ok() + .is_err() { bail!( "Cannot find `{}`; are you running under SGX, with remote attestation enabled?", diff --git a/provers/sgx/prover/Cargo.toml b/provers/sgx/prover/Cargo.toml index 96132640e..b9c184da8 100644 --- a/provers/sgx/prover/Cargo.toml +++ b/provers/sgx/prover/Cargo.toml @@ -6,16 +6,16 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = {version = "1.0", optional = true} -serde_json ={ version = "1.0", optional = true} -serde_with = {version = "3.4.0", optional = true} -tracing = {version = "0.1", optional = true} -tokio = { version = "^1.23", features = ["full"], optional = true} -bincode = {version = "1.3.3", optional = true} -raiko-lib = { path = "../../../lib", features = ["taiko", "std"] , optional = true} -raiko-primitives = { path = "../../../primitives", features = ["taiko"] , optional = true} -once_cell = "1.19.0" -alloy-sol-types = { version = "0.6", default-features = false } +raiko-lib = { workspace = true, optional = true} +raiko-primitives = { workspace = true, optional = true} + +serde = { workspace = true, optional = true} +serde_json = { workspace = true, optional = true} +serde_with = { workspace = true, optional = true} +tokio = { workspace = true, optional = true} +bincode = { workspace = true, optional = true} +once_cell = { workspace = true } +alloy-sol-types = { workspace = true } [features] default = ["enable"] @@ -25,7 +25,6 @@ enable = [ "serde", "serde_json", "serde_with", - "tracing", "bincode", "tokio", ] \ No newline at end of file diff --git a/provers/sgx/prover/src/lib.rs b/provers/sgx/prover/src/lib.rs index 26c8edfbe..1e232fa81 100644 --- a/provers/sgx/prover/src/lib.rs +++ b/provers/sgx/prover/src/lib.rs @@ -84,7 +84,7 @@ impl Prover for SgxProver { .arg("sgx-guest.manifest") .output() .await - .map_err(|e| format!("Could not generate manfifest: {}", e.to_string()))?; + .map_err(|e| format!("Could not generate manfifest: {}", e))?; print_output(&output, "Generate manifest"); @@ -95,7 +95,7 @@ impl Prover for SgxProver { .arg("-f") .output() .await - .map_err(|e| format!("Could not generate SGX private key: {}", e.to_string()))?; + .map_err(|e| format!("Could not generate SGX private key: {}", e))?; // Sign the manifest let mut cmd = Command::new("gramine-sgx-sign"); @@ -106,7 +106,7 @@ impl Prover for SgxProver { .arg("sgx-guest.manifest.sgx") .output() .await - .map_err(|e| format!("Could not sign manfifest: {}", e.to_string()))?; + .map_err(|e| format!("Could not sign manfifest: {}", e))?; } // Form gramine command @@ -127,7 +127,7 @@ impl Prover for SgxProver { .arg("bootstrap") .output() .await - .map_err(|e| format!("Could not run SGX guest boostrap: {}", e.to_string()))?; + .map_err(|e| format!("Could not run SGX guest boostrap: {}", e))?; print_output(&output, "Sgx bootstrap"); // Prove @@ -137,7 +137,7 @@ impl Prover for SgxProver { .arg(param.instance_id.to_string()) .output() .await - .map_err(|e| format!("Could not run SGX guest prover: {}", e.to_string()))?; + .map_err(|e| format!("Could not run SGX guest prover: {}", e))?; print_output(&output, "Sgx execution"); if !output.status.success() { @@ -173,7 +173,7 @@ async fn prepare_working_directory( .parent() .unwrap() .to_path_buf(); - print!("Current directory: {:?}\n", cur_dir); + println!("Current directory: {:?}\n", cur_dir); // Create required directories let directories = ["secrets", "config"]; @@ -260,7 +260,7 @@ pub async fn execute( .arg("sgx-guest.manifest") .output() .await - .map_err(|e| format!("Could not generate manfifest: {}", e.to_string()))?; + .map_err(|e| format!("Could not generate manfifest: {}", e))?; print_output(&output, "Generate manifest"); @@ -271,7 +271,7 @@ pub async fn execute( .arg("-f") .output() .await - .map_err(|e| format!("Could not generate SGX private key: {}", e.to_string()))?; + .map_err(|e| format!("Could not generate SGX private key: {}", e))?; // Sign the manifest let mut cmd = Command::new("gramine-sgx-sign"); @@ -282,7 +282,7 @@ pub async fn execute( .arg("sgx-guest.manifest.sgx") .output() .await - .map_err(|e| format!("Could not sign manfifest: {}", e.to_string()))?; + .map_err(|e| format!("Could not sign manfifest: {}", e))?; } // Form gramine command @@ -303,7 +303,7 @@ pub async fn execute( .arg("bootstrap") .output() .await - .map_err(|e| format!("Could not run SGX guest boostrap: {}", e.to_string()))?; + .map_err(|e| format!("Could not run SGX guest boostrap: {}", e))?; print_output(&output, "Sgx bootstrap"); // Prove @@ -313,7 +313,7 @@ pub async fn execute( .arg(param.instance_id.to_string()) .output() .await - .map_err(|e| format!("Could not run SGX guest prover: {}", e.to_string()))?; + .map_err(|e| format!("Could not run SGX guest prover: {}", e))?; print_output(&output, "Sgx execution"); if !output.status.success() { diff --git a/provers/sp1/guest/Cargo.lock b/provers/sp1/guest/Cargo.lock index 921051724..39b9358b2 100644 --- a/provers/sp1/guest/Cargo.lock +++ b/provers/sp1/guest/Cargo.lock @@ -35,30 +35,69 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-eips", - "alloy-network", "alloy-primitives", "alloy-rlp", + "alloy-serde", "serde", + "sha2", +] + +[[package]] +name = "alloy-dyn-abi" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872f239c15befa27cc4f0d3d82a70b3365c2d0202562bf906eb93b299fa31882" +dependencies = [ + "alloy-json-abi", + "alloy-primitives", + "alloy-sol-type-parser", + "alloy-sol-types", + "const-hex", + "itoa", + "winnow 0.6.5", ] [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "alloy-rlp", + "alloy-serde", + "c-kzg", + "once_cell", + "serde", +] + +[[package]] +name = "alloy-genesis" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "alloy-serde", + "serde", +] + +[[package]] +name = "alloy-json-abi" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a35ddfd27576474322a5869e4c123e5f3e7b2177297c18e4e82ea501cb125b" +dependencies = [ + "alloy-primitives", + "alloy-sol-type-parser", "serde", - "thiserror", ] [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ "alloy-primitives", "serde", @@ -69,20 +108,25 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-consensus", "alloy-eips", "alloy-json-rpc", "alloy-primitives", - "alloy-rlp", + "alloy-rpc-types", + "alloy-signer", + "async-trait", + "futures-utils-wasm", "serde", + "thiserror", ] [[package]] name = "alloy-primitives" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "600d34d8de81e23b6d909c094e23b3d357e01ca36b78a8c5424c501eedbe86f0" +checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" dependencies = [ "alloy-rlp", "bytes", @@ -125,25 +169,53 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/brechtpd/alloy?branch=header-serialize#14381350e57921a71292304875e87dfbfd33c3b5" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-genesis", "alloy-primitives", "alloy-rlp", + "alloy-serde", + "alloy-sol-types", "itertools 0.12.1", "serde", "serde_json", "thiserror", ] +[[package]] +name = "alloy-serde" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "serde", + "serde_json", +] + +[[package]] +name = "alloy-signer" +version = "0.1.0" +source = "git+https://github.com/brechtpd/alloy?branch=175#55a8fb3b1cee4a867851eb19bef0b71e26859d27" +dependencies = [ + "alloy-primitives", + "async-trait", + "auto_impl", + "elliptic-curve", + "k256", + "thiserror", +] + [[package]] name = "alloy-sol-macro" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86ec0a47740b20bc5613b8712d0d321d031c4efc58e9645af96085d5cccfc27" +checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" dependencies = [ + "alloy-sol-macro-input", "const-hex", - "dunce", - "heck", + "heck 0.4.1", "indexmap 2.2.6", "proc-macro-error", "proc-macro2", @@ -153,11 +225,35 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "alloy-sol-macro-input" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.57", + "syn-solidity", +] + +[[package]] +name = "alloy-sol-type-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715f4d09a330cc181fc7c361b5c5c2766408fa59a0bac60349dcb7baabd404cc" +dependencies = [ + "winnow 0.6.5", +] + [[package]] name = "alloy-sol-types" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad09ec5853fa700d12d778ad224dcdec636af424d29fad84fb9a2f16a5b0ef09" +checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -315,6 +411,17 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "async-trait" +version = "0.1.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.57", +] + [[package]] name = "aurora-engine-modexp" version = "1.0.0" @@ -622,9 +729,9 @@ checksum = "7762d17f1241643615821a8455a0b2c3e803784b058693d990b11f2dce25a0ca" [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -835,6 +942,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures-utils-wasm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" + [[package]] name = "generic-array" version = "0.14.7" @@ -906,6 +1019,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[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" @@ -1293,9 +1412,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.8" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" +checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95" dependencies = [ "memchr", "thiserror", @@ -1431,7 +1550,6 @@ dependencies = [ "alloy-rpc-types", "alloy-sol-types", "anyhow", - "bytes", "chrono", "flate2", "hashbrown 0.14.3", @@ -1441,8 +1559,6 @@ dependencies = [ "once_cell", "raiko-primitives", "revm", - "rlp", - "ruint", "serde", "serde_json", "serde_with", @@ -1455,19 +1571,17 @@ dependencies = [ name = "raiko-primitives" version = "0.1.0" dependencies = [ + "alloy-dyn-abi", "alloy-eips", "alloy-primitives", "alloy-rlp", "alloy-rlp-derive", "alloy-rpc-types", + "alloy-sol-types", "anyhow", - "bytes", "hashbrown 0.14.3", - "hex", - "k256", "revm-primitives", "rlp", - "ruint", "serde", "sha3", "thiserror", @@ -1521,7 +1635,7 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "revm" version = "7.2.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "auto_impl", "cfg-if", @@ -1534,7 +1648,7 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "3.4.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "revm-primitives", "serde", @@ -1543,7 +1657,7 @@ dependencies = [ [[package]] name = "revm-precompile" version = "5.1.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "aurora-engine-modexp", "k256", @@ -1551,14 +1665,14 @@ dependencies = [ "revm-primitives", "ripemd", "sha2", - "sp1-precompiles 0.1.0 (git+https://github.com/succinctlabs/sp1.git)", + "sp1-precompiles", "substrate-bn", ] [[package]] name = "revm-primitives" version = "3.1.0" -source = "git+https://github.com/taikoxyz/revm.git?branch=unstable#501e02eae672fc7e83cd2e21f45124fa1b460596" +source = "git+https://github.com/taikoxyz/revm.git?branch=fix-ecrecover#8d1d50fb5f0840811613feb565ad1dc56cab1cbc" dependencies = [ "alloy-primitives", "auto_impl", @@ -1837,29 +1951,13 @@ name = "sp1-guest" version = "0.1.0" dependencies = [ "raiko-lib", - "raiko-primitives", - "serde", "sp1-zkvm", ] [[package]] name = "sp1-precompiles" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?rev=cb43fd74b24fad8ed24a4885499159de3680c89f#cb43fd74b24fad8ed24a4885499159de3680c89f" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "getrandom", - "k256", - "rand", - "serde", -] - -[[package]] -name = "sp1-precompiles" -version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git#cb43fd74b24fad8ed24a4885499159de3680c89f" +source = "git+https://www.github.com/succinctlabs/sp1.git?rev=cb43fd74b24fad8ed24a4885499159de3680c89f#cb43fd74b24fad8ed24a4885499159de3680c89f" dependencies = [ "anyhow", "bincode", @@ -1882,7 +1980,7 @@ dependencies = [ "libm", "rand", "serde", - "sp1-precompiles 0.1.0 (git+https://github.com/succinctlabs/sp1.git?rev=cb43fd74b24fad8ed24a4885499159de3680c89f)", + "sp1-precompiles", ] [[package]] @@ -1956,9 +2054,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3d0961cd53c23ea94eeec56ba940f636f6394788976e9f16ca5ee0aca7464a" +checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" dependencies = [ "paste", "proc-macro2", @@ -2102,7 +2200,7 @@ checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap 2.2.6", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] @@ -2332,6 +2430,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" + [[package]] name = "wyz" version = "0.5.1" diff --git a/provers/sp1/guest/Cargo.toml b/provers/sp1/guest/Cargo.toml index a61a4b5c1..4e3ca0852 100644 --- a/provers/sp1/guest/Cargo.toml +++ b/provers/sp1/guest/Cargo.toml @@ -6,15 +6,16 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -raiko-primitives = { path = "../../../primitives"} -raiko-lib = { path = "../../../lib", features = ["std", "taiko"] } +raiko-lib = { path = "../../../lib", features = ["std"] } sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", rev = "cb43fd74b24fad8ed24a4885499159de3680c89f" } -serde = { version = "1.0.195", features = ["derive"] } [patch.crates-io] tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", branch = "patch-v2.0.2" } sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "v0.10.8" } +[patch."https://github.com/succinctlabs/sp1.git"] +sp1-precompiles = { git = "https://www.github.com/succinctlabs/sp1.git", rev = "cb43fd74b24fad8ed24a4885499159de3680c89f" } + [workspace] # cargo prove build \ No newline at end of file diff --git a/provers/sp1/guest/src/main.rs b/provers/sp1/guest/src/main.rs index 2251a4300..d91faa27d 100644 --- a/provers/sp1/guest/src/main.rs +++ b/provers/sp1/guest/src/main.rs @@ -3,7 +3,7 @@ sp1_zkvm::entrypoint!(main); use raiko_lib::{ builder::{BlockBuilderStrategy, TaikoStrategy}, - input::{GuestInput, GuestOutput}, + input::{GuestInput, GuestOutput, WrappedHeader}, }; use raiko_lib::protocol_instance::assemble_protocol_instance; use raiko_lib::protocol_instance::EvidenceType; @@ -18,7 +18,7 @@ pub fn main() { let pi = assemble_protocol_instance(&input, &header) .expect("Failed to assemble protocol instance") .instance_hash(EvidenceType::Succinct); - GuestOutput::Success((header.clone(), pi)) + GuestOutput::Success((WrappedHeader {header: header.clone() }, pi)) } Err(_) => { GuestOutput::Failure diff --git a/provers/sp1/prover/Cargo.toml b/provers/sp1/prover/Cargo.toml index a653dda24..d625610e6 100644 --- a/provers/sp1/prover/Cargo.toml +++ b/provers/sp1/prover/Cargo.toml @@ -4,15 +4,15 @@ name = "sp1-prover" edition = "2021" [dependencies] -alloy-primitives = { version = "0.6", default-features = false, optional = true } -alloy-sol-types = { version = "0.6", default-features = false } -serde = { version = "1.0", optional = true} -serde_json = { version = "1.0", optional = true } -raiko-lib = { path = "../../../lib", features = ["taiko", "std"] , optional = true } +raiko-lib = { workspace = true, optional = true } +alloy-primitives = { workspace = true, optional = true } +alloy-sol-types = { workspace = true } +serde = { workspace = true , optional = true} +serde_json = { workspace = true , optional = true } sp1-core = { workspace = true, optional = true } -anyhow = {version = "1.0", optional = true } -once_cell = "1.19.0" -sha3 = { version = "0.10", default-features = false} +anyhow = { workspace = true, optional = true } +once_cell = { workspace = true } +sha3 = { workspace = true, default-features = false} [build-dependencies] sp1-helper = { workspace = true, optional = true }