Skip to content

Commit 39a6638

Browse files
hanchonfacs950xstepitfedekunzedependabot[bot]
authored
feat(vm): move geth vm from fork to evmOS codebase (evmos#2663)
* temp * run make format * fix unit tests * fix imports * add changelog entry * exclude x/evm/core from license checker * remove unnecessary rawdb * remove unused runtime folder * semgrep: skip iteration if map is empty * add new x/evm/folder to ignored path in golangci-lint * feat(evm): add custom EIPs to VM (evmos#2629) * chore: add custom eips integration tests (evmos#2661) * update custom eips + test * move eips to eips package * add eips tests * run make format * revert an error * add missing license to file * remove unused func * enable extra eip and refactor tests * add readme * Apply suggestions from code review Signed-off-by: Federico Kunze Küllmer <[email protected]> * update doc and remove unused default eips * make markdown linter happy * fix lint --------- Signed-off-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: 0xstepit <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]> * chore: merge main (evmos#2662) * chore: clean changelog (evmos#2628) remove duplicate and fix style * build(deps): bump github.com/cosmos/ibc-go/v7 from 7.5.2-0.20240607065443-0f1cf8bf766b to 7.6.0 (evmos#2631) * build(deps): bump github.com/cosmos/ibc-go/v7 Bumps [github.com/cosmos/ibc-go/v7](https://github.com/cosmos/ibc-go) from 7.5.2-0.20240607065443-0f1cf8bf766b to 7.6.0. - [Release notes](https://github.com/cosmos/ibc-go/releases) - [Changelog](https://github.com/cosmos/ibc-go/blob/v7.6.0/CHANGELOG.md) - [Commits](https://github.com/cosmos/ibc-go/commits/v7.6.0) --- updated-dependencies: - dependency-name: github.com/cosmos/ibc-go/v7 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * update gomod2nix.toml file * bump sdk and add chlog entry --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: tom <[email protected]> * build(deps-dev): bump ws from 7.5.9 to 7.5.10 in /contracts in the npm_and_yarn group across 1 directory (evmos#2634) build(deps-dev): bump ws Bumps the npm_and_yarn group with 1 update in the /contracts directory: [ws](https://github.com/websockets/ws). Updates `ws` from 7.5.9 to 7.5.10 - [Release notes](https://github.com/websockets/ws/releases) - [Commits](websockets/ws@7.5.9...7.5.10) --- updated-dependencies: - dependency-name: ws dependency-type: indirect dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * imp(tests): Add function to get ERC-20 balance to integration utils (evmos#2635) * add get erc20 balance util * add changelog entry * add missing license * build(deps): bump bufbuild/buf-setup-action from 1.33.0 to 1.34.0 (evmos#2637) Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.33.0 to 1.34.0. - [Release notes](https://github.com/bufbuild/buf-setup-action/releases) - [Commits](bufbuild/buf-setup-action@v1.33.0...v1.34.0) --- updated-dependencies: - dependency-name: bufbuild/buf-setup-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github.com/linxGnu/grocksdb from 1.9.1 to 1.9.2 (evmos#2638) * build(deps): bump github.com/linxGnu/grocksdb from 1.9.1 to 1.9.2 Bumps [github.com/linxGnu/grocksdb](https://github.com/linxGnu/grocksdb) from 1.9.1 to 1.9.2. - [Release notes](https://github.com/linxGnu/grocksdb/releases) - [Commits](linxGnu/grocksdb@v1.9.1...v1.9.2) --- updated-dependencies: - dependency-name: github.com/linxGnu/grocksdb dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * update gomod2nix.toml file * update rocksdb version --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: stepit <[email protected]> Co-authored-by: tom <[email protected]> * fix(ci): Ignore Swagger docs in CheckOV linter (evmos#2639) * ignore client folder in checkov CI * add changelog entry * add minor change in go file to trigger cla flow * Add: Support PebbleDB image (evmos#2630) * add: config & workflow step for building pebble images * test: comment out GIT_DIFF condition in build workflow * Revert "test: comment out GIT_DIFF condition in build workflow" * test: force a workflow trigger to push test images * Revert "test: force a workflow trigger to push test images" * docs: update changelog * Update: lint * Revert: build.yml * Update CHANGELOG.md Co-authored-by: Tom <[email protected]> Signed-off-by: Amine <[email protected]> --------- Signed-off-by: Amine <[email protected]> Signed-off-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: Tom <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]> * fix(tests): Bump Dockerfile dependency and fix make test-e2e target in Makefile (evmos#2642) * fix dockerfile and makefile * fix e2e tests * add changelog entry * imp(evm): Remove EthAccount type and use BaseAccount instead (evmos#2633) * remove use of EthAccount in repository * remove EthAccount implementation * add missing license * wip adding migration logic * fix migration * add tests for migration * run make format * Update x/evm/genesis.go Signed-off-by: MalteHerrmann <[email protected]> * address review comments and add test for exporting EVM genesis * add iterator and corresponding test * use contract iterator for exporting EVM genesis state * address more review comments * remove unused method from interface definition * apply suggested renaming * address review comments * add changelog entry * add gitleaks allow directive to example contract storage * move changelog entry to breaking section * revert change in local node script --------- Signed-off-by: MalteHerrmann <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> * imp(dist): Improve efficiency of reward claiming with distribution precompile (evmos#2643) * improve reward claim method * add changelog entry * address review comments --------- Signed-off-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]> * build(deps): bump github.com/btcsuite/btcd from 0.24.0 to 0.24.2 (evmos#2641) * build(deps): bump github.com/btcsuite/btcd from 0.24.0 to 0.24.2 Bumps [github.com/btcsuite/btcd](https://github.com/btcsuite/btcd) from 0.24.0 to 0.24.2. - [Release notes](https://github.com/btcsuite/btcd/releases) - [Changelog](https://github.com/btcsuite/btcd/blob/master/CHANGES) - [Commits](btcsuite/btcd@v0.24.0...v0.24.2) --- updated-dependencies: - dependency-name: github.com/btcsuite/btcd dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * update gomod2nix.toml file --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom <[email protected]> * imp(app): Split chain configuration template into EVM config and MemIAVL config (evmos#2644) * separate EVM config template from full Evmos chain config template for use in other repos * add changelog entry * address review comments * imp(ante): Fix typos in ante package (evmos#2647) * fix typos in ante package * address review comments * build(deps): bump github.com/cometbft/cometbft from 0.37.5 to 0.37.7 (evmos#2646) * build(deps): bump the go_modules group with 2 updates Bumps the go_modules group with 2 updates: [github.com/cometbft/cometbft](https://github.com/cometbft/cometbft) and [github.com/hashicorp/go-getter](https://github.com/hashicorp/go-getter). Updates `github.com/cometbft/cometbft` from 0.37.5 to 0.38.8 - [Release notes](https://github.com/cometbft/cometbft/releases) - [Changelog](https://github.com/cometbft/cometbft/blob/v0.38.8/CHANGELOG.md) - [Commits](cometbft/cometbft@v0.37.5...v0.38.8) Updates `github.com/hashicorp/go-getter` from 1.7.4 to 1.7.5 - [Release notes](https://github.com/hashicorp/go-getter/releases) - [Changelog](https://github.com/hashicorp/go-getter/blob/main/.goreleaser.yml) - [Commits](hashicorp/go-getter@v1.7.4...v1.7.5) --- updated-dependencies: - dependency-name: github.com/cometbft/cometbft dependency-type: direct:production dependency-group: go_modules - dependency-name: github.com/hashicorp/go-getter dependency-type: indirect dependency-group: go_modules ... Signed-off-by: dependabot[bot] <[email protected]> * update gomod2nix.toml file * update cometbft version bump --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: tom <[email protected]> Co-authored-by: Tom <[email protected]> * imp(ante): Decouple EVM decorator utilities from decorator struct (evmos#2648) * decouple evm decorator utils from concrete implementation * add changelog entry * build(deps): bump github.com/cometbft/cometbft from 0.37.7 to 0.37.8 (evmos#2649) * build(deps): bump github.com/cometbft/cometbft from 0.37.7 to 0.38.9 Bumps [github.com/cometbft/cometbft](https://github.com/cometbft/cometbft) from 0.37.7 to 0.38.9. - [Release notes](https://github.com/cometbft/cometbft/releases) - [Changelog](https://github.com/cometbft/cometbft/blob/v0.38.9/CHANGELOG.md) - [Commits](cometbft/cometbft@v0.37.7...v0.38.9) --- updated-dependencies: - dependency-name: github.com/cometbft/cometbft dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * update gomod2nix.toml file * update bump version --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: tom <[email protected]> * imp(scripts): Adjust contract compilation util to include abi.json files (evmos#2650) * adjust script to include abi.json files too * rename vesting interface file to match interface name * adjust utils and precompile ABI loading for Hardhat setup * clean up after compiling contracts with all target * recompile abis * add changelog entry * run black formatter * address some more linters --------- Co-authored-by: Tom <[email protected]> * build(deps): bump golang from 1.22.4-alpine3.20 to 1.22.5-alpine3.20 (evmos#2654) Bumps golang from 1.22.4-alpine3.20 to 1.22.5-alpine3.20. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump google.golang.org/grpc from 1.64.0 to 1.65.0 (evmos#2652) * build(deps): bump google.golang.org/grpc from 1.64.0 to 1.65.0 Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.64.0 to 1.65.0. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](grpc/grpc-go@v1.64.0...v1.65.0) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * update gomod2nix.toml file --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom <[email protected]> * Merge pull request from GHSA-68fc-7mhg-6f6c * fix(stk-precompile): update dirty state * add create validator tests cases * fix(distr-precompile): update dirty state * add additional condition in isContract * refactor test * add more functions to the DistrCaller.sol * fix(ics20-precompile) update dirty state * chore(tests): add more test cases for ics20 precompile * add multi-transfer tx test cases * chore(tests): add more test cases for distr precompile * Update precompiles/common/precompile.go Signed-off-by: Tom <[email protected]> * refactor getWithdrawerHexAddr func * chore(staking-precompile): update CreateValidator and EditValidator checks * chore(tests): update staking precompile tests * chore(distr-precompile): remove claimRewards method * make format * add back claimRewards func commented out * comment out claimRewards from distr precompile logic * add staking test with transfer to bonded tokens acc * chore(ibc-transfer): add escrow account to dirties * chore(test): add test cases for ics20 precompile and escrow addr * Update tests/nix_tests/test_ics20_precompile.py Co-authored-by: stepit <[email protected]> Signed-off-by: Tom <[email protected]> * remove hardcoded exp balance * fix(precompile): use cache ctx on stateDB * add journal entry for precompiles * keep only last writeFn * add MaxPrecompileCalls limit * refactor precompile calls logic * remove unnecessary code * changes based on review comments * add StakingReverter tests * add revert test case for distr precompile * refactor cache ctx on stateDB * refactor: move CommitWithCacheCtx to RunSetup * chore: add events to snapshot * update ICS20 tests * fix err msg * renamve var * add a func on precompile cmn for journal entry * rename var * add comment * update comment description * update expected gas in ibc transfer test * address review comments * update comt * tests(ics20): add helper func to setup contract * tests(ics20): add test for nested revert * address review comments * add distr precompile tests * refactor to remove UpdateDirties func * Update precompiles/distribution/tx.go Co-authored-by: Ramiro Carlucho <[email protected]> Signed-off-by: Tom <[email protected]> * update vesting prec * refactor balance change entries setter func * add comments * update comment * fix sdk fork deps * comment claimRewards method and test * add smart contract balance check on test * remove transient storage logic * add edge test case with revert on storage change * revert changes to claimRewards * refactor var name * refactor claimRewards logic * refactor claimRewards logic * update cosmos-sdk fork with latest changes (no need for store keys deep copy) * change require with assert for invariant * update comment * update cosmos-sdk fork version * update commit function with latest changes merged from main * add changelog entry * update commit func * fix claimRewards comt --------- Signed-off-by: Tom <[email protected]> Signed-off-by: stepit <[email protected]> Co-authored-by: stepit <[email protected]> Co-authored-by: Ramiro Carlucho <[email protected]> Co-authored-by: stepit <[email protected]> * chore: update changelog (evmos#2655) * Merge pull request from GHSA-q6hg-6m9x-5g9c * fix(precompile): add funder and dest check to update balance * add more test cases * restrict funder to be origin or contract caller * restrict dest address when calling from sc * add test case with funds transfer within precompile call * remove print * add check for dirty addresses * add UpdateDirties func * update dirties helper func * Update precompiles/vesting/utils_test.go Co-authored-by: stepit <[email protected]> Signed-off-by: Tom <[email protected]> * update comment description * changes based on review comments * refactor updateDirties * add test cases for updating funder balance before and after precompile call * add revert state test * update tx logic * update integration tests * refactor auth logic * update tests * add comt * fix: add funder and vest acc to dirties * add test cases for latest changes * address review comments * address review comments * address review comments * fix FlashLoan contract compilation * update logic * use pointer in precompile txs * remove unnecessary comment --------- Signed-off-by: Tom <[email protected]> Co-authored-by: stepit <[email protected]> * chore: update CHANGELOG & fix linter (evmos#2657) * add changelog entry * run make format * fix lint warnings * update known exceptions * fix lint warnings * fix lint warnings * fix lint warnings * update solidity test suite deps --------- Co-authored-by: GAtom22 <[email protected]> * [Snyk] Security upgrade golang from 1.22.3-bullseye to 1.23rc1-bullseye (evmos#2656) fix: tests/e2e/Dockerfile.repo to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-DEBIAN11-GNUTLS28-6159417 - https://snyk.io/vuln/SNYK-DEBIAN11-GNUTLS28-6159419 - https://snyk.io/vuln/SNYK-DEBIAN11-LIBSSH2-5861756 - https://snyk.io/vuln/SNYK-DEBIAN11-CURL-3320493 - https://snyk.io/vuln/SNYK-DEBIAN11-ZLIB-6008961 Co-authored-by: snyk-bot <[email protected]> Co-authored-by: Tom <[email protected]> * update certificate --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Amine <[email protected]> Signed-off-by: Federico Kunze Küllmer <[email protected]> Signed-off-by: MalteHerrmann <[email protected]> Signed-off-by: Tom <[email protected]> Signed-off-by: stepit <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: tom <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> Co-authored-by: Amine <[email protected]> Co-authored-by: Tom <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> Co-authored-by: Ramiro Carlucho <[email protected]> Co-authored-by: GAtom22 <[email protected]> Co-authored-by: snyk-bot <[email protected]> * chore: merge main again * run make format * Update CHANGELOG.md Signed-off-by: Guillermo Paoletti <[email protected]> * fix: remove import * chore: ignore linter on geth code --------- Signed-off-by: Federico Kunze Küllmer <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Amine <[email protected]> Signed-off-by: MalteHerrmann <[email protected]> Signed-off-by: Tom <[email protected]> Signed-off-by: stepit <[email protected]> Signed-off-by: Guillermo Paoletti <[email protected]> Co-authored-by: Freddy Caceres <[email protected]> Co-authored-by: 0xstepit <[email protected]> Co-authored-by: stepit <[email protected]> Co-authored-by: stepit <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: tom <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> Co-authored-by: Amine <[email protected]> Co-authored-by: Tom <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> Co-authored-by: Ramiro Carlucho <[email protected]> Co-authored-by: GAtom22 <[email protected]> Co-authored-by: snyk-bot <[email protected]> Co-authored-by: hanchon <[email protected]>
1 parent 78b24cc commit 39a6638

File tree

197 files changed

+20702
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+20702
-186
lines changed

.golangci.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ run:
22
tests: true
33
timeout: 5m
44
concurrency: 4
5+
skip-dirs:
6+
- x/evm/core
57

68
linters:
79
enable:
@@ -33,8 +35,6 @@ linters:
3335
- gofumpt
3436
- gomodguard
3537

36-
37-
3838
linters-settings:
3939
dogsled:
4040
max-blank-identifiers: 3
@@ -53,10 +53,10 @@ linters-settings:
5353
lang-version: "1.22"
5454
gomodguard:
5555
blocked:
56-
versions: # List of blocked module version constraints
57-
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
58-
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
59-
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
60-
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
61-
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
62-
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
56+
versions: # List of blocked module version constraints
57+
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
58+
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
59+
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
60+
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
61+
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
62+
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)

.semgrepignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ tests/
3030
.semgrep_logs/
3131

3232
# Documentation
33-
client/docs/
33+
client/docs/
34+
35+
# GETH code
36+
x/evm/core/

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
109109
- (evm) [#2594](https://github.com/evmos/evmos/pull/2594) Move `CallEVM` and `CallEVMWithData` to `x/evm` module.
110110
- (app) [#2597](https://github.com/evmos/evmos/pull/2597) Remove hardcoded Bech32 conversions for blocked precompile addresses.
111111
- (contracts) [#2613](https://github.com/evmos/evmos/pull/2613) Remove unused contract and make script useable with Python <3.12.
112+
- (evm) [#2663](https://github.com/evmos/evmos/pull/2663) Port Geth `core/vm` into Evmos `x/evm`.
112113
- (ante) [#2619](https://github.com/evmos/evmos/pull/2619) Change anteutils.TxFeeChecker to authante.TxFeeChecker.
113114
- (tests) [#2635](https://github.com/evmos/evmos/pull/2635) Add function to get ERC-20 balance to integration utils.
114115
- (ci) [#2630](https://github.com/evmos/evmos/pull/2630) Add PebbleDB image to docker-push workflow.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ COPY --from=build-env /target/usr/lib /usr/lib
4141
COPY --from=build-env /target/usr/local/lib /usr/local/lib
4242
COPY --from=build-env /target/usr/include /usr/include
4343

44-
RUN apk add --no-cache ca-certificates=20240226-r0 jq=1.7.1-r0 curl=8.8.0-r0 bash=5.2.26-r0 vim=9.1.0414-r0 lz4=1.9.4-r5 rclone=1.66.0-r3 \
44+
RUN apk add --no-cache ca-certificates=20240705-r0 jq=1.7.1-r0 curl=8.8.0-r0 bash=5.2.26-r0 vim=9.1.0414-r0 lz4=1.9.4-r5 rclone=1.66.0-r4 \
4545
&& addgroup -g 1000 evmos \
4646
&& adduser -S -h /home/evmos -D evmos -u 1000 -G evmos
4747

app/ante/evm/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/cosmos/cosmos-sdk/types/tx"
1010
"github.com/ethereum/go-ethereum/common"
1111
"github.com/ethereum/go-ethereum/core"
12-
"github.com/ethereum/go-ethereum/core/vm"
1312
"github.com/ethereum/go-ethereum/params"
13+
"github.com/evmos/evmos/v18/x/evm/core/vm"
1414

1515
"github.com/evmos/evmos/v18/x/evm/statedb"
1616
evmtypes "github.com/evmos/evmos/v18/x/evm/types"

app/app.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ import (
117117
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
118118
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
119119

120-
"github.com/ethereum/go-ethereum/core/vm"
120+
"github.com/evmos/evmos/v18/x/evm/core/vm"
121121

122122
// unnamed import of statik for swagger UI support
123123
_ "github.com/evmos/evmos/v18/client/docs/statik"
@@ -171,8 +171,8 @@ import (
171171
memiavlstore "github.com/crypto-org-chain/cronos/store"
172172

173173
// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
174-
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
175-
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
174+
_ "github.com/evmos/evmos/v18/x/evm/core/tracers/js"
175+
_ "github.com/evmos/evmos/v18/x/evm/core/tracers/native"
176176
)
177177

178178
func init() {

app/config.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Tharsis Labs Ltd.(Evmos)
2+
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)
3+
4+
package app
5+
6+
import (
7+
"github.com/evmos/evmos/v18/app/eips"
8+
evmconfig "github.com/evmos/evmos/v18/x/evm/config"
9+
"github.com/evmos/evmos/v18/x/evm/core/vm"
10+
)
11+
12+
// The init function of the config file allows to setup the global
13+
// configuration for the EVM, modifying the custom ones defined in evmOS.
14+
func init() {
15+
err := evmconfig.NewEVMConfigurator().
16+
WithExtendedEips(evmosActivators).
17+
Configure()
18+
if err != nil {
19+
panic(err)
20+
}
21+
}
22+
23+
// EvmosActivators defines a map of opcode modifiers associated
24+
// with a key defining the corresponding EIP.
25+
var evmosActivators = map[int]func(*vm.JumpTable){
26+
0o000: eips.Enable0000,
27+
0o001: eips.Enable0001,
28+
0o002: eips.Enable0002,
29+
}

app/eips/README.md

+258
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# Evmos Custom EIPs
2+
3+
This document explain how **evmOS** allows chain built on top of it to define custom EIPs to modify the behavior of EVM
4+
opcodes.
5+
6+
## Custom EIPs
7+
8+
Inside an EVM, every state transition or query is executed by evaluating opcodes. Custom EIPs are functions used to
9+
change the behavior of these opcodes to tailor the EVM functionalities to fit the app-chain requirements.
10+
11+
Custom EIPs should be defined in an `eips` package inside the `./app/eips/` folder of chains using the **evmOS**
12+
framework. This organization of custom implementations is not a strict requirement, but is the suggested approach to
13+
have a clean organization of functionalities. In this file, only the custom modifier should be defined.
14+
15+
Inside this package, custom EIP should be defined in a file called `eips.go`. In this file, the EIPs modifier should be
16+
defined with the signature:
17+
18+
```go
19+
func(jt *vm.JumpTable) {}
20+
```
21+
22+
where `vm` is the package `"github.com/evmos/evmos/v18/x/evm/core/vm"`.
23+
24+
Custom EIPs are used to modify the behavior of opcodes, which are described by the `operation` structure:
25+
26+
```go
27+
type operation struct {
28+
// execute is the operation function
29+
execute executionFunc
30+
constantGas uint64
31+
dynamicGas gasFunc
32+
// minStack tells how many stack items are required
33+
minStack int
34+
// maxStack specifies the max length the stack can have for this operation
35+
// to not overflow the stack.
36+
maxStack int
37+
38+
// memorySize returns the memory size required for the operation
39+
memorySize memorySizeFunc
40+
}
41+
```
42+
43+
With the **evmOS** framework, it is possible to modify any of the fields defined in the type via the `operation` setter
44+
methods:
45+
46+
- `SetExecute`: update the execution logic for the opcode.
47+
48+
- `SetConstantGas`: update the value used for the constant gas cost.
49+
50+
- `SetDynamicGas`: update the function used to compute the dynamic gas cost.
51+
52+
- `SetMinStack`: update the minimum number of items in the stack required to execute the `operation`.
53+
54+
- `SetMaxStack`: update the maximum number of items that will be in the stack after executing the `operation`.
55+
56+
- `SetMemorySize`: the memory size required by the `operation`.
57+
58+
An example for an EIP which modifies the constant gas used for the `CREATE` opcode is reported below:
59+
60+
```go
61+
// Enable a custom EIP-0000
62+
func Enable0000(jt *vm.JumpTable) {
63+
jt[vm.CREATE].SetConstantGas(1)
64+
}
65+
```
66+
67+
In the same folder should also be defined tests and contracts used to verify the EIPs logic.
68+
69+
## Activate Custom EIPs
70+
71+
The activation of custom EIPs should be done inside the `config.go` file defined in the `./app/` folder. This file has
72+
the role of the single source for modify the EVM implementation which is defined in the
73+
[`x/evm/`](https://github.com/evmos/evmos/tree/main/x/evm) folder
74+
of **evmOS**.
75+
76+
In this file, 3 main components should be defined:
77+
78+
- The custom EIPs, also called activators.
79+
- The additional default EIPs enabled.
80+
- The EVM configurator instance.
81+
82+
All these components will be described in the following sections.
83+
84+
### Opcode & EIP Activators
85+
86+
Activators is the name provided by [Go-ethereum](https://geth.ethereum.org/) to the definition of the structure
87+
grouping all possible non-default EIPs:
88+
89+
```go
90+
var activators = map[int]func(*JumpTable){
91+
3855: enable3855,
92+
...
93+
}
94+
```
95+
96+
It can be interpreted as a list of available functionalities that can be toggled to change opcodes behavior. The
97+
structure is a map where the key is the EIP number in the octal representation, and the value is the custom EIP
98+
function that has to be evaluated.
99+
100+
In **evmOS**, custom activators should be defined in a structure with the same data type, like in the example below:
101+
102+
```go
103+
// Activate custom EIPs: 0000, 0001, 0002, etc
104+
evmosActivators = map[int]func(*vm.JumpTable){
105+
0o000: eips.Enable0000,
106+
0o001: eips.Enable0001,
107+
0o002: eips.Enable0002,
108+
}
109+
```
110+
111+
It should be noted that the value of each key in the example is the modifier defined in the `eips` package in the
112+
example provided at the of the [Custom EIPs](#custom-eips) section.
113+
114+
### Default EIPs
115+
116+
Custom EIPs defined in the `activators` map are not enabled by default. This type is only used to define the list of
117+
custom functionalities that can be activated. To specify which custom EIP activate, we should modify the
118+
**evmOS** `x/evm` module params. The parameter orchestrating enabled custom EIPs is the `DefaultExtraEIPs` and
119+
**evmOS** provide an easy and safe way to customize it.
120+
121+
To specify which activator enable in the chain, a new variable containing a slice of keys of the custom activators
122+
should be defined. An example is reported below:
123+
124+
```go
125+
evmosEnabledEIPs = []int64{
126+
0o000,
127+
}
128+
```
129+
130+
In this way, even though the custom activators defined $3$ new EIPs, we are going to activate only the number `0o000`
131+
132+
### EVM Configurator
133+
134+
The EVM configuration is the type used to modify the EVM configuration before starting a node. The type is defined as:
135+
136+
```go
137+
type EVMConfigurator struct {
138+
extendedEIPs map[int]func(*vm.JumpTable)
139+
extendedDefaultExtraEIPs []int64
140+
sealed bool
141+
}
142+
```
143+
144+
Currently, only 2 customizations are possible:
145+
146+
- `WithExtendedEips`: extended the default available EIPs.
147+
148+
- `WithExtendedDefaultExtraEIPs`: extended the default active EIPs.
149+
150+
It is important to notice that the configurator will only allow to append new entries to the default ones defined by
151+
**evmOS**. The reason behind this choice is to ensure the correct and safe execution of the virtual machine but still
152+
allowing partners to customize their implementation.
153+
154+
The `EVMConfigurator` type should be constructed using the builder pattern inside the `init()` function of the file so
155+
that it is run during the creation of the application.
156+
157+
An example of the usage of the configurator is reported below:
158+
159+
```go
160+
configurator := evmconfig.NewEVMConfigurator().
161+
WithExtendedEips(customActivators).
162+
WithExtendedDefaultExtraEIPs(defaultEnabledEIPs...).
163+
Configure()
164+
165+
err := configurator.Configure()
166+
```
167+
168+
Errors are raised when the configurator tries to append an item with the same name of one of the default one. Since
169+
this type is used to configure the EVM before starting the node, it is safe, and suggested, to panic:
170+
171+
```go
172+
if err != nil {
173+
panic(err)
174+
}
175+
```
176+
177+
## Custom EIPs Deep Dive
178+
179+
When the chain receives an EVM transaction, it is handled by the `MsgServer` of the `x/evm` within the method
180+
`EthereumTx`. The method then calls `ApplyTransaction` where the EVM configuration is created:
181+
182+
```go
183+
cfg, err := k.EVMConfig(ctx, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress), k.eip155ChainID)
184+
```
185+
186+
During the creation of this type, a query is made to retrieve the `x/evm` params. After this step, the request is
187+
passed inside the `ApplyMessageWithConfig` where a new instance of the EVM is created:
188+
189+
```go
190+
evm := k.NewEVM(ctx, msg, cfg, tracer, stateDB)
191+
```
192+
193+
The `NewEVM` method calls the `NewEVMWithHooks` where a new instance of the virtual machine interpreter is created:
194+
195+
```go
196+
evm.interpreter = NewEVMInterpreter(evm, config)
197+
```
198+
199+
The management of activators is handled in this function:
200+
201+
```go
202+
func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
203+
// If jump table was not initialised we set the default one.
204+
if cfg.JumpTable == nil {
205+
cfg.JumpTable = DefaultJumpTable(evm.chainRules)
206+
for i, eip := range cfg.ExtraEips {
207+
// Deep-copy jumptable to prevent modification of opcodes in other tables
208+
copy := CopyJumpTable(cfg.JumpTable)
209+
if err := EnableEIP(eip, copy); err != nil {
210+
// Disable it, so caller can check if it's activated or not
211+
cfg.ExtraEips = append(cfg.ExtraEips[:i], cfg.ExtraEips[i+1:]...)
212+
log.Error("EIP activation failed", "eip", eip, "error", err)
213+
}
214+
cfg.JumpTable = copy
215+
}
216+
}
217+
218+
return &EVMInterpreter{
219+
evm: evm,
220+
cfg: cfg,
221+
}
222+
}
223+
```
224+
225+
As we can see, a new `JumpTable` is created if it is not received from previous evm executions in the same transaction.
226+
After that, the function iterate over the `ExtraEips` defined in the configuration. Then, it is checked if the EIP is
227+
associated with an activator. If yes, the activator function is execute, otherwise an error is returned and the EIP is
228+
removed from the VM configuration. At this point, all the opcodes are ready to be executed.
229+
230+
## How to Use It
231+
232+
In previous sections has been described required structures and files to use the EVM configurator to enable custom
233+
EIPs. In this the general procedure is taken into considerations. Two different scenarios are described:
234+
235+
- New chain.
236+
237+
- Running chain.
238+
239+
### New Chain
240+
241+
For a new chain starting from block genesis, the procedure described in the sections above is enough. To summarize it:
242+
243+
- Create the eip file with custom activators.
244+
245+
- Create the config file with custom activators, default EIPs, and the configurator.
246+
247+
After starting the chain, the genesis validation will perform all the required checks and the chain will be ready using
248+
the new custom EIPs.
249+
250+
### Running Chain
251+
252+
The proper approach to include and enable new EIPs, with the current state of the development, is via coordinate chain
253+
upgrade. During the chain upgrade it is important to define the custom activators since they are not stored in the
254+
chain. To enable them there are two possibilities:
255+
256+
- Write a migration to add the new enabled EIPsm during the upgrade.
257+
258+
- After the upgrade, create a governance proposal to modify the `x/evm` params.

0 commit comments

Comments
 (0)