diff --git a/Cargo.lock b/Cargo.lock index 26b6dcc5e4..b1fcc64cf8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1035,7 +1035,7 @@ checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" [[package]] name = "codecs-derive" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "convert_case 0.6.0", "parity-scale-codec", @@ -3188,25 +3188,12 @@ checksum = "1822d18e4384a5e79d94dc9e4d1239cfa9fad24e55b44d2efeff5b394c9fece4" dependencies = [ "jsonrpsee-core 0.18.2", "jsonrpsee-http-client 0.18.2", - "jsonrpsee-proc-macros 0.18.2", - "jsonrpsee-server 0.18.2", + "jsonrpsee-proc-macros", + "jsonrpsee-server", "jsonrpsee-types 0.18.2", "tracing", ] -[[package]] -name = "jsonrpsee" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f3783308bddc49d0218307f66a09330c106fbd792c58bac5c8dc294fdd0f98" -dependencies = [ - "jsonrpsee-core 0.19.0", - "jsonrpsee-proc-macros 0.19.0", - "jsonrpsee-server 0.19.0", - "jsonrpsee-types 0.19.0", - "tracing", -] - [[package]] name = "jsonrpsee-core" version = "0.16.2" @@ -3250,30 +3237,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "jsonrpsee-core" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa4c4d5fb801dcc316d81f76422db259809037a86b3194ae538dd026b05ed7" -dependencies = [ - "anyhow", - "async-trait", - "beef", - "futures-util", - "globset", - "hyper", - "jsonrpsee-types 0.19.0", - "parking_lot 0.12.1", - "rand 0.8.5", - "rustc-hash", - "serde", - "serde_json", - "soketto", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "jsonrpsee-http-client" version = "0.16.2" @@ -3325,19 +3288,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "jsonrpsee-proc-macros" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21dc12b1d4f16a86e8c522823c4fab219c88c03eb7c924ec0501a64bf12e058b" -dependencies = [ - "heck", - "proc-macro-crate 1.3.1", - "proc-macro2 1.0.66", - "quote 1.0.32", - "syn 1.0.109", -] - [[package]] name = "jsonrpsee-server" version = "0.18.2" @@ -3358,26 +3308,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "jsonrpsee-server" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e79d78cfd5abd8394da10753723093c3ff64391602941c9c4b1d80a3414fd53" -dependencies = [ - "futures-util", - "hyper", - "jsonrpsee-core 0.19.0", - "jsonrpsee-types 0.19.0", - "serde", - "serde_json", - "soketto", - "tokio", - "tokio-stream", - "tokio-util", - "tower", - "tracing", -] - [[package]] name = "jsonrpsee-types" version = "0.16.2" @@ -3406,20 +3336,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "jsonrpsee-types" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00aa7cc87bc42e04e26c8ac3e7186142f7fd2949c763d9b6a7e64a69672d8fb2" -dependencies = [ - "anyhow", - "beef", - "serde", - "serde_json", - "thiserror", - "tracing", -] - [[package]] name = "jsonwebtoken" version = "8.3.0" @@ -4985,7 +4901,7 @@ checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0" [[package]] name = "reth-beacon-consensus" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "futures", "reth-consensus-common", @@ -5009,7 +4925,7 @@ dependencies = [ [[package]] name = "reth-codecs" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "bytes", "codecs-derive", @@ -5019,7 +4935,7 @@ dependencies = [ [[package]] name = "reth-consensus-common" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "reth-interfaces", "reth-primitives", @@ -5029,7 +4945,7 @@ dependencies = [ [[package]] name = "reth-db" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "bytes", "derive_more", @@ -5056,7 +4972,7 @@ dependencies = [ [[package]] name = "reth-ecies" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "aes", "block-padding", @@ -5087,7 +5003,7 @@ dependencies = [ [[package]] name = "reth-eth-wire" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "async-trait", "bytes", @@ -5112,7 +5028,7 @@ dependencies = [ [[package]] name = "reth-interfaces" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "async-trait", "auto_impl", @@ -5136,7 +5052,7 @@ dependencies = [ [[package]] name = "reth-libmdbx" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "bitflags 2.3.3", "byteorder", @@ -5151,7 +5067,7 @@ dependencies = [ [[package]] name = "reth-mdbx-sys" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "bindgen", "cc", @@ -5161,7 +5077,7 @@ dependencies = [ [[package]] name = "reth-metrics" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "metrics", "reth-metrics-derive", @@ -5170,7 +5086,7 @@ dependencies = [ [[package]] name = "reth-metrics-derive" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "once_cell", "proc-macro2 1.0.66", @@ -5182,7 +5098,7 @@ dependencies = [ [[package]] name = "reth-net-common" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "pin-project", "reth-primitives", @@ -5192,7 +5108,7 @@ dependencies = [ [[package]] name = "reth-network-api" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "async-trait", "reth-eth-wire", @@ -5206,7 +5122,7 @@ dependencies = [ [[package]] name = "reth-payload-builder" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "futures-util", "reth-interfaces", @@ -5226,7 +5142,7 @@ dependencies = [ [[package]] name = "reth-primitives" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "bytes", "crc", @@ -5266,11 +5182,11 @@ dependencies = [ [[package]] name = "reth-provider" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "auto_impl", "derive_more", - "itertools 0.11.0", + "itertools 0.10.5", "parking_lot 0.12.1", "pin-project", "reth-db", @@ -5287,13 +5203,12 @@ dependencies = [ [[package]] name = "reth-prune" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ - "itertools 0.11.0", + "itertools 0.10.5", "rayon", "reth-db", "reth-interfaces", - "reth-metrics", "reth-primitives", "reth-provider", "thiserror", @@ -5303,7 +5218,7 @@ dependencies = [ [[package]] name = "reth-revm" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "reth-consensus-common", "reth-interfaces", @@ -5318,7 +5233,7 @@ dependencies = [ [[package]] name = "reth-revm-inspectors" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "boa_engine", "boa_gc", @@ -5335,7 +5250,7 @@ dependencies = [ [[package]] name = "reth-revm-primitives" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "reth-primitives", "revm", @@ -5344,7 +5259,7 @@ dependencies = [ [[package]] name = "reth-rlp" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "arrayvec", "auto_impl", @@ -5358,7 +5273,7 @@ dependencies = [ [[package]] name = "reth-rlp-derive" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "proc-macro2 1.0.66", "quote 1.0.32", @@ -5368,7 +5283,7 @@ dependencies = [ [[package]] name = "reth-rpc" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "async-trait", "bytes", @@ -5378,7 +5293,7 @@ dependencies = [ "http", "http-body", "hyper", - "jsonrpsee 0.19.0", + "jsonrpsee 0.18.2", "jsonwebtoken", "pin-project", "rand 0.8.5", @@ -5414,9 +5329,9 @@ dependencies = [ [[package]] name = "reth-rpc-api" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ - "jsonrpsee 0.19.0", + "jsonrpsee 0.18.2", "reth-primitives", "reth-rpc-types", "serde_json", @@ -5425,11 +5340,11 @@ dependencies = [ [[package]] name = "reth-rpc-engine-api" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "async-trait", - "jsonrpsee-core 0.19.0", - "jsonrpsee-types 0.19.0", + "jsonrpsee-core 0.18.2", + "jsonrpsee-types 0.18.2", "reth-beacon-consensus", "reth-interfaces", "reth-payload-builder", @@ -5446,10 +5361,9 @@ dependencies = [ [[package]] name = "reth-rpc-types" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ - "itertools 0.11.0", - "jsonrpsee-types 0.19.0", + "jsonrpsee-types 0.18.2", "reth-primitives", "reth-rlp", "serde", @@ -5460,12 +5374,12 @@ dependencies = [ [[package]] name = "reth-stages" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "aquamarine", "async-trait", "futures-util", - "itertools 0.11.0", + "itertools 0.10.5", "num-traits", "pin-project", "rayon", @@ -5486,7 +5400,7 @@ dependencies = [ [[package]] name = "reth-tasks" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "dyn-clone", "futures-util", @@ -5500,7 +5414,7 @@ dependencies = [ [[package]] name = "reth-transaction-pool" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "aquamarine", "async-trait", @@ -5527,7 +5441,7 @@ dependencies = [ [[package]] name = "reth-trie" version = "0.1.0-alpha.4" -source = "git+https://github.com/paradigmxyz/reth#aaf2d2cf194cc5b2c6e8ec106001ee44db9512c9" +source = "git+https://github.com/paradigmxyz/reth?rev=4ab924c5d361bbfdcdad9f997d16d67b4a1730b7#4ab924c5d361bbfdcdad9f997d16d67b4a1730b7" dependencies = [ "derive_more", "hex", @@ -6731,6 +6645,7 @@ dependencies = [ "reth-rpc-types", "revm", "schemars", + "secp256k1", "serde", "serde_json", "sov-modules-api", diff --git a/Cargo.toml b/Cargo.toml index 579a7b688a..df89c0944b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,14 +95,16 @@ ethers-providers = "=2.0.8" ethers-signers = { version = "=2.0.8", default-features = false } ethers-middleware = "=2.0.8" -reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "0.1.0-alpha.4"} -reth-rpc-types = { git = "https://github.com/paradigmxyz/reth", version = "0.1.0-alpha.4"} -reth-rpc = { git = "https://github.com/paradigmxyz/reth", version = "0.1.0-alpha.4"} -reth-revm = { git = "https://github.com/paradigmxyz/reth", version = "0.1.0-alpha.4"} +reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "4ab924c5d361bbfdcdad9f997d16d67b4a1730b7"} +reth-rpc-types = { git = "https://github.com/paradigmxyz/reth", rev = "4ab924c5d361bbfdcdad9f997d16d67b4a1730b7"} +reth-rpc = { git = "https://github.com/paradigmxyz/reth", rev = "4ab924c5d361bbfdcdad9f997d16d67b4a1730b7"} +reth-revm = { git = "https://github.com/paradigmxyz/reth", rev = "4ab924c5d361bbfdcdad9f997d16d67b4a1730b7"} revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" } revm-primitives = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" } +secp256k1 = { version = "0.27.0", default-features = false, features = ["global-context", "rand-std", "recovery"] } + [patch.crates-io] # See reth: https://github.com/paradigmxyz/reth/blob/main/Cargo.toml#L79 revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" } diff --git a/full-node/sov-ethereum/src/lib.rs b/full-node/sov-ethereum/src/lib.rs index 75ccf80823..9992fe917c 100644 --- a/full-node/sov-ethereum/src/lib.rs +++ b/full-node/sov-ethereum/src/lib.rs @@ -17,9 +17,10 @@ pub mod experimental { use jsonrpsee::types::ErrorObjectOwned; use jsonrpsee::RpcModule; use jupiter::da_service::DaServiceConfig; - use reth_primitives::Bytes as RethBytes; + use reth_primitives::TransactionSignedNoHash as RethTransactionSignedNoHash; + use reth_rpc::eth::error::EthApiError; use sov_evm::call::CallMessage; - use sov_evm::evm::{EthAddress, EvmTransaction}; + use sov_evm::evm::{EthAddress, RawEvmTransaction}; use sov_modules_api::transaction::Transaction; use sov_modules_api::utils::to_jsonrpsee_error_object; use sov_modules_api::EncodeCall; @@ -47,24 +48,36 @@ pub mod experimental { } impl Ethereum { - fn make_raw_tx(&self, evm_tx: EvmTransaction) -> Result, std::io::Error> { + fn make_raw_tx( + &self, + raw_tx: RawEvmTransaction, + ) -> Result<(H256, Vec), jsonrpsee::core::Error> { + let signed_transaction: RethTransactionSignedNoHash = + raw_tx.clone().try_into().map_err(EthApiError::from)?; + + let tx_hash = signed_transaction.hash(); + let sender = signed_transaction + .recover_signer() + .ok_or(EthApiError::InvalidTransactionSignature)?; + let mut nonces = self.nonces.lock().unwrap(); let nonce = *nonces - .entry(evm_tx.sender) + .entry(sender.into()) .and_modify(|n| *n += 1) .or_insert(0); - let tx = CallMessage { tx: evm_tx }; + let tx = CallMessage { tx: raw_tx }; let message = as EncodeCall>>::encode_call( tx, ); + let tx = Transaction::::new_signed_tx( &self.tx_signer_prov_key, message, nonce, ); - tx.try_to_vec() + Ok((H256::from(tx_hash), tx.try_to_vec()?)) } } @@ -111,13 +124,10 @@ pub mod experimental { "eth_sendRawTransaction", |parameters, ethereum| async move { let data: Bytes = parameters.one().unwrap(); - let data = RethBytes::from(data.as_ref()); - - let evm_transaction: EvmTransaction = data.try_into().expect("Not an evm tx"); - let tx_hash = evm_transaction.hash; - let raw_tx = ethereum - .make_raw_tx(evm_transaction) + let raw_evm_tx = RawEvmTransaction { rlp: data.to_vec() }; + let (tx_hash, raw_tx) = ethereum + .make_raw_tx(raw_evm_tx) .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; ethereum @@ -125,7 +135,7 @@ pub mod experimental { .await .map_err(|e| to_jsonrpsee_error_object(e, ETH_RPC_ERROR))?; - Ok::<_, ErrorObjectOwned>(H256::from(tx_hash)) + Ok::<_, ErrorObjectOwned>(tx_hash) }, )?; diff --git a/module-system/module-implementations/sov-evm/Cargo.toml b/module-system/module-implementations/sov-evm/Cargo.toml index 37dab7f5a1..5142967870 100644 --- a/module-system/module-implementations/sov-evm/Cargo.toml +++ b/module-system/module-implementations/sov-evm/Cargo.toml @@ -37,9 +37,6 @@ ethers-contract = { workspace = true } ethers-middleware = { workspace = true } ethers-providers = { workspace = true } ethers-signers = { workspace = true } - - - ethers = { workspace = true } revm = { workspace = true } @@ -48,12 +45,14 @@ reth-rpc-types = { workspace = true } reth-rpc = { workspace = true } reth-revm = { workspace = true } + [dev-dependencies] primitive-types = "0.12.1" tokio = { workspace = true } tempfile = { workspace = true } bytes = { workspace = true } +secp256k1 = { workspace = true } sov-modules-api = { path = "../../sov-modules-api", version = "0.1", features = ["macros"] } diff --git a/module-system/module-implementations/sov-evm/src/call.rs b/module-system/module-implementations/sov-evm/src/call.rs index 27f27992dc..13d40318e9 100644 --- a/module-system/module-implementations/sov-evm/src/call.rs +++ b/module-system/module-implementations/sov-evm/src/call.rs @@ -5,8 +5,8 @@ use sov_state::WorkingSet; use crate::evm::db::EvmDb; use crate::evm::executor::{self}; -use crate::evm::transaction::{BlockEnv, EvmTransaction}; -use crate::evm::{contract_address, EvmChainCfg}; +use crate::evm::transaction::{BlockEnv, EvmTransactionSignedEcRecovered}; +use crate::evm::{contract_address, EvmChainCfg, RawEvmTransaction}; use crate::experimental::SpecIdWrapper; use crate::{Evm, TransactionReceipt}; @@ -18,38 +18,40 @@ use crate::{Evm, TransactionReceipt}; )] #[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)] pub struct CallMessage { - pub tx: EvmTransaction, + pub tx: RawEvmTransaction, } impl Evm { pub(crate) fn execute_call( &self, - tx: EvmTransaction, + tx: RawEvmTransaction, _context: &C, working_set: &mut WorkingSet, ) -> Result { - // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/515 + let evm_tx_recovered: EvmTransactionSignedEcRecovered = tx.clone().try_into()?; let block_env = self.block_env.get(working_set).unwrap_or_default(); let cfg = self.cfg.get(working_set).unwrap_or_default(); let cfg_env = get_cfg_env(&block_env, cfg, None); - self.transactions.set(&tx.hash, &tx, working_set); + + let hash = evm_tx_recovered.hash(); + self.transactions.set(&hash, &tx, working_set); let evm_db: EvmDb<'_, C> = self.get_db(working_set); // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/505 - let result = executor::execute_tx(evm_db, block_env, tx.clone(), cfg_env).unwrap(); + let result = executor::execute_tx(evm_db, block_env, &evm_tx_recovered, cfg_env).unwrap(); let receipt = TransactionReceipt { - transaction_hash: tx.hash, + transaction_hash: hash.into(), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504 transaction_index: 0, // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504 block_hash: Default::default(), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504 block_number: Some(0), - from: tx.sender, - to: tx.to, + from: evm_tx_recovered.signer().into(), + to: evm_tx_recovered.to(), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504 cumulative_gas_used: Default::default(), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/504 diff --git a/module-system/module-implementations/sov-evm/src/evm/conversions.rs b/module-system/module-implementations/sov-evm/src/evm/conversions.rs index 5277565ed9..acfce19886 100644 --- a/module-system/module-implementations/sov-evm/src/evm/conversions.rs +++ b/module-system/module-implementations/sov-evm/src/evm/conversions.rs @@ -1,13 +1,20 @@ use bytes::Bytes; -use ethers_core::types::{OtherFields, Transaction}; -use reth_rpc::eth::error::{EthApiError, RpcInvalidTransactionError}; +use ethereum_types::U64; +use ethers_core::types::{Bytes as EthBytes, OtherFields, Transaction}; +use reth_primitives::{ + Bytes as RethBytes, TransactionSigned as RethTransactionSigned, + TransactionSignedEcRecovered as RethTransactionSignedEcRecovered, + TransactionSignedNoHash as RethTransactionSignedNoHash, +}; +use reth_rpc::eth::error::EthApiError; use reth_rpc_types::CallRequest; use revm::primitives::{ AccountInfo as ReVmAccountInfo, BlockEnv as ReVmBlockEnv, Bytecode, CreateScheme, TransactTo, TxEnv, B160, B256, U256, }; +use thiserror::Error; -use super::transaction::{AccessListItem, BlockEnv, EvmTransaction}; +use super::transaction::{BlockEnv, EvmTransactionSignedEcRecovered, RawEvmTransaction}; use super::AccountInfo; impl From for ReVmAccountInfo { @@ -47,65 +54,56 @@ impl From for ReVmBlockEnv { } } -impl From for (B160, Vec) { - fn from(item: AccessListItem) -> Self { - ( - B160::from_slice(&item.address), - item.storage_keys - .into_iter() - .map(U256::from_le_bytes) - .collect(), - ) - } -} +impl From<&EvmTransactionSignedEcRecovered> for TxEnv { + fn from(tx: &EvmTransactionSignedEcRecovered) -> Self { + let tx: &RethTransactionSignedEcRecovered = tx.as_ref(); -impl From for TxEnv { - fn from(tx: EvmTransaction) -> Self { - let to = match tx.to { - Some(addr) => TransactTo::Call(B160::from_slice(&addr)), + let to = match tx.to() { + Some(addr) => TransactTo::Call(addr), None => TransactTo::Create(CreateScheme::Create), }; - let access_list = tx - .access_lists - .into_iter() - .map(|item| item.into()) - .collect(); - Self { - caller: B160::from_slice(&tx.sender), - data: Bytes::from(tx.data), - gas_limit: tx.gas_limit, - gas_price: U256::from(tx.gas_price), - gas_priority_fee: Some(U256::from(tx.max_priority_fee_per_gas)), + caller: tx.signer(), + gas_limit: tx.gas_limit(), + gas_price: U256::from(tx.effective_gas_price(None)), + gas_priority_fee: tx.max_priority_fee_per_gas().map(U256::from), transact_to: to, - value: U256::from(tx.value), - nonce: Some(tx.nonce), - chain_id: Some(tx.chain_id), - access_list, + value: U256::from(tx.value()), + data: Bytes::from(tx.input().to_vec()), + chain_id: tx.chain_id(), + nonce: Some(tx.nonce()), + // TODO handle access list + access_list: vec![], } } } -impl From for Transaction { - fn from(evm_tx: EvmTransaction) -> Self { - Self { - hash: evm_tx.hash.into(), - nonce: evm_tx.nonce.into(), - from: evm_tx.sender.into(), - to: evm_tx.to.map(|addr| addr.into()), - value: evm_tx.value.into(), - // https://github.com/foundry-rs/foundry/blob/master/anvil/core/src/eth/transaction/mod.rs#L1251 - gas_price: Some(evm_tx.max_fee_per_gas.into()), - input: evm_tx.data.into(), - v: (evm_tx.odd_y_parity as u8).into(), - r: evm_tx.r.into(), - s: evm_tx.s.into(), - transaction_type: Some(2.into()), +impl TryFrom for Transaction { + type Error = RawEvmTxConversionError; + fn try_from(evm_tx: RawEvmTransaction) -> Result { + let tx: EvmTransactionSignedEcRecovered = evm_tx.try_into()?; + let tx: &RethTransactionSignedEcRecovered = tx.as_ref(); + + Ok(Self { + hash: tx.hash().into(), + nonce: tx.nonce().into(), + + from: tx.signer().into(), + to: tx.to().map(|addr| addr.into()), + value: tx.value().into(), + gas_price: Some(tx.effective_gas_price(None).into()), + + input: EthBytes::from(tx.input().to_vec()), + v: tx.signature().v(tx.chain_id()).into(), + r: tx.signature().r.into(), + s: tx.signature().s.into(), + transaction_type: Some(U64::from(tx.tx_type() as u8)), + // TODO handle access list access_list: None, - max_priority_fee_per_gas: Some(evm_tx.max_priority_fee_per_gas.into()), - max_fee_per_gas: Some(evm_tx.max_fee_per_gas.into()), - chain_id: Some(evm_tx.chain_id.into()), + max_priority_fee_per_gas: tx.max_priority_fee_per_gas().map(From::from), + max_fee_per_gas: Some(tx.max_fee_per_gas().into()), + chain_id: tx.chain_id().map(|id| id.into()), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/503 block_hash: Some([0; 32].into()), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/503 @@ -116,64 +114,58 @@ impl From for Transaction { gas: Default::default(), // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/503 other: OtherFields::default(), - } + }) } } -use reth_primitives::{Bytes as RethBytes, TransactionSigned}; +#[derive(Error, Debug)] +pub enum RawEvmTxConversionError { + #[error("Empty raw transaction data")] + EmptyRawTransactionData, + #[error("Failed to decode signed transaction")] + FailedToDecodeSignedTransaction, +} + +impl From for EthApiError { + fn from(e: RawEvmTxConversionError) -> Self { + match e { + RawEvmTxConversionError::EmptyRawTransactionData => { + EthApiError::EmptyRawTransactionData + } + RawEvmTxConversionError::FailedToDecodeSignedTransaction => { + EthApiError::FailedToDecodeSignedTransaction + } + } + } +} -impl TryFrom for EvmTransaction { - type Error = EthApiError; +impl TryFrom for RethTransactionSignedNoHash { + type Error = RawEvmTxConversionError; - fn try_from(data: RethBytes) -> Result { + fn try_from(data: RawEvmTransaction) -> Result { + let data = RethBytes::from(data.rlp); if data.is_empty() { - return Err(EthApiError::EmptyRawTransactionData); + return Err(RawEvmTxConversionError::EmptyRawTransactionData); } - let transaction = TransactionSigned::decode_enveloped(data) - .map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?; + let transaction = RethTransactionSigned::decode_enveloped(data) + .map_err(|_| RawEvmTxConversionError::FailedToDecodeSignedTransaction)?; - let transaction = transaction - .into_ecrecovered() - .ok_or(EthApiError::InvalidTransactionSignature)?; + Ok(transaction.into()) + } +} - let (signed_transaction, signer) = transaction.to_components(); +impl TryFrom for EvmTransactionSignedEcRecovered { + type Error = RawEvmTxConversionError; - let tx_hash = signed_transaction.hash(); - let tx_eip_1559 = match signed_transaction.transaction { - reth_primitives::Transaction::Legacy(_) => { - return Err(EthApiError::InvalidTransaction( - RpcInvalidTransactionError::TxTypeNotSupported, - )) - } - reth_primitives::Transaction::Eip2930(_) => { - return Err(EthApiError::InvalidTransaction( - RpcInvalidTransactionError::TxTypeNotSupported, - )) - } - reth_primitives::Transaction::Eip1559(tx_eip_1559) => tx_eip_1559, - }; + fn try_from(evm_tx: RawEvmTransaction) -> Result { + let tx = RethTransactionSignedNoHash::try_from(evm_tx)?; + let tx: RethTransactionSigned = tx.into(); + let tx = tx + .into_ecrecovered() + .ok_or(RawEvmTxConversionError::FailedToDecodeSignedTransaction)?; - Ok(Self { - sender: signer.into(), - data: tx_eip_1559.input.to_vec(), - gas_limit: tx_eip_1559.gas_limit, - // https://github.com/foundry-rs/foundry/blob/master/anvil/core/src/eth/transaction/mod.rs#L1251C20-L1251C20 - gas_price: tx_eip_1559.max_fee_per_gas, - max_priority_fee_per_gas: tx_eip_1559.max_priority_fee_per_gas, - max_fee_per_gas: tx_eip_1559.max_fee_per_gas, - to: tx_eip_1559.to.to().map(|addr| addr.into()), - value: tx_eip_1559.value, - nonce: tx_eip_1559.nonce, - // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/503 - access_lists: vec![], - chain_id: tx_eip_1559.chain_id, - // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/503 - hash: tx_hash.into(), - odd_y_parity: Default::default(), - r: Default::default(), - s: Default::default(), - }) + Ok(EvmTransactionSignedEcRecovered::new(tx)) } } @@ -198,7 +190,7 @@ pub fn prepare_call_env(request: CallRequest) -> TxEnv { .unwrap_or_default(), chain_id: request.chain_id.map(|c| c.as_u64()), nonce: request.nonce.map(|n| TryInto::::try_into(n).unwrap()), - + // TODO handle access list access_list: Default::default(), } } diff --git a/module-system/module-implementations/sov-evm/src/evm/executor.rs b/module-system/module-implementations/sov-evm/src/evm/executor.rs index f961016548..d7e56d96ca 100644 --- a/module-system/module-implementations/sov-evm/src/evm/executor.rs +++ b/module-system/module-implementations/sov-evm/src/evm/executor.rs @@ -4,12 +4,12 @@ use reth_revm::tracing::{TracingInspector, TracingInspectorConfig}; use revm::primitives::{CfgEnv, EVMError, Env, ExecutionResult, ResultAndState, TxEnv}; use revm::{self, Database, DatabaseCommit}; -use super::transaction::{BlockEnv, EvmTransaction}; +use super::transaction::{BlockEnv, EvmTransactionSignedEcRecovered}; pub(crate) fn execute_tx + DatabaseCommit>( db: DB, block_env: BlockEnv, - tx: EvmTransaction, + tx: &EvmTransactionSignedEcRecovered, config_env: CfgEnv, ) -> Result> { let mut evm = revm::new(); diff --git a/module-system/module-implementations/sov-evm/src/evm/mod.rs b/module-system/module-implementations/sov-evm/src/evm/mod.rs index ee03fd513d..aa853bc2bf 100644 --- a/module-system/module-implementations/sov-evm/src/evm/mod.rs +++ b/module-system/module-implementations/sov-evm/src/evm/mod.rs @@ -19,9 +19,10 @@ pub type EthAddress = [u8; 20]; pub(crate) type Bytes32 = [u8; 32]; pub use conversions::prepare_call_env; -pub use transaction::EvmTransaction; +pub use transaction::RawEvmTransaction; use crate::experimental::SpecIdWrapper; + // Stores information about an EVM account #[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone, Default)] pub(crate) struct AccountInfo { diff --git a/module-system/module-implementations/sov-evm/src/evm/tests.rs b/module-system/module-implementations/sov-evm/src/evm/tests.rs index b30ff0c12b..8e2590ebd9 100644 --- a/module-system/module-implementations/sov-evm/src/evm/tests.rs +++ b/module-system/module-implementations/sov-evm/src/evm/tests.rs @@ -1,5 +1,6 @@ use std::convert::Infallible; +use reth_primitives::TransactionKind; use revm::db::CacheDB; use revm::primitives::{CfgEnv, KECCAK_EMPTY, U256}; use revm::{Database, DatabaseCommit}; @@ -9,10 +10,10 @@ use super::db::EvmDb; use super::db_init::InitEvmDb; use super::executor; use crate::evm::test_helpers::{output, SimpleStorageContract}; -use crate::evm::transaction::{BlockEnv, EvmTransaction}; +use crate::evm::transaction::BlockEnv; use crate::evm::{contract_address, AccountInfo}; +use crate::tests::dev_signer::DevSigner; use crate::Evm; - type C = sov_modules_api::default_context::DefaultContext; #[test] @@ -36,7 +37,8 @@ fn simple_contract_execution_in_memory_state() { fn simple_contract_execution + DatabaseCommit + InitEvmDb>( mut evm_db: DB, ) { - let caller: [u8; 20] = [11; 20]; + let dev_signer = DevSigner::new_random(); + let caller = dev_signer.address; evm_db.insert_account_info( caller, AccountInfo { @@ -50,12 +52,11 @@ fn simple_contract_execution + DatabaseCommit + let contract = SimpleStorageContract::new(); let contract_address = { - let tx = EvmTransaction { - to: None, - data: contract.byte_code().to_vec(), - ..Default::default() - }; + let tx = dev_signer + .sign_default_transaction(TransactionKind::Create, contract.byte_code().to_vec(), 1) + .unwrap(); + let tx = &tx.try_into().unwrap(); let result = executor::execute_tx(&mut evm_db, BlockEnv::default(), tx, CfgEnv::default()).unwrap(); contract_address(result).expect("Expected successful contract creation") @@ -66,26 +67,30 @@ fn simple_contract_execution + DatabaseCommit + { let call_data = contract.set_call_data(set_arg); - let tx = EvmTransaction { - to: Some(*contract_address.as_fixed_bytes()), - data: hex::decode(hex::encode(&call_data)).unwrap(), - nonce: 1, - ..Default::default() - }; + let tx = dev_signer + .sign_default_transaction( + TransactionKind::Call(contract_address.as_fixed_bytes().into()), + hex::decode(hex::encode(&call_data)).unwrap(), + 2, + ) + .unwrap(); + let tx = &tx.try_into().unwrap(); executor::execute_tx(&mut evm_db, BlockEnv::default(), tx, CfgEnv::default()).unwrap(); } let get_res = { let call_data = contract.get_call_data(); - let tx = EvmTransaction { - to: Some(*contract_address.as_fixed_bytes()), - data: hex::decode(hex::encode(&call_data)).unwrap(), - nonce: 2, - ..Default::default() - }; + let tx = dev_signer + .sign_default_transaction( + TransactionKind::Call(contract_address.as_fixed_bytes().into()), + hex::decode(hex::encode(&call_data)).unwrap(), + 3, + ) + .unwrap(); + let tx = &tx.try_into().unwrap(); let result = executor::execute_tx(&mut evm_db, BlockEnv::default(), tx, CfgEnv::default()).unwrap(); diff --git a/module-system/module-implementations/sov-evm/src/evm/transaction.rs b/module-system/module-implementations/sov-evm/src/evm/transaction.rs index 4ae947f500..6f0810e4f1 100644 --- a/module-system/module-implementations/sov-evm/src/evm/transaction.rs +++ b/module-system/module-implementations/sov-evm/src/evm/transaction.rs @@ -1,3 +1,7 @@ +use reth_primitives::{ + TransactionSignedEcRecovered as RethTransactionSignedEcRecovered, H160, H256, +}; + use super::{Bytes32, EthAddress}; #[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)] @@ -25,6 +29,7 @@ impl Default for BlockEnv { } } +/// Rlp encoded evm transaction. #[cfg_attr( feature = "native", derive(serde::Serialize), @@ -32,55 +37,46 @@ impl Default for BlockEnv { derive(schemars::JsonSchema) )] #[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)] -pub struct AccessListItem { - pub address: EthAddress, - pub storage_keys: Vec, +pub struct RawEvmTransaction { + /// Rlp data. + pub rlp: Vec, } -#[cfg_attr( - feature = "native", - derive(serde::Serialize), - derive(serde::Deserialize), - derive(schemars::JsonSchema) -)] -#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)] -pub struct EvmTransaction { - pub sender: EthAddress, - pub data: Vec, - pub gas_limit: u64, - pub gas_price: u128, - pub max_priority_fee_per_gas: u128, - pub max_fee_per_gas: u128, - pub to: Option, - pub value: u128, - pub nonce: u64, - pub access_lists: Vec, - pub chain_id: u64, - pub odd_y_parity: bool, - pub r: Bytes32, - pub s: Bytes32, - // todo remove it - pub hash: Bytes32, +/// EC recovered evm transaction. +pub struct EvmTransactionSignedEcRecovered { + tx: RethTransactionSignedEcRecovered, } -impl Default for EvmTransaction { - fn default() -> Self { - Self { - sender: Default::default(), - data: Default::default(), - gas_limit: u64::MAX, - gas_price: Default::default(), - max_priority_fee_per_gas: Default::default(), - max_fee_per_gas: Default::default(), - to: Default::default(), - value: Default::default(), - nonce: Default::default(), - access_lists: Default::default(), - chain_id: 1, - hash: Default::default(), - odd_y_parity: Default::default(), - r: Default::default(), - s: Default::default(), - } +impl EvmTransactionSignedEcRecovered { + /// Creates a new EvmTransactionSignedEcRecovered. + pub fn new(tx: RethTransactionSignedEcRecovered) -> Self { + Self { tx } + } + + /// Transaction hash. Used to identify transaction. + pub fn hash(&self) -> H256 { + self.tx.hash() + } + + /// Signer of transaction recovered from signature. + pub fn signer(&self) -> H160 { + self.tx.signer() + } + + /// Receiver of the transaction. + pub fn to(&self) -> Option { + self.tx.to().map(|to| to.into()) + } +} + +impl AsRef for EvmTransactionSignedEcRecovered { + fn as_ref(&self) -> &RethTransactionSignedEcRecovered { + &self.tx + } +} + +impl From for RethTransactionSignedEcRecovered { + fn from(tx: EvmTransactionSignedEcRecovered) -> Self { + tx.tx } } diff --git a/module-system/module-implementations/sov-evm/src/lib.rs b/module-system/module-implementations/sov-evm/src/lib.rs index 226c976474..bf8919fefd 100644 --- a/module-system/module-implementations/sov-evm/src/lib.rs +++ b/module-system/module-implementations/sov-evm/src/lib.rs @@ -31,7 +31,7 @@ mod experimental { use super::evm::db::EvmDb; use super::evm::transaction::BlockEnv; use super::evm::{DbAccount, EthAddress}; - use crate::evm::{Bytes32, EvmChainCfg, EvmTransaction}; + use crate::evm::{Bytes32, EvmChainCfg, RawEvmTransaction}; use crate::TransactionReceipt; #[derive(Clone)] @@ -89,7 +89,7 @@ mod experimental { pub(crate) block_env: sov_state::StateValue, #[state] - pub(crate) transactions: sov_state::StateMap, + pub(crate) transactions: sov_state::StateMap, #[state] pub(crate) receipts: sov_state::StateMap, diff --git a/module-system/module-implementations/sov-evm/src/query.rs b/module-system/module-implementations/sov-evm/src/query.rs index 8380b05bd7..c716cccab0 100644 --- a/module-system/module-implementations/sov-evm/src/query.rs +++ b/module-system/module-implementations/sov-evm/src/query.rs @@ -6,6 +6,7 @@ use reth_rpc_types::state::StateOverride; use reth_rpc_types::{BlockOverrides, CallRequest, TransactionRequest}; use revm::primitives::{CfgEnv, ExecutionResult}; use sov_modules_api::macros::rpc_gen; +use sov_modules_api::utils::to_jsonrpsee_error_object; use sov_state::WorkingSet; use tracing::info; @@ -62,7 +63,8 @@ impl Evm { ) -> RpcResult> { info!("evm module: eth_getTransactionByHash"); let evm_transaction = self.transactions.get(&hash.into(), working_set); - Ok(evm_transaction.map(|tx| tx.into())) + let result = evm_transaction.map(Transaction::try_from).transpose(); + result.map_err(|e| to_jsonrpsee_error_object(e, "ETH_RPC_ERROR")) } // TODO https://github.com/Sovereign-Labs/sovereign-sdk/issues/502 diff --git a/module-system/module-implementations/sov-evm/src/tests/call_tests.rs b/module-system/module-implementations/sov-evm/src/tests/call_tests.rs index d39e218a8f..350a74d767 100644 --- a/module-system/module-implementations/sov-evm/src/tests/call_tests.rs +++ b/module-system/module-implementations/sov-evm/src/tests/call_tests.rs @@ -1,3 +1,4 @@ +use reth_primitives::TransactionKind; use revm::primitives::{SpecId, KECCAK_EMPTY, U256}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::default_signature::private_key::DefaultPrivateKey; @@ -6,37 +7,39 @@ use sov_state::{ProverStorage, WorkingSet}; use crate::call::CallMessage; use crate::evm::test_helpers::SimpleStorageContract; -use crate::evm::transaction::EvmTransaction; use crate::evm::EthAddress; +use crate::tests::dev_signer::DevSigner; use crate::{AccountData, Evm, EvmConfig}; - type C = DefaultContext; -fn create_messages(contract_addr: EthAddress, set_arg: u32) -> Vec { +fn create_messages( + contract_addr: EthAddress, + set_arg: u32, + dev_signer: DevSigner, +) -> Vec { let mut transactions = Vec::default(); let contract = SimpleStorageContract::new(); // Contract creation. { - transactions.push(CallMessage { - tx: EvmTransaction { - to: None, - data: contract.byte_code().to_vec(), - ..Default::default() - }, - }); + let signed_tx = dev_signer + .sign_default_transaction(TransactionKind::Create, contract.byte_code().to_vec(), 0) + .unwrap(); + + transactions.push(CallMessage { tx: signed_tx }); } // Update contract state. { - transactions.push(CallMessage { - tx: EvmTransaction { - to: Some(contract_addr), - data: hex::decode(hex::encode(&contract.set_call_data(set_arg))).unwrap(), - nonce: 1, - ..Default::default() - }, - }); + let signed_tx = dev_signer + .sign_default_transaction( + TransactionKind::Call(contract_addr.into()), + hex::decode(hex::encode(&contract.set_call_data(set_arg))).unwrap(), + 1, + ) + .unwrap(); + + transactions.push(CallMessage { tx: signed_tx }); } transactions @@ -53,7 +56,9 @@ fn evm_test() { let sender = priv_key.pub_key(); let sender_addr = sender.to_address::<::Address>(); let sender_context = C::new(sender_addr); - let caller = [0; 20]; + + let dev_signer: DevSigner = DevSigner::new_random(); + let caller = dev_signer.address; let evm = Evm::::default(); @@ -73,14 +78,14 @@ fn evm_test() { evm.genesis(&config, working_set).unwrap(); - let contract_addr = hex::decode("bd770416a3345f91e4b34576cb804a576fa48eb1") + let contract_addr = hex::decode("819c5497b157177315e1204f52e588b393771719") .unwrap() .try_into() .unwrap(); let set_arg = 999; - for tx in create_messages(contract_addr, set_arg) { + for tx in create_messages(contract_addr, set_arg, dev_signer) { evm.call(tx, &sender_context, working_set).unwrap(); } diff --git a/module-system/module-implementations/sov-evm/src/tests/dev_signer.rs b/module-system/module-implementations/sov-evm/src/tests/dev_signer.rs new file mode 100644 index 0000000000..c7e83c3597 --- /dev/null +++ b/module-system/module-implementations/sov-evm/src/tests/dev_signer.rs @@ -0,0 +1,79 @@ +use ethers_core::rand::rngs::StdRng; +use ethers_core::rand::SeedableRng; +use reth_primitives::{ + public_key_to_address, sign_message, Bytes as RethBytes, Transaction as RethTransaction, + TransactionKind, TransactionSigned, TxEip1559 as RethTxEip1559, H256, +}; +use reth_rpc::eth::error::SignError; +use secp256k1::{PublicKey, SecretKey}; + +use crate::evm::{EthAddress, RawEvmTransaction}; + +/// ETH transactions signer used in tests. +pub(crate) struct DevSigner { + secret_key: SecretKey, + pub(crate) address: EthAddress, +} + +impl DevSigner { + /// Creates a new signer. + pub(crate) fn new(secret_key: SecretKey) -> Self { + let public_key = PublicKey::from_secret_key(secp256k1::SECP256K1, &secret_key); + let addr = public_key_to_address(public_key); + Self { + secret_key, + address: addr.into(), + } + } + + /// Creates a new signer with random private key. + pub(crate) fn new_random() -> Self { + let mut rng = StdRng::seed_from_u64(22); + let secret_key = SecretKey::new(&mut rng); + Self::new(secret_key) + } + + /// Signs Eip1559 transaction. + pub(crate) fn sign_transaction( + &self, + transaction: RethTxEip1559, + ) -> Result { + let transaction = RethTransaction::Eip1559(transaction); + + let tx_signature_hash = transaction.signature_hash(); + + let signature = sign_message( + H256::from_slice(self.secret_key.as_ref()), + tx_signature_hash, + ) + .map_err(|_| SignError::CouldNotSign)?; + + Ok(TransactionSigned::from_transaction_and_signature( + transaction, + signature, + )) + } + + /// Signs default Eip1559 transaction with to, data and nonce overridden. + pub(crate) fn sign_default_transaction( + &self, + to: TransactionKind, + data: Vec, + nonce: u64, + ) -> Result { + let reth_tx = RethTxEip1559 { + to, + input: RethBytes::from(data), + nonce, + chain_id: 1, + gas_limit: u64::MAX, + ..Default::default() + }; + + let signed = self.sign_transaction(reth_tx)?; + + Ok(RawEvmTransaction { + rlp: signed.envelope_encoded().to_vec(), + }) + } +} diff --git a/module-system/module-implementations/sov-evm/src/tests/mod.rs b/module-system/module-implementations/sov-evm/src/tests/mod.rs index 30f5b5e423..d5b55080e8 100644 --- a/module-system/module-implementations/sov-evm/src/tests/mod.rs +++ b/module-system/module-implementations/sov-evm/src/tests/mod.rs @@ -1,3 +1,4 @@ mod call_tests; mod cfg_tests; +pub(crate) mod dev_signer; mod tx_tests; diff --git a/module-system/module-schemas/schemas/sov-evm.json b/module-system/module-schemas/schemas/sov-evm.json index 28f23f5e32..00b39d8655 100644 --- a/module-system/module-schemas/schemas/sov-evm.json +++ b/module-system/module-schemas/schemas/sov-evm.json @@ -7,165 +7,25 @@ ], "properties": { "tx": { - "$ref": "#/definitions/EvmTransaction" + "$ref": "#/definitions/RawEvmTransaction" } }, "definitions": { - "AccessListItem": { + "RawEvmTransaction": { + "description": "Rlp encoded evm transaction.", "type": "object", "required": [ - "address", - "storage_keys" + "rlp" ], "properties": { - "address": { + "rlp": { + "description": "Rlp data.", "type": "array", "items": { "type": "integer", "format": "uint8", "minimum": 0.0 - }, - "maxItems": 20, - "minItems": 20 - }, - "storage_keys": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "maxItems": 32, - "minItems": 32 - } - } - } - }, - "EvmTransaction": { - "type": "object", - "required": [ - "access_lists", - "chain_id", - "data", - "gas_limit", - "gas_price", - "hash", - "max_fee_per_gas", - "max_priority_fee_per_gas", - "nonce", - "odd_y_parity", - "r", - "s", - "sender", - "value" - ], - "properties": { - "access_lists": { - "type": "array", - "items": { - "$ref": "#/definitions/AccessListItem" } - }, - "chain_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "data": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - } - }, - "gas_limit": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "gas_price": { - "type": "integer", - "format": "uint128", - "minimum": 0.0 - }, - "hash": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "maxItems": 32, - "minItems": 32 - }, - "max_fee_per_gas": { - "type": "integer", - "format": "uint128", - "minimum": 0.0 - }, - "max_priority_fee_per_gas": { - "type": "integer", - "format": "uint128", - "minimum": 0.0 - }, - "nonce": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, - "odd_y_parity": { - "type": "boolean" - }, - "r": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "maxItems": 32, - "minItems": 32 - }, - "s": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "maxItems": 32, - "minItems": 32 - }, - "sender": { - "type": "array", - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "maxItems": 20, - "minItems": 20 - }, - "to": { - "type": [ - "array", - "null" - ], - "items": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "maxItems": 20, - "minItems": 20 - }, - "value": { - "type": "integer", - "format": "uint128", - "minimum": 0.0 } } }