diff --git a/Cargo.lock b/Cargo.lock index f09c90c8bed..e0f2efb1010 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -434,6 +434,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "assert_matches" version = "1.5.0" @@ -489,6 +495,83 @@ dependencies = [ "wildmatch", ] +[[package]] +name = "aurora-engine-modexp" +version = "1.0.0" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.6.1#26a126231e1ce338598a7d9909779f32e4dce8a2" +dependencies = [ + "hex", + "num", +] + +[[package]] +name = "aurora-engine-precompiles" +version = "1.0.0" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.6.1#26a126231e1ce338598a7d9909779f32e4dce8a2" +dependencies = [ + "aurora-engine-modexp", + "aurora-engine-sdk", + "aurora-engine-types", + "ethabi", + "evm", + "hex", + "libsecp256k1", + "num", + "ripemd", + "sha2 0.10.6", + "sha3", + "zeropool-bn", +] + +[[package]] +name = "aurora-engine-sdk" +version = "1.0.0" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.6.1#26a126231e1ce338598a7d9909779f32e4dce8a2" +dependencies = [ + "aurora-engine-types", + "base64 0.21.0", + "sha2 0.10.6", + "sha3", +] + +[[package]] +name = "aurora-engine-transactions" +version = "1.0.0" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.6.1#26a126231e1ce338598a7d9909779f32e4dce8a2" +dependencies = [ + "aurora-engine-precompiles", + "aurora-engine-sdk", + "aurora-engine-types", + "evm", + "rlp", +] + +[[package]] +name = "aurora-engine-types" +version = "1.0.0" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=3.6.1#26a126231e1ce338598a7d9909779f32e4dce8a2" +dependencies = [ + "base64 0.21.0", + "borsh 0.10.3", + "bs58 0.5.1", + "hex", + "primitive-types 0.12.2", + "rlp", + "serde", + "serde_json", +] + +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -684,7 +767,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" dependencies = [ "arrayref", - "arrayvec", + "arrayvec 0.5.2", "cc", "cfg-if 0.1.10", "constant_time_eq", @@ -692,6 +775,15 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array 0.14.5", +] + [[package]] name = "block-buffer" version = "0.10.2" @@ -805,6 +897,16 @@ dependencies = [ "hashbrown 0.11.2", ] +[[package]] +name = "borsh" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +dependencies = [ + "borsh-derive 0.10.3", + "hashbrown 0.11.2", +] + [[package]] name = "borsh" version = "1.0.0" @@ -821,8 +923,21 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", + "borsh-derive-internal 0.9.3", + "borsh-schema-derive-internal 0.9.3", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn 1.0.103", +] + +[[package]] +name = "borsh-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +dependencies = [ + "borsh-derive-internal 0.10.3", + "borsh-schema-derive-internal 0.10.3", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.103", @@ -853,6 +968,17 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "borsh-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "borsh-schema-derive-internal" version = "0.9.3" @@ -864,6 +990,17 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "borsh-schema-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "brotli" version = "3.3.4" @@ -891,12 +1028,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "sha2 0.10.6", + "tinyvec", +] + [[package]] name = "bumpalo" version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + [[package]] name = "bytecheck" version = "0.6.8" @@ -1813,7 +1966,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer", + "block-buffer 0.10.2", "crypto-common", "subtle", ] @@ -1933,7 +2086,7 @@ dependencies = [ "curve25519-dalek", "ed25519", "rand_core 0.6.4", - "sha2", + "sha2 0.10.6", "subtle", ] @@ -2063,6 +2216,114 @@ dependencies = [ "xshell", ] +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types", + "hex", + "once_cell", + "regex", + "serde", + "serde_json", + "sha3", + "thiserror", + "uint", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash 0.8.0", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "tiny-keccak", +] + +[[package]] +name = "ethereum" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a89fb87a9e103f71b903b80b670200b54cc67a07578f070681f1fffb7396fb7" +dependencies = [ + "bytes", + "ethereum-types", + "hash-db", + "hash256-std-hasher", + "rlp", + "sha3", + "triehash", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash 0.8.0", + "impl-codec", + "impl-rlp", + "impl-serde", + "primitive-types 0.12.2", + "scale-info", + "uint", +] + +[[package]] +name = "evm" +version = "0.39.1" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?tag=v0.39.1#0334a09d6b6e83ff3a8da992e33f29ba95e0c9fe" +dependencies = [ + "auto_impl", + "ethereum", + "evm-core", + "evm-gasometer", + "evm-runtime", + "log", + "primitive-types 0.12.2", + "rlp", + "sha3", +] + +[[package]] +name = "evm-core" +version = "0.39.1" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?tag=v0.39.1#0334a09d6b6e83ff3a8da992e33f29ba95e0c9fe" +dependencies = [ + "primitive-types 0.12.2", +] + +[[package]] +name = "evm-gasometer" +version = "0.39.1" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?tag=v0.39.1#0334a09d6b6e83ff3a8da992e33f29ba95e0c9fe" +dependencies = [ + "evm-core", + "evm-runtime", + "primitive-types 0.12.2", +] + +[[package]] +name = "evm-runtime" +version = "0.39.1" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?tag=v0.39.1#0334a09d6b6e83ff3a8da992e33f29ba95e0c9fe" +dependencies = [ + "auto_impl", + "evm-core", + "primitive-types 0.12.2", + "sha3", +] + [[package]] name = "expect-test" version = "1.3.0" @@ -2134,6 +2395,18 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + [[package]] name = "fixedbitset" version = "0.4.2" @@ -2447,6 +2720,21 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +[[package]] +name = "hash-db" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d23bd4e7b5eda0d0f3a307e8b381fdc8ba9000f26fbe912250c0a4cc3956364a" + +[[package]] +name = "hash256-std-hasher" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92c171d55b98633f4ed3860808f004099b36c1cc29c42cfc53aa8591b21efcf2" +dependencies = [ + "crunchy", +] + [[package]] name = "hashbrown" version = "0.11.2" @@ -2566,7 +2854,17 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" dependencies = [ - "hmac", + "hmac 0.12.1", +] + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac", + "digest 0.9.0", ] [[package]] @@ -2578,6 +2876,17 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array 0.14.5", + "hmac 0.8.1", +] + [[package]] name = "http" version = "0.2.7" @@ -2715,6 +3024,44 @@ dependencies = [ "version_check", ] +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "indexer-example" version = "0.0.0" @@ -2789,12 +3136,15 @@ dependencies = [ "actix-rt", "anyhow", "assert_matches", + "aurora-engine-transactions", + "aurora-engine-types", "borsh 1.0.0", "bytesize", "chrono", "clap", "derive-enum-from-into", "derive_more", + "ethabi", "futures", "hex", "insta", @@ -2829,11 +3179,12 @@ dependencies = [ "node-runtime", "once_cell", "parking_lot 0.12.1", - "primitive-types", + "primitive-types 0.10.1", "rand", "rlp", "serde", "serde_json", + "sha3", "smart-default", "strum", "tempfile", @@ -3011,6 +3362,54 @@ dependencies = [ "zstd-sys", ] +[[package]] +name = "libsecp256k1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" +dependencies = [ + "arrayref", + "base64 0.13.0", + "digest 0.9.0", + "hmac-drbg", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand", + "serde", + "sha2 0.9.9", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +dependencies = [ + "libsecp256k1-core", +] + [[package]] name = "libsqlite3-sys" version = "0.26.0" @@ -3414,7 +3813,7 @@ dependencies = [ "near-crypto", "near-primitives", "near-primitives-core", - "num-rational", + "num-rational 0.3.2", "serde", "serde_json", "tempfile", @@ -3493,9 +3892,9 @@ dependencies = [ "near-store", "near-vm-runner", "node-runtime", - "num-rational", + "num-rational 0.3.2", "once_cell", - "primitive-types", + "primitive-types 0.10.1", "rand", "rand_chacha", "rayon", @@ -3521,11 +3920,11 @@ dependencies = [ "near-o11y", "near-parameters", "near-primitives", - "num-rational", + "num-rational 0.3.2", "once_cell", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "smart-default", "time", "tracing", @@ -3623,7 +4022,7 @@ dependencies = [ "near-store", "near-telemetry", "near-vm-runner", - "num-rational", + "num-rational 0.3.2", "once_cell", "percent-encoding", "rand", @@ -3681,7 +4080,7 @@ dependencies = [ "blake2", "bolero", "borsh 1.0.0", - "bs58", + "bs58 0.4.0", "curve25519-dalek", "derive_more", "ed25519-dalek", @@ -3691,11 +4090,11 @@ dependencies = [ "near-config-utils", "near-stdx", "once_cell", - "primitive-types", + "primitive-types 0.10.1", "secp256k1", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "subtle", "tempfile", "thiserror", @@ -3754,9 +4153,9 @@ dependencies = [ "near-o11y", "near-primitives", "near-store", - "num-rational", + "num-rational 0.3.2", "once_cell", - "primitive-types", + "primitive-types 0.10.1", "rand", "rand_hc", "serde_json", @@ -3873,7 +4272,7 @@ dependencies = [ "actix", "actix-cors", "actix-web", - "bs58", + "bs58 0.4.0", "derive_more", "easy-ext", "futures", @@ -3996,7 +4395,7 @@ dependencies = [ "anyhow", "async-trait", "borsh 1.0.0", - "bs58", + "bs58 0.4.0", "clap", "ed25519-dalek", "hex", @@ -4024,7 +4423,7 @@ dependencies = [ "secp256k1", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "strum", "thiserror", "tokio", @@ -4073,7 +4472,7 @@ dependencies = [ "rayon", "rlimit", "serde", - "sha2", + "sha2 0.10.6", "smart-default", "strum", "stun", @@ -4128,7 +4527,7 @@ dependencies = [ "insta", "near-account-id", "near-primitives-core", - "num-rational", + "num-rational 0.3.2", "serde", "serde_repr", "serde_yaml", @@ -4219,9 +4618,9 @@ dependencies = [ "near-rpc-error-macro", "near-stdx", "near-vm-runner", - "num-rational", + "num-rational 0.3.2", "once_cell", - "primitive-types", + "primitive-types 0.10.1", "rand", "rand_chacha", "reed-solomon-erasure", @@ -4243,17 +4642,17 @@ dependencies = [ "arbitrary", "base64 0.21.0", "borsh 1.0.0", - "bs58", + "bs58 0.4.0", "derive_more", "enum-map", "expect-test", "insta", "near-account-id", - "num-rational", + "num-rational 0.3.2", "serde", "serde_json", "serde_repr", - "sha2", + "sha2 0.10.6", "thiserror", ] @@ -4325,7 +4724,7 @@ dependencies = [ "near-ping", "near-primitives", "once_cell", - "sha2", + "sha2 0.10.6", "tokio", "tracing", ] @@ -4548,7 +4947,7 @@ dependencies = [ "near-vm-engine", "near-vm-types", "near-vm-vm", - "num-rational", + "num-rational 0.3.2", "once_cell", "parity-wasm 0.41.0", "parity-wasm 0.42.2", @@ -4560,7 +4959,7 @@ dependencies = [ "serde", "serde_json", "serde_repr", - "sha2", + "sha2 0.10.6", "sha3", "strum", "tempfile", @@ -4728,9 +5127,9 @@ dependencies = [ "near-telemetry", "near-vm-runner", "node-runtime", - "num-rational", + "num-rational 0.3.2", "once_cell", - "primitive-types", + "primitive-types 0.10.1", "rand", "rayon", "regex", @@ -4842,14 +5241,14 @@ dependencies = [ "near-vm-runner", "near-wallet-contract", "num-bigint 0.3.3", - "num-rational", + "num-rational 0.3.2", "num-traits", "once_cell", "rand", "rayon", "serde", "serde_json", - "sha2", + "sha2 0.10.6", "tempfile", "testlib", "thiserror", @@ -4885,6 +5284,20 @@ dependencies = [ "winapi", ] +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint 0.4.3", + "num-complex", + "num-integer", + "num-iter", + "num-rational 0.4.1", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.2.6" @@ -4907,6 +5320,26 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -4917,6 +5350,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.3.2" @@ -4930,6 +5374,18 @@ dependencies = [ "serde", ] +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint 0.4.3", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -5195,6 +5651,32 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "parity-scale-codec" +version = "3.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" +dependencies = [ + "arrayvec 0.7.4", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +dependencies = [ + "proc-macro-crate 2.0.2", + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "parity-wasm" version = "0.41.0" @@ -5425,7 +5907,21 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" dependencies = [ - "fixed-hash", + "fixed-hash 0.7.0", + "uint", +] + +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash 0.8.0", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", "uint", ] @@ -5445,7 +5941,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit", + "toml_edit 0.19.15", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +dependencies = [ + "toml_datetime", + "toml_edit 0.20.2", ] [[package]] @@ -5992,9 +6498,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ "bytes", + "rlp-derive", "rustc-hex", ] +[[package]] +name = "rlp-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "rocksdb" version = "0.21.0" @@ -6011,7 +6529,7 @@ version = "0.0.0" dependencies = [ "anyhow", "borsh 1.0.0", - "bs58", + "bs58 0.4.0", "bytesize", "cfg-if 1.0.0", "chrono", @@ -6032,7 +6550,7 @@ dependencies = [ "near-vm-runner", "nearcore", "node-runtime", - "num-rational", + "num-rational 0.3.2", "num-traits", "rand", "rand_xorshift", @@ -6120,7 +6638,7 @@ dependencies = [ "block_on_proc", "cfg-if 1.0.0", "hex", - "hmac", + "hmac 0.12.1", "http", "log", "maybe-async", @@ -6131,7 +6649,7 @@ dependencies = [ "serde", "serde-xml-rs", "serde_derive", - "sha2", + "sha2 0.10.6", "thiserror", "time", "tokio", @@ -6256,6 +6774,30 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scale-info" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef2175c2907e7c8bc0a9c3f86aeb5ec1f3b275300ad58a44d0c3ae379a5e52e" +dependencies = [ + "cfg-if 1.0.0", + "derive_more", + "parity-scale-codec", + "scale-info-derive", +] + +[[package]] +name = "scale-info-derive" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b8eb8fd61c5cdd3390d9b2132300a7e7618955b98b8416f118c1b4e144f" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.103", +] + [[package]] name = "schannel" version = "0.1.19" @@ -6525,6 +7067,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "sha2" version = "0.10.6" @@ -7057,6 +7612,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -7210,6 +7774,17 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.0.0", + "toml_datetime", + "winnow", +] + [[package]] name = "tonic" version = "0.6.2" @@ -7413,6 +7988,16 @@ dependencies = [ "tracing-log 0.2.0", ] +[[package]] +name = "triehash" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1631b201eb031b563d2e85ca18ec8092508e262a3196ce9bd10a67ec87b9f5c" +dependencies = [ + "hash-db", + "rlp", +] + [[package]] name = "try-lock" version = "0.2.3" @@ -7467,9 +8052,9 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "uint" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ "byteorder", "crunchy", diff --git a/Cargo.toml b/Cargo.toml index 73ed4457d5d..9d3ff61ee53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,6 +121,8 @@ arbitrary = { version = "1.2.3", features = ["derive"] } arc-swap = "1.5" assert_matches = "1.5.0" async-trait = "0.1.58" +aurora-engine-transactions = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.6.1" } +aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "3.6.1" } awc = { version = "3", features = ["openssl"] } backtrace = "0.3" base64 = "0.21" @@ -170,6 +172,7 @@ ed25519-dalek = { version = "2.1.0", default-features = false, features = [ elastic-array = "0.11" enum-map = "2.1.0" enumset = "1.0" +ethabi = "18" expect-test = "1.3.0" finite-wasm = "0.5.0" fs2 = "0.4" diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 94bcc438f73..2f3606f20ce 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -67,10 +67,14 @@ testlib.workspace = true [dev-dependencies] assert_matches.workspace = true +aurora-engine-transactions.workspace = true +aurora-engine-types.workspace = true derive-enum-from-into.workspace = true +ethabi.workspace = true insta.workspace = true near-undo-block.workspace = true rlp.workspace = true +sha3.workspace = true [features] performance_stats = [ diff --git a/integration-tests/src/tests/client/features/wallet_contract.rs b/integration-tests/src/tests/client/features/wallet_contract.rs index 9666c2a61a5..2f1a8b6bd22 100644 --- a/integration-tests/src/tests/client/features/wallet_contract.rs +++ b/integration-tests/src/tests/client/features/wallet_contract.rs @@ -1,12 +1,15 @@ use assert_matches::assert_matches; +use aurora_engine_transactions::eip_2930::Transaction2930; +use aurora_engine_transactions::EthTransactionKind; +use aurora_engine_types::types::{Address, Wei}; +use ethabi::ethereum_types::U256; use near_chain_configs::{Genesis, NEAR_BASE}; use near_client::{test_utils::TestEnv, ProcessTxResponse}; -use near_crypto::{InMemorySigner, KeyType, SecretKey}; -use near_primitives::errors::{ - ActionError, ActionErrorKind, FunctionCallError, InvalidAccessKeyError, InvalidTxError, - TxExecutionError, -}; -use near_primitives::test_utils::eth_implicit_test_account; +use near_crypto::{InMemorySigner, KeyType, PublicKey, SecretKey}; +use near_primitives::account::id::AccountIdRef; +use near_primitives::account::{AccessKeyPermission, FunctionCallPermission}; +use near_primitives::errors::{InvalidAccessKeyError, InvalidTxError}; +use near_primitives::test_utils::{create_user_test_signer, eth_implicit_test_account}; use near_primitives::transaction::{ Action, AddKeyAction, DeployContractAction, FunctionCallAction, SignedTransaction, TransferAction, @@ -23,13 +26,9 @@ use near_vm_runner::ContractCode; use near_wallet_contract::{wallet_contract, wallet_contract_magic_bytes}; use nearcore::test_utils::TestEnvNightshadeSetupExt; use node_runtime::ZERO_BALANCE_ACCOUNT_STORAGE_LIMIT; -use rlp::RlpStream; -use testlib::runtime_utils::{alice_account, bob_account, carol_account}; +use testlib::runtime_utils::{alice_account, bob_account}; -use crate::{ - node::{Node, RuntimeNode}, - tests::client::process_blocks::produce_blocks_from_height, -}; +use crate::tests::client::process_blocks::produce_blocks_from_height; /// Try to process tx in the next blocks, check that tx and all generated receipts succeed. /// Return height of the next block. @@ -43,6 +42,7 @@ fn check_tx_processing( assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); let next_height = produce_blocks_from_height(env, blocks_number, height); let final_outcome = env.clients[0].chain.get_final_transaction_result(&tx_hash).unwrap(); + println!("{final_outcome:?}"); assert_matches!(final_outcome.status, FinalExecutionStatus::SuccessValue(_)); next_height } @@ -65,6 +65,22 @@ fn view_request(env: &TestEnv, request: QueryRequest) -> QueryResponse { .unwrap() } +fn view_balance(env: &TestEnv, account: &AccountIdRef) -> u128 { + let request = QueryRequest::ViewAccount { account_id: account.into() }; + match view_request(&env, request).kind { + QueryResponseKind::ViewAccount(view) => view.amount, + _ => panic!("wrong query response"), + } +} + +fn view_nonce(env: &TestEnv, account: &AccountIdRef, pk: PublicKey) -> u64 { + let request = QueryRequest::ViewAccessKey { account_id: account.into(), public_key: pk }; + match view_request(&env, request).kind { + QueryResponseKind::AccessKey(view) => view.nonce, + _ => panic!("wrong query response"), + } +} + /// Tests that ETH-implicit account is created correctly, with Wallet Contract hash. #[test] fn test_eth_implicit_account_creation() { @@ -214,126 +230,258 @@ fn test_transaction_from_eth_implicit_account_fail() { assert_eq!(response, expected_tx_error); } -// TODO(eth-implicit) Remove this test and replace it with tests that directly call the `Wallet Contract` when it is ready. -/// Creating an ETH-implicit account with meta-transaction, then attempting to use it with another meta-transaction. -/// -/// The `create_account` parameter controls whether we create ETH-implicit account -/// before attempting to use it by making a function call. -/// Depending on `rlp_transaction` blob that is sent to the `Wallet Contract` -/// the transaction is either authorized or unauthorized. -/// The `authorized` parameter controls which case will be tested. -fn meta_tx_call_wallet_contract(create_account: bool, authorized: bool) { +#[test] +fn test_wallet_contract_interaction() { if !checked_feature!("stable", EthImplicitAccounts, PROTOCOL_VERSION) { return; } - let genesis = Genesis::test(vec![alice_account(), bob_account(), carol_account()], 3); + + let genesis = Genesis::test(vec!["test0".parse().unwrap(), alice_account(), bob_account()], 1); + let mut env = TestEnv::builder(&genesis.config).nightshade_runtimes(&genesis).build(); + + let genesis_block = env.clients[0].chain.get_block_by_height(0).unwrap(); + let mut height = 1; + let blocks_number = 10; + + // As the relayer, alice will be sending Near transactions which + // contain the Ethereum transactions the user signs. let relayer = alice_account(); - let node = RuntimeNode::new_from_genesis(&relayer, genesis); - let sender = bob_account(); + let mut relayer_signer = + NearSigner { account_id: &relayer, signer: create_user_test_signer(&relayer) }; + // Bob will receive a $NEAR transfer from the eth implicit account + let receiver = bob_account(); + // Generate an eth implicit account for the user let secret_key = SecretKey::from_seed(KeyType::SECP256K1, "test"); let public_key = secret_key.public_key(); let eth_implicit_account = derive_eth_implicit_account_id(public_key.unwrap_as_secp256k1()); - let other_public_key = SecretKey::from_seed(KeyType::SECP256K1, "test2").public_key(); - - // Although ETH-implicit account can be zero-balance, we pick 1 here in order to make transfer later from this account. - let transfer_amount = 1u128; - let actions = vec![Action::Transfer(TransferAction { deposit: transfer_amount })]; - - if create_account { - // Create ETH-implicit account by funding it. - node.user() - .meta_tx(sender.clone(), eth_implicit_account.clone(), relayer.clone(), actions) - .unwrap() - .assert_success(); - } - let target = carol_account(); - let initial_balance = node.view_balance(&target).expect("failed looking up balance"); - - // TODO(eth-implicit) Append appropriate values to the RLP stream when proper `Wallet Contract` is implemented. - let mut stream = RlpStream::new_list(3); - stream.append(&target.as_str()); - // The RLP trait `Encodable` is not implemented for `u128`. We must encode it as bytes. - // TODO(eth-implicit) Do not try to encode `u128` values directly, see https://github.com/near/nearcore/pull/10269#discussion_r1425585051. - stream.append(&transfer_amount.to_be_bytes().as_slice()); - if authorized { - stream.append(&public_key.key_data()); - } else { - stream.append(&other_public_key.key_data()); - } - let rlp_encoded_data = stream.out().to_vec(); + // Create ETH-implicit account by funding it. + // Although ETH-implicit account can be zero-balance, we pick a non-zero amount + // here in order to make transfer later from this account. + let deposit_for_account_creation = NEAR_BASE; + let actions = vec![Action::Transfer(TransferAction { deposit: deposit_for_account_creation })]; + let nonce = + view_nonce(&env, relayer_signer.account_id, relayer_signer.signer.public_key.clone()) + 1; + let block_hash = *genesis_block.hash(); + let signed_transaction = SignedTransaction::from_actions( + nonce, + relayer.clone(), + eth_implicit_account.clone(), + &relayer_signer.signer, + actions, + block_hash, + ); + height = check_tx_processing(&mut env, signed_transaction, height, blocks_number); - let args = serde_json::json!({ - "target": target.to_string(), - "rlp_transaction": rlp_encoded_data, - }) - .to_string() + // The relayer adds its key to the eth implicit account so that + // can sign Near transactions for the user. + let relayer_pk = relayer_signer.signer.public_key.clone(); + let action = Action::AddKey(Box::new(AddKeyAction { + public_key: relayer_pk, + access_key: AccessKey { + nonce: 0, + permission: AccessKeyPermission::FunctionCall(FunctionCallPermission { + allowance: None, + receiver_id: eth_implicit_account.to_string(), + method_names: vec!["rlp_execute".into()], + }), + }, + })); + let signed_transaction = create_rlp_execute_tx( + ð_implicit_account, + action, + 0, + ð_implicit_account, + &secret_key, + &mut relayer_signer, + &env, + ); + height = check_tx_processing(&mut env, signed_transaction, height, blocks_number); + + // Now the relayer can sign transactions for the implicit account directly + relayer_signer.account_id = ð_implicit_account; + + let init_wallet_balance = view_balance(&env, ð_implicit_account); + let init_receiver_balance = view_balance(&env, &receiver); + + // The user signs a transaction to transfer some $NEAR + let transfer_amount = NEAR_BASE / 7; + let action = Action::Transfer(TransferAction { deposit: transfer_amount }); + let signed_transaction = create_rlp_execute_tx( + &receiver, + action, + 1, + ð_implicit_account, + &secret_key, + &mut relayer_signer, + &env, + ); + check_tx_processing(&mut env, signed_transaction, height, blocks_number); + + let final_wallet_balance = view_balance(&env, ð_implicit_account); + let final_receiver_balance = view_balance(&env, &receiver); + + assert_eq!(final_receiver_balance - init_receiver_balance, transfer_amount); + let wallet_balance_diff = init_wallet_balance - final_wallet_balance; + // Wallet balance is a little lower due to gas fees. + assert!(wallet_balance_diff - transfer_amount < NEAR_BASE / 500); +} + +fn create_rlp_execute_tx( + target: &AccountIdRef, + mut action: Action, + nonce: u64, + eth_implicit_account: &AccountIdRef, + secret_key: &SecretKey, + near_signer: &mut NearSigner<'_>, + env: &TestEnv, +) -> SignedTransaction { + const CHAIN_ID: u64 = 0x4ea7; + // handles 24 vs 18 decimal mismatch between $NEAR and $ETH + const MAX_YOCTO_NEAR: u128 = 1_000_000; + + // Construct Eth transaction from user's intended action + let value = match &mut action { + Action::Transfer(tx) => { + let raw_amount = tx.deposit; + tx.deposit = raw_amount % MAX_YOCTO_NEAR; + Wei::new_u128(raw_amount / MAX_YOCTO_NEAR) + } + Action::FunctionCall(fn_call) => { + let raw_amount = fn_call.deposit; + fn_call.deposit = raw_amount % MAX_YOCTO_NEAR; + Wei::new_u128(raw_amount / MAX_YOCTO_NEAR) + } + _ => Wei::zero(), + }; + let tx_data = abi_encode(target.to_string(), action); + let transaction = Transaction2930 { + chain_id: CHAIN_ID, + nonce: nonce.into(), + gas_price: U256::zero(), + gas_limit: U256::zero(), + to: Some(derive_address(target)), + value, + data: tx_data, + access_list: Vec::new(), + }; + let signed_tx = sign_eth_transaction(transaction, &secret_key); + let signed_tx_bytes: Vec = (&signed_tx).into(); + let tx_bytes_b64 = near_primitives::serialize::to_base64(&signed_tx_bytes); + let args = format!( + r#"{{ + "target": "{target}", + "tx_bytes_b64": "{tx_bytes_b64}" + }}"# + ) .into_bytes(); + // Construct Near transaction to `rlp_execute` method let actions = vec![Action::FunctionCall(Box::new(FunctionCallAction { - method_name: "execute_rlp".to_owned(), + method_name: "rlp_execute".into(), args, - gas: 30_000_000_000_000, + gas: 300_000_000_000_000, deposit: 0, }))]; - // Call Wallet Contract with JSON-encoded arguments: `target` and `rlp_transaction`. The `rlp_transaction`'s value is RLP-encoded. - let tx_result = - node.user().meta_tx(sender, eth_implicit_account.clone(), relayer, actions).unwrap(); - let wallet_contract_call_result = &tx_result.receipts_outcome[1].outcome.status; - - if create_account && authorized { - // If the public key recovered from the RLP transaction's signature is valid for this ETH-implicit account, - // the transaction will succeed. `target`'s balance will increase by `transfer_amount`. - tx_result.assert_success(); - let final_balance = node.view_balance(&target).expect("failed looking up balance"); - assert_eq!(final_balance, initial_balance + transfer_amount); - return; - } + let nonce = view_nonce(env, near_signer.account_id, near_signer.signer.public_key.clone()) + 1; + let block_hash = *env.clients[0].chain.get_head_block().unwrap().hash(); + SignedTransaction::from_actions( + nonce, + near_signer.account_id.into(), + eth_implicit_account.into(), + &near_signer.signer, + actions, + block_hash, + ) +} - if create_account { - // The public key recovered from the RLP transaction's signature isn't valid for this ETH-implicit account. - // The Wallet Contract will reject this transaction. - let expected_error = near_primitives::views::ExecutionStatusView::Failure( - TxExecutionError::ActionError( - ActionError { - index: Some(0), - kind: ActionErrorKind::FunctionCallError { - 0: FunctionCallError::ExecutionError( - "Smart contract panicked: Public key does not match the Wallet Contract address." - .to_string() - ) - } - } - ) - ); - assert_eq!(wallet_contract_call_result, &expected_error); - } else { - // The Wallet Contract function call is not executed because the account does not exist. - let expected_error = near_primitives::views::ExecutionStatusView::Failure( - TxExecutionError::ActionError(ActionError { - index: Some(0), - kind: ActionErrorKind::AccountDoesNotExist { account_id: eth_implicit_account }, - }), - ); - assert_eq!(wallet_contract_call_result, &expected_error); +struct NearSigner<'a> { + account_id: &'a AccountIdRef, + signer: InMemorySigner, +} + +fn abi_encode(target: String, action: Action) -> Vec { + const ADD_KEY_SELECTOR: &[u8] = &[0x75, 0x3c, 0xe5, 0xab]; + const TRANSFER_SELECTOR: &[u8] = &[0x3e, 0xd6, 0x41, 0x24]; + + let mut buf = Vec::new(); + match action { + Action::AddKey(add_key) => { + buf.extend_from_slice(ADD_KEY_SELECTOR); + let (public_key_kind, public_key) = match add_key.public_key { + PublicKey::ED25519(key) => (0, key.as_ref().to_vec()), + PublicKey::SECP256K1(key) => (1, key.as_ref().to_vec()), + }; + let nonce = add_key.access_key.nonce; + let (is_full_access, is_limited_allowance, allowance, receiver_id, method_names) = + match add_key.access_key.permission { + AccessKeyPermission::FullAccess => (true, false, 0, String::new(), Vec::new()), + AccessKeyPermission::FunctionCall(permission) => ( + false, + permission.allowance.is_some(), + permission.allowance.unwrap_or_default(), + permission.receiver_id, + permission.method_names, + ), + }; + let tokens = &[ + ethabi::Token::Uint(public_key_kind.into()), + ethabi::Token::Bytes(public_key), + ethabi::Token::Uint(nonce.into()), + ethabi::Token::Bool(is_full_access), + ethabi::Token::Bool(is_limited_allowance), + ethabi::Token::Uint(allowance.into()), + ethabi::Token::String(receiver_id), + ethabi::Token::Array(method_names.into_iter().map(ethabi::Token::String).collect()), + ]; + buf.extend_from_slice(ðabi::encode(tokens)); + } + Action::Transfer(tx) => { + buf.extend_from_slice(TRANSFER_SELECTOR); + let tokens = &[ethabi::Token::String(target), ethabi::Token::Uint(tx.deposit.into())]; + buf.extend_from_slice(ðabi::encode(tokens)); + } + _ => unimplemented!(), } + buf } -/// Wallet Contract function call is rejected because the ETH-implicit account does not exist. -#[test] -fn meta_tx_call_wallet_contract_account_does_not_exist() { - meta_tx_call_wallet_contract(false, true); +fn sign_eth_transaction(transaction: Transaction2930, sk: &SecretKey) -> EthTransactionKind { + let mut rlp_stream = rlp::RlpStream::new(); + rlp_stream.append(&aurora_engine_transactions::eip_2930::TYPE_BYTE); + transaction.rlp_append_unsigned(&mut rlp_stream); + let message_hash = keccak256(rlp_stream.as_raw()); + let signature = sk.sign(&message_hash); + let bytes: [u8; 65] = match signature { + near_crypto::Signature::SECP256K1(x) => x.into(), + _ => panic!("Expected SECP256K1 key"), + }; + let v = bytes[64]; + let r = U256::from_big_endian(&bytes[0..32]); + let s = U256::from_big_endian(&bytes[32..64]); + let signed_transaction = aurora_engine_transactions::eip_2930::SignedTransaction2930 { + transaction, + parity: v, + r, + s, + }; + EthTransactionKind::Eip2930(signed_transaction) } -/// Wallet Contract function call fails because the provided public key does not match the ETH-implicit address. -#[test] -fn meta_tx_call_wallet_contract_unauthorized() { - meta_tx_call_wallet_contract(true, false); +fn keccak256(bytes: &[u8]) -> [u8; 32] { + use sha3::{Digest, Keccak256}; + + Keccak256::digest(bytes).into() } -/// Wallet Contract function call is executed successfully. -#[test] -fn meta_tx_call_wallet_contract_authorized() { - meta_tx_call_wallet_contract(true, true); +fn derive_address(account_id: &AccountIdRef) -> Address { + let bytes = if account_id.as_str().starts_with("0x") { + let buf = hex::decode(&account_id.as_str()[2..42]).expect("account_id is hex encoded"); + return Address::try_from_slice(&buf).expect("slice is correct size"); + } else { + account_id.as_bytes() + }; + let hash = keccak256(bytes); + Address::try_from_slice(&hash[12..32]).expect("slice is correct size") }