From 883a73e3286823d05a3bf9d1e7c08853af1f6e8c Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:16:16 +0900 Subject: [PATCH] bump geth to v1.14.11 (#99) * bump geth to v1.14.11 * update precompiles --- go.mod | 4 +- go.sum | 10 ++-- integration-tests/go.mod | 10 ++-- integration-tests/go.sum | 24 ++++---- x/evm/keeper/context.go | 9 +-- x/evm/keeper/keeper.go | 9 ++- x/evm/keeper/precompiles.go | 57 +++++++------------ x/evm/precompiles/cosmos/contract.go | 23 ++++---- x/evm/precompiles/cosmos/contract_test.go | 18 +++--- x/evm/precompiles/erc20_registry/contract.go | 21 ++++--- .../erc20_registry/contract_test.go | 2 +- x/evm/types/address.go | 8 --- x/evm/types/expected_keeper.go | 4 +- 13 files changed, 89 insertions(+), 110 deletions(-) diff --git a/go.mod b/go.mod index 3d1da42..7830b3c 100644 --- a/go.mod +++ b/go.mod @@ -224,7 +224,7 @@ require ( github.com/status-im/keycard-go v0.2.0 // indirect github.com/strangelove-ventures/cometbft-client v0.1.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/supranational/blst v0.3.11 // indirect + github.com/supranational/blst v0.3.13 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect @@ -288,7 +288,7 @@ replace ( replace ( github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d - github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241027024417-b90d6257f9b7 + github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 // use custom version until this PR is merged // - https://github.com/strangelove-ventures/cometbft-client/pull/10 diff --git a/go.sum b/go.sum index aae3b67..447fba6 100644 --- a/go.sum +++ b/go.sum @@ -1094,8 +1094,6 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= @@ -1442,8 +1440,8 @@ github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 h1:V62KOhe6Em github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261/go.mod h1:KsQ7Wm/dw9N0l7Ypn3QKGwgUX5XinTlcHGIF0DSjsw4= github.com/initia-labs/cometbft-client v0.0.0-20240924071428-ef115cefa07e h1:k+pg63SFozCAK4LZFSiZtof6z69Tlu0O/Zftj1aAwes= github.com/initia-labs/cometbft-client v0.0.0-20240924071428-ef115cefa07e/go.mod h1:aVposiPW9FOUeAeJ7JjJRdE3g+L6i8YDxFn6Cv6+Az4= -github.com/initia-labs/evm v0.0.0-20241027024417-b90d6257f9b7 h1:m7ni67mL0+7qQCFXvjNPeEx3s91Oyxcu5UL82INOvMs= -github.com/initia-labs/evm v0.0.0-20241027024417-b90d6257f9b7/go.mod h1:Mq0biU2jbdmKSZoqOj29017ygFrMnB5/Rifwp980W4o= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 h1:JmJpxtYnF++Lj9MhD2LxOtgNAJM0aYqgO9nBkuhiGlI= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d h1:TLq8lB1PtQ0pjGf+bN8YgGVeLMuytZ26SBGMOs1seKY= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d/go.mod h1:zh6x1osR0hNvEcFrC/lhGD08sMfQmr9wHVvZ/mRWMCs= github.com/initia-labs/initia v0.6.0 h1:/39ZN26zeixxZZdcfY1sOitiBhfnG3lcbPtpFqd9z7A= @@ -1821,8 +1819,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= -github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/supranational/blst v0.3.13 h1:AYeSxdOMacwu7FBmpfloBz5pbFXDmJL33RuwnKtmTjk= +github.com/supranational/blst v0.3.13/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 86a16af..79d24a5 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -8,7 +8,7 @@ require ( github.com/cosmos/cosmos-sdk v0.50.10 github.com/cosmos/ibc-go/v8 v8.5.0 github.com/ethereum/go-ethereum v1.14.9 - github.com/initia-labs/initia v0.5.6 + github.com/initia-labs/initia v0.6.0 github.com/initia-labs/minievm v0.5.2 github.com/stretchr/testify v1.9.0 ) @@ -146,12 +146,12 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/initia-labs/OPinit v0.5.5 // indirect github.com/initia-labs/OPinit/api v0.5.1 // indirect - github.com/initia-labs/kvindexer v0.1.8 // indirect + github.com/initia-labs/kvindexer v0.1.9 // indirect github.com/initia-labs/kvindexer/submodules/block v0.1.0 // indirect github.com/initia-labs/kvindexer/submodules/evm-tx v0.1.2 // indirect github.com/initia-labs/kvindexer/submodules/pair v0.1.1 // indirect github.com/initia-labs/kvindexer/submodules/tx v0.1.0 // indirect - github.com/initia-labs/movevm v0.5.0 // indirect + github.com/initia-labs/movevm v0.6.0 // indirect github.com/jellydator/ttlcache/v3 v3.3.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmhodges/levigo v1.0.0 // indirect @@ -203,7 +203,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/supranational/blst v0.3.11 // indirect + github.com/supranational/blst v0.3.13 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect @@ -271,7 +271,7 @@ replace ( replace ( github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d - github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241027024417-b90d6257f9b7 + github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 // use custom version until this PR is merged // - https://github.com/strangelove-ventures/cometbft-client/pull/10 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 3d2e672..fafc6d6 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1059,8 +1059,6 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= @@ -1400,14 +1398,14 @@ github.com/initia-labs/OPinit/api v0.5.1 h1:zwyJf7HtKJCKvLJ1R9PjVfJO1L+d/jKoeFyT github.com/initia-labs/OPinit/api v0.5.1/go.mod h1:gHK6DEWb3/DqQD5LjKirUx9jilAh2UioXanoQdgqVfU= github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261 h1:V62KOhe6Em3wAvJsDVP+3is98I3mk/29OKNVs4IxeFQ= github.com/initia-labs/cometbft v0.0.0-20240925132752-ff8ff0126261/go.mod h1:KsQ7Wm/dw9N0l7Ypn3QKGwgUX5XinTlcHGIF0DSjsw4= -github.com/initia-labs/evm v0.0.0-20241027024417-b90d6257f9b7 h1:m7ni67mL0+7qQCFXvjNPeEx3s91Oyxcu5UL82INOvMs= -github.com/initia-labs/evm v0.0.0-20241027024417-b90d6257f9b7/go.mod h1:Mq0biU2jbdmKSZoqOj29017ygFrMnB5/Rifwp980W4o= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98 h1:JmJpxtYnF++Lj9MhD2LxOtgNAJM0aYqgO9nBkuhiGlI= +github.com/initia-labs/evm v0.0.0-20241105070652-c43b570a4e98/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d h1:TLq8lB1PtQ0pjGf+bN8YgGVeLMuytZ26SBGMOs1seKY= github.com/initia-labs/ibc-go/v8 v8.0.0-20240802003717-19c0b4ad450d/go.mod h1:zh6x1osR0hNvEcFrC/lhGD08sMfQmr9wHVvZ/mRWMCs= -github.com/initia-labs/initia v0.5.6 h1:7Um8tVTFHlYkt2kIpOzv5U6O3Z0izVJOZh+UXTmdFPU= -github.com/initia-labs/initia v0.5.6/go.mod h1:BPtxDrbu3HHnlZ8EGb3AZ5PDR4d+UVR5KMeX0K+oGI8= -github.com/initia-labs/kvindexer v0.1.8 h1:PZ7FPYZO2zFXBdnvVlwMFVv6O59fpgCObELxVYB0hBo= -github.com/initia-labs/kvindexer v0.1.8/go.mod h1:OV85HaQ9KVrg+zGPUlxT9RF9nAaM3Yq4/3MoHqGqhWk= +github.com/initia-labs/initia v0.6.0 h1:/39ZN26zeixxZZdcfY1sOitiBhfnG3lcbPtpFqd9z7A= +github.com/initia-labs/initia v0.6.0/go.mod h1:nTHzSyI6Ldv8uG98h/A6N+h/qcfrlbALB7UDabWqenY= +github.com/initia-labs/kvindexer v0.1.9 h1:rv/zD8VMU0+P7f+rTtYefIG93f3vRy55JqNK+fohQr8= +github.com/initia-labs/kvindexer v0.1.9/go.mod h1:OV85HaQ9KVrg+zGPUlxT9RF9nAaM3Yq4/3MoHqGqhWk= github.com/initia-labs/kvindexer/submodules/block v0.1.0 h1:y+EXnksd/I2F96mzIoQA64nZUZON2P+99YrSzeLCLoY= github.com/initia-labs/kvindexer/submodules/block v0.1.0/go.mod h1:4c+c59wVAnjuaJv/pcDYaUkeVmOqVV+orqEjya/RIjo= github.com/initia-labs/kvindexer/submodules/evm-tx v0.1.2 h1:1U+GayjFUAmMuNInTtUm5kj9RFdmd2t/+bmUTYoeFGM= @@ -1416,11 +1414,12 @@ github.com/initia-labs/kvindexer/submodules/pair v0.1.1 h1:o151gA4jIbqEl+pWTOCiz github.com/initia-labs/kvindexer/submodules/pair v0.1.1/go.mod h1:8X1GE1ZLkH7z8TKb5MUh7UClTkcqVFIwXIIRdsqeUZY= github.com/initia-labs/kvindexer/submodules/tx v0.1.0 h1:6kbf6wmzXPN0XCQLasiFgq1AlZHkt5K3/ZG+IWw1nNs= github.com/initia-labs/kvindexer/submodules/tx v0.1.0/go.mod h1:i0XeLbLa6xdgTR01WF8kaAO50vMmwxbeq0fKexwpFHU= -github.com/initia-labs/movevm v0.5.0 h1:dBSxoVyUumSE4x6/ZSOWtvbtZpw+V4W25/NH6qLU0uQ= -github.com/initia-labs/movevm v0.5.0/go.mod h1:aUWdvFZPdULjJ2McQTE+mLnfnG3CLAz0TWJRFzFFUwg= +github.com/initia-labs/movevm v0.6.0 h1:46JjDfOId6hfeoqYqKWTzPeb5ESQzzm8AhhGWYnFOmE= +github.com/initia-labs/movevm v0.6.0/go.mod h1:aUWdvFZPdULjJ2McQTE+mLnfnG3CLAz0TWJRFzFFUwg= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jellydator/ttlcache/v3 v3.3.0 h1:BdoC9cE81qXfrxeb9eoJi9dWrdhSuwXMAnHTbnBm4Wc= +github.com/jellydator/ttlcache/v3 v3.3.0/go.mod h1:bj2/e0l4jRnQdrnSTaGTsh4GSXvMjQcy41i7th0GVGw= github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls= github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -1771,8 +1770,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= -github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/supranational/blst v0.3.13 h1:AYeSxdOMacwu7FBmpfloBz5pbFXDmJL33RuwnKtmTjk= +github.com/supranational/blst v0.3.13/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= @@ -1852,6 +1851,7 @@ go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= diff --git a/x/evm/keeper/context.go b/x/evm/keeper/context.go index 140154c..91ebce7 100644 --- a/x/evm/keeper/context.go +++ b/x/evm/keeper/context.go @@ -193,7 +193,8 @@ func (k Keeper) CreateEVM(ctx context.Context, caller common.Address, tracer *tr stateDB, types.DefaultChainConfig(ctx), vmConfig, - k.precompiles.toMap(stateDB), + // use custom precompiles + k.Precompiles(stateDB), ) if tracer != nil { @@ -238,7 +239,7 @@ func (k Keeper) EVMStaticCallWithTracer(ctx context.Context, caller common.Addre sdkCtx := sdk.UnwrapSDKContext(ctx) gasBalance := k.computeGasLimit(sdkCtx) rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time) - evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, append(vm.ActivePrecompiles(rules), k.precompiles.toAddrs()...), accessList) + evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, k.precompileAddrs, accessList) retBz, gasRemaining, err := evm.StaticCall( vm.AccountRef(caller), @@ -276,7 +277,7 @@ func (k Keeper) EVMCallWithTracer(ctx context.Context, caller common.Address, co } rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time) - evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, append(vm.ActivePrecompiles(rules), k.precompiles.toAddrs()...), accessList) + evm.StateDB.Prepare(rules, caller, types.NullAddress, &contractAddr, k.precompileAddrs, accessList) retBz, gasRemaining, err := evm.Call( vm.AccountRef(caller), @@ -370,7 +371,7 @@ func (k Keeper) EVMCreateWithTracer(ctx context.Context, caller common.Address, } rules := evm.ChainConfig().Rules(evm.Context.BlockNumber, evm.Context.Random != nil, evm.Context.Time) - evm.StateDB.Prepare(rules, caller, types.NullAddress, nil, append(vm.ActivePrecompiles(rules), k.precompiles.toAddrs()...), accessList) + evm.StateDB.Prepare(rules, caller, types.NullAddress, nil, k.precompileAddrs, accessList) var gasRemaining uint64 if salt == nil { diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 64fb107..6c53cf5 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" evmconfig "github.com/initia-labs/minievm/x/evm/config" "github.com/initia-labs/minievm/x/evm/contracts/i_cosmos_callback" @@ -77,7 +78,9 @@ type Keeper struct { // evm stores EVMBlockHashes collections.Map[uint64, []byte] - precompiles precompiles + precompiles vm.PrecompiledContracts + precompileAddrs []common.Address + queryCosmosWhitelist types.QueryCosmosWhitelist cosmosCallbackABI *abi.ABI } @@ -154,7 +157,9 @@ func NewKeeper( EVMBlockHashes: collections.NewMap(sb, types.EVMBlockHashPrefix, "evm_block_hashes", collections.Uint64Key, collections.BytesValue), - precompiles: []precompile{}, + precompiles: vm.PrecompiledContracts{}, + precompileAddrs: []common.Address{}, + queryCosmosWhitelist: queryCosmosWhitelist, cosmosCallbackABI: cosmosCallbackABI, } diff --git a/x/evm/keeper/precompiles.go b/x/evm/keeper/precompiles.go index e290b68..a303bf6 100644 --- a/x/evm/keeper/precompiles.go +++ b/x/evm/keeper/precompiles.go @@ -1,20 +1,18 @@ package keeper import ( - "github.com/ethereum/go-ethereum/common" + "math/big" + "slices" + "github.com/ethereum/go-ethereum/core/vm" + sdk "github.com/cosmos/cosmos-sdk/types" + cosmosprecompile "github.com/initia-labs/minievm/x/evm/precompiles/cosmos" erc20registryprecompile "github.com/initia-labs/minievm/x/evm/precompiles/erc20_registry" "github.com/initia-labs/minievm/x/evm/types" ) -// precompile is a precompiled contract. -type precompile struct { - addr common.Address - contract vm.PrecompiledContract -} - // loadPrecompiles loads the precompiled contracts. func (k *Keeper) loadPrecompiles() error { erc20RegistryPrecompile, err := erc20registryprecompile.NewERC20RegistryPrecompile(k.erc20StoresKeeper) @@ -35,38 +33,25 @@ func (k *Keeper) loadPrecompiles() error { return err } - k.precompiles = precompiles{ - { - addr: common.BytesToAddress([]byte{0xf1}), - contract: cosmosPrecompile, - }, - { - addr: common.BytesToAddress([]byte{0xf2}), - contract: erc20RegistryPrecompile, - }, - } - - return nil -} + // prepare precompiles; always use latest chain config + // to load all precompiles. + chainConfig := types.DefaultChainConfig(sdk.Context{}) + rules := chainConfig.Rules(big.NewInt(1), true, 1) -// precompiles is a list of precompiled contracts. -type precompiles []precompile + precompiles := vm.ActivePrecompiledContracts(rules) + precompiles[types.CosmosPrecompileAddress] = cosmosPrecompile + precompiles[types.ERC20RegistryPrecompileAddress] = erc20RegistryPrecompile + k.precompiles = precompiles -// toMap converts the precompiles to a map. -func (ps precompiles) toMap(stateDB types.StateDB) map[common.Address]vm.PrecompiledContract { - m := make(map[common.Address]vm.PrecompiledContract) - for _, p := range ps { - m[p.addr] = p.contract.(types.WithStateDB).WithStateDB(stateDB) - } + precompileAddrs := slices.Clone(vm.ActivePrecompiles(rules)) + precompileAddrs = append(precompileAddrs, types.CosmosPrecompileAddress, types.ERC20RegistryPrecompileAddress) + k.precompileAddrs = precompileAddrs - return m + return nil } -func (ps precompiles) toAddrs() []common.Address { - addrs := make([]common.Address, len(ps)) - for i, p := range ps { - addrs[i] = p.addr - } - - return addrs +func (k *Keeper) Precompiles(stateDB types.StateDB) vm.PrecompiledContracts { + k.precompiles[types.CosmosPrecompileAddress].(types.SetStateDB).SetStateDB(stateDB) + k.precompiles[types.ERC20RegistryPrecompileAddress].(types.SetStateDB).SetStateDB(stateDB) + return k.precompiles } diff --git a/x/evm/precompiles/cosmos/contract.go b/x/evm/precompiles/cosmos/contract.go index 1e06a1f..3ca9cf6 100644 --- a/x/evm/precompiles/cosmos/contract.go +++ b/x/evm/precompiles/cosmos/contract.go @@ -22,9 +22,9 @@ import ( "github.com/initia-labs/minievm/x/evm/types" ) -var _ vm.ExtendedPrecompiledContract = CosmosPrecompile{} -var _ vm.PrecompiledContract = CosmosPrecompile{} -var _ types.WithStateDB = CosmosPrecompile{} +var _ vm.ExtendedPrecompiledContract = &CosmosPrecompile{} +var _ vm.PrecompiledContract = &CosmosPrecompile{} +var _ types.SetStateDB = &CosmosPrecompile{} type CosmosPrecompile struct { *abi.ABI @@ -49,13 +49,13 @@ func NewCosmosPrecompile( edk types.ERC20DenomKeeper, grpcRouter types.GRPCRouter, queryWhitelist types.QueryCosmosWhitelist, -) (CosmosPrecompile, error) { +) (*CosmosPrecompile, error) { abi, err := i_cosmos.ICosmosMetaData.GetAbi() if err != nil { - return CosmosPrecompile{}, err + return nil, err } - return CosmosPrecompile{ + return &CosmosPrecompile{ ABI: abi, cdc: cdc, ac: ac, @@ -67,12 +67,11 @@ func NewCosmosPrecompile( }, nil } -func (e CosmosPrecompile) WithStateDB(stateDB types.StateDB) vm.PrecompiledContract { +func (e *CosmosPrecompile) SetStateDB(stateDB types.StateDB) { e.stateDB = stateDB - return e } -func (e CosmosPrecompile) originAddress(ctx context.Context, addrBz []byte) (sdk.AccAddress, error) { +func (e *CosmosPrecompile) originAddress(ctx context.Context, addrBz []byte) (sdk.AccAddress, error) { account := e.ak.GetAccount(ctx, addrBz) if shorthandCallerAccount, ok := account.(types.ShorthandAccountI); ok { addr, err := shorthandCallerAccount.GetOriginalAddress(e.ac) @@ -87,7 +86,7 @@ func (e CosmosPrecompile) originAddress(ctx context.Context, addrBz []byte) (sdk } // ExtendedRun implements vm.ExtendedPrecompiledContract. -func (e CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { +func (e *CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { snapshot := e.stateDB.Snapshot() ctx := e.stateDB.ContextOfSnapshot(snapshot).WithGasMeter(storetypes.NewGasMeter(suppliedGas)) @@ -345,11 +344,11 @@ func (e CosmosPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppl } // RequiredGas implements vm.PrecompiledContract. -func (e CosmosPrecompile) RequiredGas(input []byte) uint64 { +func (e *CosmosPrecompile) RequiredGas(input []byte) uint64 { return 0 } // Run implements vm.PrecompiledContract. -func (e CosmosPrecompile) Run(input []byte) ([]byte, error) { +func (e *CosmosPrecompile) Run(input []byte) ([]byte, error) { return nil, errors.New("the CosmosPrecompile works exclusively with ExtendedRun") } diff --git a/x/evm/precompiles/cosmos/contract_test.go b/x/evm/precompiles/cosmos/contract_test.go index 8d2de8e..e15ecf7 100644 --- a/x/evm/precompiles/cosmos/contract_test.go +++ b/x/evm/precompiles/cosmos/contract_test.go @@ -67,7 +67,7 @@ func Test_CosmosPrecompile_IsBlockedAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -113,7 +113,7 @@ func Test_CosmosPrecompile_IsModuleAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -159,7 +159,7 @@ func Test_CosmosPrecompile_ToCosmosAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -190,7 +190,7 @@ func Test_CosmosPrecompile_ToEVMAddress(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -221,7 +221,7 @@ func Test_ExecuteCosmos(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -294,7 +294,7 @@ func Test_ExecuteCosmosWithOptions(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") cosmosAddr, err := ac.BytesToString(evmAddr.Bytes()) @@ -400,7 +400,7 @@ func Test_QueryCosmos(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") @@ -447,7 +447,7 @@ func Test_ToDenom(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") @@ -489,7 +489,7 @@ func Test_ToErc20(t *testing.T) { require.NoError(t, err) stateDB := NewMockStateDB(ctx) - cosmosPrecompile = cosmosPrecompile.WithStateDB(stateDB).(precompiles.CosmosPrecompile) + cosmosPrecompile.SetStateDB(stateDB) evmAddr := common.HexToAddress("0x1") diff --git a/x/evm/precompiles/erc20_registry/contract.go b/x/evm/precompiles/erc20_registry/contract.go index 3e2739b..6e15c76 100644 --- a/x/evm/precompiles/erc20_registry/contract.go +++ b/x/evm/precompiles/erc20_registry/contract.go @@ -12,9 +12,9 @@ import ( "github.com/initia-labs/minievm/x/evm/types" ) -var _ vm.ExtendedPrecompiledContract = ERC20RegistryPrecompile{} -var _ vm.PrecompiledContract = ERC20RegistryPrecompile{} -var _ types.WithStateDB = ERC20RegistryPrecompile{} +var _ vm.ExtendedPrecompiledContract = &ERC20RegistryPrecompile{} +var _ vm.PrecompiledContract = &ERC20RegistryPrecompile{} +var _ types.SetStateDB = &ERC20RegistryPrecompile{} type ERC20RegistryPrecompile struct { *abi.ABI @@ -22,18 +22,17 @@ type ERC20RegistryPrecompile struct { k types.IERC20StoresKeeper } -func NewERC20RegistryPrecompile(k types.IERC20StoresKeeper) (ERC20RegistryPrecompile, error) { +func NewERC20RegistryPrecompile(k types.IERC20StoresKeeper) (*ERC20RegistryPrecompile, error) { abi, err := i_erc20_registry.IErc20RegistryMetaData.GetAbi() if err != nil { - return ERC20RegistryPrecompile{}, err + return nil, err } - return ERC20RegistryPrecompile{ABI: abi, k: k}, nil + return &ERC20RegistryPrecompile{ABI: abi, k: k}, nil } -func (e ERC20RegistryPrecompile) WithStateDB(stateDB types.StateDB) vm.PrecompiledContract { +func (e *ERC20RegistryPrecompile) SetStateDB(stateDB types.StateDB) { e.stateDB = stateDB - return e } const ( @@ -44,7 +43,7 @@ const ( ) // ExtendedRun implements vm.ExtendedPrecompiledContract. -func (e ERC20RegistryPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { +func (e *ERC20RegistryPrecompile) ExtendedRun(caller vm.ContractRef, input []byte, suppliedGas uint64, readOnly bool) (resBz []byte, usedGas uint64, err error) { snapshot := e.stateDB.Snapshot() ctx := e.stateDB.ContextOfSnapshot(snapshot).WithGasMeter(storetypes.NewGasMeter(suppliedGas)) @@ -159,11 +158,11 @@ func (e ERC20RegistryPrecompile) ExtendedRun(caller vm.ContractRef, input []byte } // RequiredGas implements vm.PrecompiledContract. -func (e ERC20RegistryPrecompile) RequiredGas(input []byte) uint64 { +func (e *ERC20RegistryPrecompile) RequiredGas(input []byte) uint64 { return 0 } // Run implements vm.PrecompiledContract. -func (e ERC20RegistryPrecompile) Run(input []byte) ([]byte, error) { +func (e *ERC20RegistryPrecompile) Run(input []byte) ([]byte, error) { return nil, errors.New("the ERC20RegistryPrecompile works exclusively with ExtendedRun") } diff --git a/x/evm/precompiles/erc20_registry/contract_test.go b/x/evm/precompiles/erc20_registry/contract_test.go index d7494f9..57126c9 100644 --- a/x/evm/precompiles/erc20_registry/contract_test.go +++ b/x/evm/precompiles/erc20_registry/contract_test.go @@ -76,7 +76,7 @@ func Test_ERC20RegistryPrecompile(t *testing.T) { // set context stateDB := NewMockStateDB(ctx) - registry = registry.WithStateDB(stateDB).(precompiles.ERC20RegistryPrecompile) + registry.SetStateDB(stateDB) erc20Addr := common.HexToAddress("0x1") accountAddr := common.HexToAddress("0x2") diff --git a/x/evm/types/address.go b/x/evm/types/address.go index 30b6e69..ed764c7 100644 --- a/x/evm/types/address.go +++ b/x/evm/types/address.go @@ -22,14 +22,6 @@ var CosmosPrecompileAddress common.Address = common.HexToAddress("0xf1") // 0xf2 ERC20Registry precompile address var ERC20RegistryPrecompileAddress common.Address = common.HexToAddress("0xf2") -// 0xf3 ERC721Registry precompile address -var ERC721RegistryPrecompileAddress common.Address = common.HexToAddress("0xf3") - -// IsPrecompileAddress checks if the address is a precompile address -func IsPrecompileAddress(addr common.Address) bool { - return addr == ERC20RegistryPrecompileAddress || addr == CosmosPrecompileAddress -} - // Parse string contract address to sdk.AccAddress func ContractAddressFromString(ac address.Codec, contractAddrInString string) (contractAddr common.Address, err error) { if common.IsHexAddress(contractAddrInString) { diff --git a/x/evm/types/expected_keeper.go b/x/evm/types/expected_keeper.go index 6546333..85ecd85 100644 --- a/x/evm/types/expected_keeper.go +++ b/x/evm/types/expected_keeper.go @@ -90,8 +90,8 @@ type StateDB interface { ContextOfSnapshot(i int) sdk.Context } -type WithStateDB interface { - WithStateDB(stateDB StateDB) vm.PrecompiledContract +type SetStateDB interface { + SetStateDB(stateDB StateDB) } type GRPCRouter interface {