forked from cerc-io/laconicd-deprecated
d24bfe7965
* deps(sdk): bump to v0.46.4 (#1423) * deps(sdk): bump to v0.46.4 * deps(sdk): add IAVLDisableFastNode flag with false default * imp: reduce integration test block time to 2s (#1428) * build(deps): bump github.com/onsi/gomega from 1.23.0 to 1.24.0 (#1429) Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.23.0 to 1.24.0. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.23.0...v1.24.0) --- updated-dependencies: - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(rpc): different result from `eth_getProof` comparing with Ethereum (#1431) * align with eth_getProof for more info, see https://eips.ethereum.org/EIPS/eip-1186 * add GetHexProofs * add change doc * keep default res * fix lint * add e2e test * Apply suggestions from code review * fix lint * nix run -f ./nix gomod2nix * Refactor EIP-712 signature verification (#1397) * [WIP] EIP-712 Signature Refactor * Debug and add ante tests * Add tests for failure cases * Add changelog entry * Code cleanup * Add tests for MsgDelegate and MsgWithdrawDelegationReward * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Code cleanup * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Minor codefix * Update ethereum/eip712/encoding.go * Minor code revision updates * Refactor EIP712 unit tests to use test suite * Address import cycle and implement minor refactors * Fix lint issues * Add EIP712 unit suite test function * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Add minor refactors; increase test coverage * Correct ante_test for change in payload * Add single-signer util and tests * Update ethereum/eip712/encoding.go * Update ethereum/eip712/encoding.go * fix build Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * fix: build test on mac by updating to python3.10 (#1437) * build(deps): bump loader-utils from 1.4.0 to 1.4.1 in /tests/solidity (#1445) Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.4.0 to 1.4.1. - [Release notes](https://github.com/webpack/loader-utils/releases) - [Changelog](https://github.com/webpack/loader-utils/blob/v1.4.1/CHANGELOG.md) - [Commits](https://github.com/webpack/loader-utils/compare/v1.4.0...v1.4.1) --- updated-dependencies: - dependency-name: loader-utils dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * imp(evm): improve performance of EstimateGas (#1444) * imp(evm): improve performance of EstimateGas * changelog * fix(rpc): decode `finalized` block number (#1442) * fix(rpc): decode 'finalized' block number * changelog Co-authored-by: Freddy Caceres <facs95@gmail.com> * build(deps): bump github.com/onsi/gomega from 1.24.0 to 1.24.1 (#1449) Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.24.0 to 1.24.1. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.24.0...v1.24.1) --- updated-dependencies: - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github.com/spf13/viper from 1.13.0 to 1.14.0 (#1439) Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.13.0 to 1.14.0. - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.13.0...v1.14.0) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 4rgon4ut <59182467+4rgon4ut@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix: unstable tx_priority test (#1440) * fix unstable tx_priority test * Update tests/integration_tests/test_priority.py Co-authored-by: yihuang <huang@crypto.com> * Update tests/integration_tests/test_priority.py Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: Adi Saravanan <59209660+adisaran64@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * build(deps): bump github.com/cosmos/ibc-go/v5 from 5.0.1 to 5.1.0 (#1450) Bumps [github.com/cosmos/ibc-go/v5](https://github.com/cosmos/ibc-go) from 5.0.1 to 5.1.0. - [Release notes](https://github.com/cosmos/ibc-go/releases) - [Changelog](https://github.com/cosmos/ibc-go/blob/v5.1.0/CHANGELOG.md) - [Commits](https://github.com/cosmos/ibc-go/compare/v5.0.1...v5.1.0) --- updated-dependencies: - dependency-name: github.com/cosmos/ibc-go/v5 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump golangci/golangci-lint-action from 3.3.0 to 3.3.1 (#1454) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/v3.3.0...v3.3.1) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * refactor(all): refactor errors import to use cosmossdk.io (#1456) * refactor (errors) refactor errors import to use cosmossdk.io instead of cosmos-sdk/types/errors * refactor (errors) refactor errors import in ethsecp256k1 file * refactor (errors) add changes to changelog * build(deps): bump alpine from 3.16.2 to 3.16.3 (#1453) Bumps alpine from 3.16.2 to 3.16.3. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Empty KV gas config (#1460) * update sdk version * setup empty gas config * fix lint * fix integration tests * add Ante unit test * update changelog * test: remove unused integration tests (#1462) * fix: remove e2e github action (#1463) * remove unused tests * imp: remove e2e github action * build(deps): bump loader-utils from 1.4.1 to 1.4.2 in /tests/solidity (#1464) Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.4.1 to 1.4.2. - [Release notes](https://github.com/webpack/loader-utils/releases) - [Changelog](https://github.com/webpack/loader-utils/blob/v1.4.2/CHANGELOG.md) - [Commits](https://github.com/webpack/loader-utils/compare/v1.4.1...v1.4.2) --- updated-dependencies: - dependency-name: loader-utils dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore (deps): Update geth version to v1.10.25 (#1413) * build(deps): bump github.com/ethereum/go-ethereum Bumps [github.com/ethereum/go-ethereum](https://github.com/ethereum/go-ethereum) from 1.10.19 to 1.10.25. - [Release notes](https://github.com/ethereum/go-ethereum/releases) - [Commits](https://github.com/ethereum/go-ethereum/compare/v1.10.19...v1.10.25) --- updated-dependencies: - dependency-name: github.com/ethereum/go-ethereum dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * wip geth update * fix geth init flag order * add chainId to getTransaction. fix types comparison. update expected values on tests * wip add tracer config * tracers test * update tests * update to v1.10.25 * fix linter python * ignore error * fix lint * additional changes from diff * fix issues * solve lint issues * fix tests * fix flake * wrap types comparison in integration tests * fix integration tests * fix flake * update changelog Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * Add EIP-712 encoding support type for any array (#1430) * Add EIP-712 encoding support type for any array * Refactor implementation + add tests * Refactor unpacking implementation; refactor test case * Fix lint issue * Add MsgExec test case * Update comment for clarity * Add changelog entry * Refactor `sdkerrors` to `errorsmod` Co-authored-by: Freddy Caceres <facs95@gmail.com> * fix: extend geth config on integration tests (#1467) * changing git config and adding tests * removing print statements * remove unneccessary imports * fix flake * remove geth setup test Co-authored-by: Freddy Caceres <facs95@gmail.com> * tests: Add unit tests for rpc client endpoints (#1409) * test: add preliminary unit tests and additional mocks for chain_info, account_info and filters * tests: added additional mocked client calls * tests: bumped coverage of call_tx to 56% and chain_info to 77% * tests: bumped call_tx coverage to 70.2% and added additional mock client calls * tests: tx_info preliminary tests added for debugging. * tests: added test coverage for sign_tx and additional mocks * tests: tx_info test coverage bumped to 60.3% * test: coverage for tracing_tests now at 72% * tests: added fee makert query client mocks and bumped chain_info to 87.6% coverage. * tests: failing Cosmos auth module account query. * tests: added FeeMarket Params mock to call_tx_test * cleanup some unused code * tests: added helper function to test suite for signing a Tx and bumped coverage of tx_info to 71.2% * test: commented GetAccount error case and bumped chain_info to 90.3% coverage * test: cleanup of tests in node_info, sign_tx and account_info * Clean up print Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Apply suggestions from code review * fix import issues Co-authored-by: Vladislav Varadinov <vlad@evmos.org> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * Refactor to omit empty optionals from EIP-712 type generation (#1459) * Refactor to omit empty values from type creation; add test for v1.vote * Add test for createValidator with optional fields left blank * Add changelog entry * Update changelog entry Co-authored-by: Freddy Caceres <facs95@gmail.com> * fix: protogen scripts were not correctly implemented (#1466) * Delete local copy of third party proto files * Update protocgen script and buf yaml files to mirror cosmos-sdk * Update makefile commands for proto-gen and proto-swagger-gen to correctly use docker * Commit changed .pb.go files after updating the protogen scripts * Adjust grep in proto-tools-installer script to look for correct gogoproto replacement * address reviews - remove unnecessary ignore in buf.yaml and cosmos-sdk download in the protocgen script * remove proto-update-deps from makefile as we don't store local copies of third party protofiles anymore * Add changelog entry * Update protoc-swagger-gen.sh * Remove third party queries from swagger-ui config (for now) * fix integrations tests * fix dead changelog links (markdown-link-check) Co-authored-by: Freddy Caceres <facs95@gmail.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * added gas consumption test (#1474) * build(deps): bump github.com/cosmos/cosmos-proto (#1475) Bumps [github.com/cosmos/cosmos-proto](https://github.com/cosmos/cosmos-proto) from 1.0.0-alpha7 to 1.0.0-alpha8. - [Release notes](https://github.com/cosmos/cosmos-proto/releases) - [Commits](https://github.com/cosmos/cosmos-proto/compare/v1.0.0-alpha7...v1.0.0-alpha8) --- updated-dependencies: - dependency-name: github.com/cosmos/cosmos-proto dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: chain-id in grpc query is not initialized without abci event (#1405) * fix: chain-id in grpc query is not initialized without abci event Closes: #1404 Solution: - pass the chain-id from caller. * Update CHANGELOG.md * only override if input is not empty * add comment to chain id * pass chain-id to state transition * Update x/evm/keeper/grpc_query.go * Apply suggestions from code review * fix golang lint * update gomod2nix.toml * fix unit tests * update gomod2nix * api breaking changelog * add unit tests, and fix TraceBlock by the way * Update CHANGELOG.md * test --grpc-only mode in integration tests * remove tmp var * Update tests/integration_tests/test_grpc_only.py * Update x/evm/keeper/grpc_query_test.go Co-authored-by: mmsqe <tqd0800210105@gmail.com> * fix linters * fix nil pointer in tests * fix conflicts * fix conflicts * fixes * fix lint * fix unit test Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mmsqe <tqd0800210105@gmail.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * fix(evm): Simplify Gas Math (#1452) * fix math * changelog * imp(ante): refactor `AnteHandler` (#1455) * fix(ante): block gas check * refactor * rename * use gas wanted * remove consume gas logic on ante handler * comment * c++ * move min gas price * comment * Update app/ante/eth.go Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com> * fix build * fix integration test script Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * tests: add additional gas consumption tests (#1477) * split existing gas test * added contract call test * fix flake issues, update gomod2nix * isort imports * add stateful contract calls * chore: update proto make commands (#1471) * Update proto make commands to use cosmos docker image and add notes for possible problems * Apply make proto-all with new docker container * Remove stale DOCKER_BUF variable * Revert to using the tendermintdev/sdk-proto-gen docker image * remove '@' in proto-lint and proto-check-breaking for consistency with other commands * Remove unnecessary go get from protocgen.sh (only works after adding --network host to docker run) * Add --network host to docker run for compatibility on linux * use cosmos/proto-builder docker image for proto-format because clang-format is not installed on tendermintdev/sdk-proto-gen * update swagger docs after recent additions to evm.proto in #1413 Co-authored-by: Tomas Guerra <54514587+GAtom22@users.noreply.github.com> * Remove unbound labels from added custom tendermint metrics (#1434) * Remove unbound labels from added custom tendermint metrics * Add entry to changelog * deps: bump SDK to v0.46.6 (#1486) * deps: bump SDK to v0.46.6 * changelog * Update CHANGELOG.md Co-authored-by: Tomas Guerra <54514587+GAtom22@users.noreply.github.com> Co-authored-by: Tomas Guerra <54514587+GAtom22@users.noreply.github.com> * fear(eip712): Add EIP-712 encoding for multiple messages of the same type (#1483) * Add EIP-712 encoding for multiple messages of the same type * Fix Protobuf encoding bug * Add ante tests * Refactor naming and minor implementation details * Test empty transaction coverage * Address revisions for code clarity * Move aminoMessage type definition * fix: enable `fixIssue172` flag for non-deterministic keyring test (#1447) * enable fixIssue172 flag for test for more info, https://github.com/btcsuite/btcutil/pull/182/files * fix import * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Adi Saravanan <59209660+adisaran64@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * fix(tests): Delete inconsistent test (#1481) * Delete inconsistent test * delete test * build(deps): bump alpine from 3.16.3 to 3.17.0 (#1492) Bumps alpine from 3.16.3 to 3.17.0. --- updated-dependencies: - dependency-name: alpine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump google.golang.org/grpc from 1.50.1 to 1.51.0 (#1490) Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.50.1 to 1.51.0. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.50.1...v1.51.0) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github.com/onsi/ginkgo/v2 from 2.5.0 to 2.5.1 (#1489) Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.5.0 to 2.5.1. - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.5.0...v2.5.1) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: refactor imports naming for clarity (#1491) * chore: refactor imports naming for clarity * Merge main and fix conflicts * fix: align empty account result for old blocks as ethereum (#1484) * align result account as ethereum * add test_get_transaction_count * add change doc * sync gomod2nix * Apply suggestions from code review * crosscheck with ws & geth * sync gomod2nix * Update rpc/backend/utils.go * use session provider Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * imp(ante): refactor AnteHandler (#1479) * imp(ante): refactor AnteHandler * fix test * test * Adjust deprecated sdkerrors import (#1493) * refactor test files * Apply suggestions from code review Co-authored-by: 4rgon4ut <59182467+4rgon4ut@users.noreply.github.com> * lint * prioritization comment * fix test Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> Co-authored-by: 4rgon4ut <59182467+4rgon4ut@users.noreply.github.com> * chore: Update linter and protogen configuration (#1478) * add protolint yaml * Update .protolint.yml with Evmos settings * Add super-linter.yml for GH action * Copy .markdownlint.yml settings from Evmos * Sort proto imports * address protolint error in all Protobuf files * update Makefile to mirror Proto commands for Evmos * remove unnecessary go get command in protocgen.sh when using cosmos docker image * copy .clang-format from Evmos repo * apply make proto-format * Execute make proto-all after changes to config are complete * address last linter comment * fix(server): telemetry setup (#1497) * fix(server): telemetry setup * more fixes * fix * changelog * update standalone process * chore(evm) - Delete deprecated store migrations (#1498) * (fix): Delete deprecated migrations * Update x/evm/module.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix(evm): Added Cancun and Shanghai blocks to ChainConfig (#1499) * (refactor): Added Cancun and Shanghai blocks to ChainConfig * (tests): Added test for invalid Shanghai and Cancun block * (fix): ran proto linter * Applied changes from code review * Added CHANGELOG entry Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * chore(app): add store listener to Ethermint app (#1501) * add store listener to Ethermint app * add changelog entry * build(deps): bump cosmossdk.io/math from 1.0.0-beta.3 to 1.0.0-beta.4 (#1502) Bumps [cosmossdk.io/math](https://github.com/cosmos/cosmos-sdk) from 1.0.0-beta.3 to 1.0.0-beta.4. - [Release notes](https://github.com/cosmos/cosmos-sdk/releases) - [Changelog](https://github.com/cosmos/cosmos-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/cosmos/cosmos-sdk/compare/math/v1.0.0-beta.3...math/v1.0.0-beta.4) --- updated-dependencies: - dependency-name: cosmossdk.io/math dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(app): register node service (#1505) * fix(app): register node service * changelog * fix(cmd): add missing GetAuxToFeeCommand (#1504) Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> * chore(feemarket): Delete deprecated migration logic (#1508) * (refactor): Remove old migration code * (fix): Lint and add CHANGELOG entry * Remove simulation checks (#1507) * Add cli rollback command it's useful in app-hash mismatch situation. * Update CHANGELOG.md * (refactor): removed old sim tests logic * (fix): removed tests from CI * (fix): fix test.yml * (fix): format and lint * (fix): fix linter issue * (fix): fix linter issues v2 * (fix): linter * (fix): removed sim-test references * Applied changes from code review Co-authored-by: HuangYi <huang@crypto.com> * chore: verify fees refactor (#1496) * chore: verify fees refactor * adjust call structure in rest of repo after splitting up DeductTxCostsFromUserBalance * adjust test logic after splitting DeductTxCostsFromUserBalance up * remove outdated TODO * address PR comments - remove import name for evm keeper * remove misleading comment * address review comments - only handover boolean instead of context * remove TODO Co-authored-by: MalteHerrmann <malteherrmann.mail@web.de> Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> * json-rpc(filters) fix block hash on newBlock filter (#1503) * tests(filters) add block hash check on newBlock filter * tests(filters) fix linting errors * fix(filters): fix newBlock filter response * fix(filters): add changes on CHANGELOG file * fix(ci): add gitleaks config (#1513) * fix(ci): add gitleaks config to ignore init.sh * make ci lint init.sh Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * tests(filters): add/improve integration tests for JSON-RPC methods (#1480) * tests(filters) add block hash check on newBlock filter * tests(filters) add getLogs test cases * tests(filters) add eth_newFilter multiple filters test cases * tests(filters) add eth_newFilter and eth_eth_uninstallFilter test case * tests(filters) fix linting errors * tests(filters) fix linting error on imports * tests(filters) add test case: register filter before contract deploy * tests(filters) refactor logs topics assertion * tests(filters) add topics filter test cases * tests(filters) fix linting errors * tests(filters) remove unnecessary package.json file * tests(filters) update based on PR comments * tests(filters) separate getNewBlocks failing test to a separate PR * tests(filters) add retry on send_tx to avoid Timeout error * tests(filters) add logs by topic and block range test case * update gomod2nix * tests(filters) remove test elapsed time log Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * build(deps): bump minimist in /tests/integration_tests/hardhat (#1516) Bumps [minimist](https://github.com/minimistjs/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/minimistjs/minimist/releases) - [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md) - [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * tests(filters): add logs by topic test case (#1515) * tests(filters) add logs by topic test case * fix(logs): add getLogs http call in test * tests(logs) add test case for getLogs by topic * tests(logs) fix lint errors * chore(all): markdownlint (#1522) * build(deps): bump github.com/cosmos/cosmos-proto (#1525) Bumps [github.com/cosmos/cosmos-proto](https://github.com/cosmos/cosmos-proto) from 1.0.0-alpha8 to 1.0.0-beta.1. - [Release notes](https://github.com/cosmos/cosmos-proto/releases) - [Commits](https://github.com/cosmos/cosmos-proto/compare/v1.0.0-alpha8...v1.0.0-beta.1) --- updated-dependencies: - dependency-name: github.com/cosmos/cosmos-proto dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump decode-uri-component in /tests/solidity (#1526) Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2. - [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases) - [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2) --- updated-dependencies: - dependency-name: decode-uri-component dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * tests(integration): block gas limit tests (#1500) * added antehandler test * add integration tests * add back gas call test * added integration tests v2 * linters * Update tests/integration_tests/test_gas.py * Update tests/integration_tests/test_gas.py * update gomod2nix * Update tests/integration_tests/test_gas.py Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com> * chore(ante): deprecate legacy EIP-712 signature verification via AnteHandler (#1521) * fix: rename EIP-712 sig. verification to indicate Legacy status * Add changelog entry * Update changelog, refactor implementation, update comments * Apply suggestions from code review * address comments * changelog * Update CHANGELOG.md Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com> * fix test Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com> * feat(ci): add Golang dependency vulnerability check (#1528) * feat(ci): add Golang dependency vulnerability check * update * check run * c++ * chore(evm): add comment regarding RANDOM opcode (#1520) * fix: add random field to BlockContext using block header hash * add comment Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update release date * update changelog Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Daniel Burckhardt <daniel.m.burckhardt@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mmsqe <mavis@crypto.com> Co-authored-by: Austin Chandra <austinchandra@berkeley.edu> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: 4rgon4ut <59182467+4rgon4ut@users.noreply.github.com> Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: Adi Saravanan <59209660+adisaran64@users.noreply.github.com> Co-authored-by: Tomas Guerra <54514587+GAtom22@users.noreply.github.com> Co-authored-by: Ramiro Carlucho <ramirocarlucho@gmail.com> Co-authored-by: Vladislav Varadinov <vladislav.varadinov@gmail.com> Co-authored-by: Vladislav Varadinov <vlad@evmos.org> Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> Co-authored-by: mmsqe <tqd0800210105@gmail.com> Co-authored-by: Devon Bear <itsdevbear@berachain.com> Co-authored-by: v-homsi <110708931+v-homsi@users.noreply.github.com> Co-authored-by: MalteHerrmann <malteherrmann.mail@web.de>
553 lines
21 KiB
Go
553 lines
21 KiB
Go
package keeper
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
sdkmath "cosmossdk.io/math"
|
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
|
|
ethermint "github.com/evmos/ethermint/types"
|
|
"github.com/evmos/ethermint/x/evm/statedb"
|
|
"github.com/evmos/ethermint/x/evm/types"
|
|
evm "github.com/evmos/ethermint/x/evm/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core"
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
"github.com/ethereum/go-ethereum/params"
|
|
)
|
|
|
|
// GasToRefund calculates the amount of gas the state machine should refund to the sender. It is
|
|
// capped by the refund quotient value.
|
|
// Note: do not pass 0 to refundQuotient
|
|
func GasToRefund(availableRefund, gasConsumed, refundQuotient uint64) uint64 {
|
|
// Apply refund counter
|
|
refund := gasConsumed / refundQuotient
|
|
if refund > availableRefund {
|
|
return availableRefund
|
|
}
|
|
return refund
|
|
}
|
|
|
|
// EVMConfig creates the EVMConfig based on current state
|
|
func (k *Keeper) EVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress, chainID *big.Int) (*types.EVMConfig, error) {
|
|
params := k.GetParams(ctx)
|
|
ethCfg := params.ChainConfig.EthereumConfig(chainID)
|
|
|
|
// get the coinbase address from the block proposer
|
|
coinbase, err := k.GetCoinbaseAddress(ctx, proposerAddress)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to obtain coinbase address")
|
|
}
|
|
|
|
baseFee := k.GetBaseFee(ctx, ethCfg)
|
|
return &types.EVMConfig{
|
|
Params: params,
|
|
ChainConfig: ethCfg,
|
|
CoinBase: coinbase,
|
|
BaseFee: baseFee,
|
|
}, nil
|
|
}
|
|
|
|
// TxConfig loads `TxConfig` from current transient storage
|
|
func (k *Keeper) TxConfig(ctx sdk.Context, txHash common.Hash) statedb.TxConfig {
|
|
return statedb.NewTxConfig(
|
|
common.BytesToHash(ctx.HeaderHash()), // BlockHash
|
|
txHash, // TxHash
|
|
uint(k.GetTxIndexTransient(ctx)), // TxIndex
|
|
uint(k.GetLogSizeTransient(ctx)), // LogIndex
|
|
)
|
|
}
|
|
|
|
// NewEVM generates a go-ethereum VM from the provided Message fields and the chain parameters
|
|
// (ChainConfig and module Params). It additionally sets the validator operator address as the
|
|
// coinbase address to make it available for the COINBASE opcode, even though there is no
|
|
// beneficiary of the coinbase transaction (since we're not mining).
|
|
//
|
|
// NOTE: the RANDOM opcode is currently not supported since it requires
|
|
// RANDAO implementation. See https://github.com/evmos/ethermint/pull/1520#pullrequestreview-1200504697
|
|
// for more information.
|
|
|
|
func (k *Keeper) NewEVM(
|
|
ctx sdk.Context,
|
|
msg core.Message,
|
|
cfg *types.EVMConfig,
|
|
tracer vm.EVMLogger,
|
|
stateDB vm.StateDB,
|
|
) evm.EVM {
|
|
blockCtx := vm.BlockContext{
|
|
CanTransfer: core.CanTransfer,
|
|
Transfer: core.Transfer,
|
|
GetHash: k.GetHashFn(ctx),
|
|
Coinbase: cfg.CoinBase,
|
|
GasLimit: ethermint.BlockGasLimit(ctx),
|
|
BlockNumber: big.NewInt(ctx.BlockHeight()),
|
|
Time: big.NewInt(ctx.BlockHeader().Time.Unix()),
|
|
Difficulty: big.NewInt(0), // unused. Only required in PoW context
|
|
BaseFee: cfg.BaseFee,
|
|
Random: nil, // not supported
|
|
}
|
|
|
|
txCtx := core.NewEVMTxContext(msg)
|
|
if tracer == nil {
|
|
tracer = k.Tracer(ctx, msg, cfg.ChainConfig)
|
|
}
|
|
vmConfig := k.VMConfig(ctx, msg, cfg, tracer)
|
|
return k.evmConstructor(blockCtx, txCtx, stateDB, cfg.ChainConfig, vmConfig, k.customPrecompiles)
|
|
}
|
|
|
|
// VMConfig creates an EVM configuration from the debug setting and the extra EIPs enabled on the
|
|
// module parameters. The config generated uses the default JumpTable from the EVM.
|
|
func (k Keeper) VMConfig(ctx sdk.Context, msg core.Message, cfg *types.EVMConfig, tracer vm.EVMLogger) vm.Config {
|
|
noBaseFee := true
|
|
if types.IsLondon(cfg.ChainConfig, ctx.BlockHeight()) {
|
|
noBaseFee = k.feeMarketKeeper.GetParams(ctx).NoBaseFee
|
|
}
|
|
|
|
var debug bool
|
|
if _, ok := tracer.(types.NoOpTracer); !ok {
|
|
debug = true
|
|
}
|
|
|
|
return vm.Config{
|
|
Debug: debug,
|
|
Tracer: tracer,
|
|
NoBaseFee: noBaseFee,
|
|
ExtraEips: cfg.Params.EIPs(),
|
|
}
|
|
}
|
|
|
|
// GetHashFn implements vm.GetHashFunc for Ethermint. It handles 3 cases:
|
|
// 1. The requested height matches the current height from context (and thus same epoch number)
|
|
// 2. The requested height is from an previous height from the same chain epoch
|
|
// 3. The requested height is from a height greater than the latest one
|
|
func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc {
|
|
return func(height uint64) common.Hash {
|
|
h, err := ethermint.SafeInt64(height)
|
|
if err != nil {
|
|
k.Logger(ctx).Error("failed to cast height to int64", "error", err)
|
|
return common.Hash{}
|
|
}
|
|
|
|
switch {
|
|
case ctx.BlockHeight() == h:
|
|
// Case 1: The requested height matches the one from the context so we can retrieve the header
|
|
// hash directly from the context.
|
|
// Note: The headerHash is only set at begin block, it will be nil in case of a query context
|
|
headerHash := ctx.HeaderHash()
|
|
if len(headerHash) != 0 {
|
|
return common.BytesToHash(headerHash)
|
|
}
|
|
|
|
// only recompute the hash if not set (eg: checkTxState)
|
|
contextBlockHeader := ctx.BlockHeader()
|
|
header, err := tmtypes.HeaderFromProto(&contextBlockHeader)
|
|
if err != nil {
|
|
k.Logger(ctx).Error("failed to cast tendermint header from proto", "error", err)
|
|
return common.Hash{}
|
|
}
|
|
|
|
headerHash = header.Hash()
|
|
return common.BytesToHash(headerHash)
|
|
|
|
case ctx.BlockHeight() > h:
|
|
// Case 2: if the chain is not the current height we need to retrieve the hash from the store for the
|
|
// current chain epoch. This only applies if the current height is greater than the requested height.
|
|
histInfo, found := k.stakingKeeper.GetHistoricalInfo(ctx, h)
|
|
if !found {
|
|
k.Logger(ctx).Debug("historical info not found", "height", h)
|
|
return common.Hash{}
|
|
}
|
|
|
|
header, err := tmtypes.HeaderFromProto(&histInfo.Header)
|
|
if err != nil {
|
|
k.Logger(ctx).Error("failed to cast tendermint header from proto", "error", err)
|
|
return common.Hash{}
|
|
}
|
|
|
|
return common.BytesToHash(header.Hash())
|
|
default:
|
|
// Case 3: heights greater than the current one returns an empty hash.
|
|
return common.Hash{}
|
|
}
|
|
}
|
|
}
|
|
|
|
// ApplyTransaction runs and attempts to perform a state transition with the given transaction (i.e Message), that will
|
|
// only be persisted (committed) to the underlying KVStore if the transaction does not fail.
|
|
//
|
|
// # Gas tracking
|
|
//
|
|
// Ethereum consumes gas according to the EVM opcodes instead of general reads and writes to store. Because of this, the
|
|
// state transition needs to ignore the SDK gas consumption mechanism defined by the GasKVStore and instead consume the
|
|
// amount of gas used by the VM execution. The amount of gas used is tracked by the EVM and returned in the execution
|
|
// result.
|
|
//
|
|
// Prior to the execution, the starting tx gas meter is saved and replaced with an infinite gas meter in a new context
|
|
// in order to ignore the SDK gas consumption config values (read, write, has, delete).
|
|
// After the execution, the gas used from the message execution will be added to the starting gas consumed, taking into
|
|
// consideration the amount of gas returned. Finally, the context is updated with the EVM gas consumed value prior to
|
|
// returning.
|
|
//
|
|
// For relevant discussion see: https://github.com/cosmos/cosmos-sdk/discussions/9072
|
|
func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*types.MsgEthereumTxResponse, error) {
|
|
var (
|
|
bloom *big.Int
|
|
bloomReceipt ethtypes.Bloom
|
|
)
|
|
|
|
cfg, err := k.EVMConfig(ctx, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress), k.eip155ChainID)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to load evm config")
|
|
}
|
|
txConfig := k.TxConfig(ctx, tx.Hash())
|
|
|
|
// get the signer according to the chain rules from the config and block height
|
|
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))
|
|
msg, err := tx.AsMessage(signer, cfg.BaseFee)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to return ethereum transaction as core message")
|
|
}
|
|
|
|
// snapshot to contain the tx processing and post processing in same scope
|
|
var commit func()
|
|
tmpCtx := ctx
|
|
if k.hooks != nil {
|
|
// Create a cache context to revert state when tx hooks fails,
|
|
// the cache context is only committed when both tx and hooks executed successfully.
|
|
// Didn't use `Snapshot` because the context stack has exponential complexity on certain operations,
|
|
// thus restricted to be used only inside `ApplyMessage`.
|
|
tmpCtx, commit = ctx.CacheContext()
|
|
}
|
|
|
|
// pass true to commit the StateDB
|
|
res, err := k.ApplyMessageWithConfig(tmpCtx, msg, nil, true, cfg, txConfig)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to apply ethereum core message")
|
|
}
|
|
|
|
logs := types.LogsToEthereum(res.Logs)
|
|
|
|
// Compute block bloom filter
|
|
if len(logs) > 0 {
|
|
bloom = k.GetBlockBloomTransient(ctx)
|
|
bloom.Or(bloom, big.NewInt(0).SetBytes(ethtypes.LogsBloom(logs)))
|
|
bloomReceipt = ethtypes.BytesToBloom(bloom.Bytes())
|
|
}
|
|
|
|
cumulativeGasUsed := res.GasUsed
|
|
if ctx.BlockGasMeter() != nil {
|
|
limit := ctx.BlockGasMeter().Limit()
|
|
cumulativeGasUsed += ctx.BlockGasMeter().GasConsumed()
|
|
if cumulativeGasUsed > limit {
|
|
cumulativeGasUsed = limit
|
|
}
|
|
}
|
|
|
|
var contractAddr common.Address
|
|
if msg.To() == nil {
|
|
contractAddr = crypto.CreateAddress(msg.From(), msg.Nonce())
|
|
}
|
|
|
|
receipt := ðtypes.Receipt{
|
|
Type: tx.Type(),
|
|
PostState: nil, // TODO: intermediate state root
|
|
CumulativeGasUsed: cumulativeGasUsed,
|
|
Bloom: bloomReceipt,
|
|
Logs: logs,
|
|
TxHash: txConfig.TxHash,
|
|
ContractAddress: contractAddr,
|
|
GasUsed: res.GasUsed,
|
|
BlockHash: txConfig.BlockHash,
|
|
BlockNumber: big.NewInt(ctx.BlockHeight()),
|
|
TransactionIndex: txConfig.TxIndex,
|
|
}
|
|
|
|
if !res.Failed() {
|
|
receipt.Status = ethtypes.ReceiptStatusSuccessful
|
|
// Only call hooks if tx executed successfully.
|
|
if err = k.PostTxProcessing(tmpCtx, msg, receipt); err != nil {
|
|
// If hooks return error, revert the whole tx.
|
|
res.VmError = types.ErrPostTxProcessing.Error()
|
|
k.Logger(ctx).Error("tx post processing failed", "error", err)
|
|
|
|
// If the tx failed in post processing hooks, we should clear the logs
|
|
res.Logs = nil
|
|
} else if commit != nil {
|
|
// PostTxProcessing is successful, commit the tmpCtx
|
|
commit()
|
|
// Since the post processing can alter the log, we need to update the result
|
|
res.Logs = types.NewLogsFromEth(receipt.Logs)
|
|
ctx.EventManager().EmitEvents(tmpCtx.EventManager().Events())
|
|
}
|
|
}
|
|
|
|
// refund gas in order to match the Ethereum gas consumption instead of the default SDK one.
|
|
if err = k.RefundGas(ctx, msg, msg.Gas()-res.GasUsed, cfg.Params.EvmDenom); err != nil {
|
|
return nil, errorsmod.Wrapf(err, "failed to refund gas leftover gas to sender %s", msg.From())
|
|
}
|
|
|
|
if len(receipt.Logs) > 0 {
|
|
// Update transient block bloom filter
|
|
k.SetBlockBloomTransient(ctx, receipt.Bloom.Big())
|
|
k.SetLogSizeTransient(ctx, uint64(txConfig.LogIndex)+uint64(len(receipt.Logs)))
|
|
}
|
|
|
|
k.SetTxIndexTransient(ctx, uint64(txConfig.TxIndex)+1)
|
|
|
|
totalGasUsed, err := k.AddTransientGasUsed(ctx, res.GasUsed)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to add transient gas used")
|
|
}
|
|
|
|
// reset the gas meter for current cosmos transaction
|
|
k.ResetGasMeterAndConsumeGas(ctx, totalGasUsed)
|
|
return res, nil
|
|
}
|
|
|
|
// ApplyMessageWithConfig computes the new state by applying the given message against the existing state.
|
|
// If the message fails, the VM execution error with the reason will be returned to the client
|
|
// and the transaction won't be committed to the store.
|
|
//
|
|
// # Reverted state
|
|
//
|
|
// The snapshot and rollback are supported by the `statedb.StateDB`.
|
|
//
|
|
// # Different Callers
|
|
//
|
|
// It's called in three scenarios:
|
|
// 1. `ApplyTransaction`, in the transaction processing flow.
|
|
// 2. `EthCall/EthEstimateGas` grpc query handler.
|
|
// 3. Called by other native modules directly.
|
|
//
|
|
// # Prechecks and Preprocessing
|
|
//
|
|
// All relevant state transition prechecks for the MsgEthereumTx are performed on the AnteHandler,
|
|
// prior to running the transaction against the state. The prechecks run are the following:
|
|
//
|
|
// 1. the nonce of the message caller is correct
|
|
// 2. caller has enough balance to cover transaction fee(gaslimit * gasprice)
|
|
// 3. the amount of gas required is available in the block
|
|
// 4. the purchased gas is enough to cover intrinsic usage
|
|
// 5. there is no overflow when calculating intrinsic gas
|
|
// 6. caller has enough balance to cover asset transfer for **topmost** call
|
|
//
|
|
// The preprocessing steps performed by the AnteHandler are:
|
|
//
|
|
// 1. set up the initial access list (iff fork > Berlin)
|
|
//
|
|
// # Tracer parameter
|
|
//
|
|
// It should be a `vm.Tracer` object or nil, if pass `nil`, it'll create a default one based on keeper options.
|
|
//
|
|
// # Commit parameter
|
|
//
|
|
// If commit is true, the `StateDB` will be committed, otherwise discarded.
|
|
func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
|
|
msg core.Message,
|
|
tracer vm.EVMLogger,
|
|
commit bool,
|
|
cfg *types.EVMConfig,
|
|
txConfig statedb.TxConfig,
|
|
) (*types.MsgEthereumTxResponse, error) {
|
|
var (
|
|
ret []byte // return bytes from evm execution
|
|
vmErr error // vm errors do not effect consensus and are therefore not assigned to err
|
|
)
|
|
|
|
// return error if contract creation or call are disabled through governance
|
|
if !cfg.Params.EnableCreate && msg.To() == nil {
|
|
return nil, errorsmod.Wrap(types.ErrCreateDisabled, "failed to create new contract")
|
|
} else if !cfg.Params.EnableCall && msg.To() != nil {
|
|
return nil, errorsmod.Wrap(types.ErrCallDisabled, "failed to call contract")
|
|
}
|
|
|
|
stateDB := statedb.New(ctx, k, txConfig)
|
|
evm := k.NewEVM(ctx, msg, cfg, tracer, stateDB)
|
|
|
|
leftoverGas := msg.Gas()
|
|
|
|
// Allow the tracer captures the tx level events, mainly the gas consumption.
|
|
vmCfg := evm.Config()
|
|
if vmCfg.Debug {
|
|
vmCfg.Tracer.CaptureTxStart(leftoverGas)
|
|
defer func() {
|
|
vmCfg.Tracer.CaptureTxEnd(leftoverGas)
|
|
}()
|
|
}
|
|
|
|
sender := vm.AccountRef(msg.From())
|
|
contractCreation := msg.To() == nil
|
|
isLondon := cfg.ChainConfig.IsLondon(evm.Context().BlockNumber)
|
|
|
|
intrinsicGas, err := k.GetEthIntrinsicGas(ctx, msg, cfg.ChainConfig, contractCreation)
|
|
if err != nil {
|
|
// should have already been checked on Ante Handler
|
|
return nil, errorsmod.Wrap(err, "intrinsic gas failed")
|
|
}
|
|
|
|
// Should check again even if it is checked on Ante Handler, because eth_call don't go through Ante Handler.
|
|
if leftoverGas < intrinsicGas {
|
|
// eth_estimateGas will check for this exact error
|
|
return nil, errorsmod.Wrap(core.ErrIntrinsicGas, "apply message")
|
|
}
|
|
leftoverGas -= intrinsicGas
|
|
|
|
// access list preparation is moved from ante handler to here, because it's needed when `ApplyMessage` is called
|
|
// under contexts where ante handlers are not run, for example `eth_call` and `eth_estimateGas`.
|
|
if rules := cfg.ChainConfig.Rules(big.NewInt(ctx.BlockHeight()), cfg.ChainConfig.MergeNetsplitBlock != nil); rules.IsBerlin {
|
|
stateDB.PrepareAccessList(msg.From(), msg.To(), evm.ActivePrecompiles(rules), msg.AccessList())
|
|
}
|
|
|
|
if contractCreation {
|
|
// take over the nonce management from evm:
|
|
// - reset sender's nonce to msg.Nonce() before calling evm.
|
|
// - increase sender's nonce by one no matter the result.
|
|
stateDB.SetNonce(sender.Address(), msg.Nonce())
|
|
ret, _, leftoverGas, vmErr = evm.Create(sender, msg.Data(), leftoverGas, msg.Value())
|
|
stateDB.SetNonce(sender.Address(), msg.Nonce()+1)
|
|
} else {
|
|
ret, leftoverGas, vmErr = evm.Call(sender, *msg.To(), msg.Data(), leftoverGas, msg.Value())
|
|
}
|
|
|
|
refundQuotient := params.RefundQuotient
|
|
|
|
// After EIP-3529: refunds are capped to gasUsed / 5
|
|
if isLondon {
|
|
refundQuotient = params.RefundQuotientEIP3529
|
|
}
|
|
|
|
// calculate gas refund
|
|
if msg.Gas() < leftoverGas {
|
|
return nil, errorsmod.Wrap(types.ErrGasOverflow, "apply message")
|
|
}
|
|
// refund gas
|
|
temporaryGasUsed := msg.Gas() - leftoverGas
|
|
leftoverGas += GasToRefund(stateDB.GetRefund(), temporaryGasUsed, refundQuotient)
|
|
|
|
// EVM execution error needs to be available for the JSON-RPC client
|
|
var vmError string
|
|
if vmErr != nil {
|
|
vmError = vmErr.Error()
|
|
}
|
|
|
|
// The dirty states in `StateDB` is either committed or discarded after return
|
|
if commit {
|
|
if err := stateDB.Commit(); err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to commit stateDB")
|
|
}
|
|
}
|
|
|
|
// calculate a minimum amount of gas to be charged to sender if GasLimit
|
|
// is considerably higher than GasUsed to stay more aligned with Tendermint gas mechanics
|
|
// for more info https://github.com/evmos/ethermint/issues/1085
|
|
gasLimit := sdk.NewDec(int64(msg.Gas()))
|
|
minGasMultiplier := k.GetMinGasMultiplier(ctx)
|
|
minimumGasUsed := gasLimit.Mul(minGasMultiplier)
|
|
|
|
if msg.Gas() < leftoverGas {
|
|
return nil, errorsmod.Wrapf(types.ErrGasOverflow, "message gas limit < leftover gas (%d < %d)", msg.Gas(), leftoverGas)
|
|
}
|
|
|
|
gasUsed := sdk.MaxDec(minimumGasUsed, sdk.NewDec(int64(temporaryGasUsed))).TruncateInt().Uint64()
|
|
// reset leftoverGas, to be used by the tracer
|
|
leftoverGas = msg.Gas() - gasUsed
|
|
|
|
return &types.MsgEthereumTxResponse{
|
|
GasUsed: gasUsed,
|
|
VmError: vmError,
|
|
Ret: ret,
|
|
Logs: types.NewLogsFromEth(stateDB.Logs()),
|
|
Hash: txConfig.TxHash.Hex(),
|
|
}, nil
|
|
}
|
|
|
|
// ApplyMessage calls ApplyMessageWithConfig with default EVMConfig
|
|
func (k *Keeper) ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogger, commit bool) (*types.MsgEthereumTxResponse, error) {
|
|
cfg, err := k.EVMConfig(ctx, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress), k.eip155ChainID)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrap(err, "failed to load evm config")
|
|
}
|
|
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash()))
|
|
return k.ApplyMessageWithConfig(ctx, msg, tracer, commit, cfg, txConfig)
|
|
}
|
|
|
|
// GetEthIntrinsicGas returns the intrinsic gas cost for the transaction
|
|
func (k *Keeper) GetEthIntrinsicGas(ctx sdk.Context, msg core.Message, cfg *params.ChainConfig, isContractCreation bool) (uint64, error) {
|
|
height := big.NewInt(ctx.BlockHeight())
|
|
homestead := cfg.IsHomestead(height)
|
|
istanbul := cfg.IsIstanbul(height)
|
|
|
|
return core.IntrinsicGas(msg.Data(), msg.AccessList(), isContractCreation, homestead, istanbul)
|
|
}
|
|
|
|
// RefundGas transfers the leftover gas to the sender of the message, caped to half of the total gas
|
|
// consumed in the transaction. Additionally, the function sets the total gas consumed to the value
|
|
// returned by the EVM execution, thus ignoring the previous intrinsic gas consumed during in the
|
|
// AnteHandler.
|
|
func (k *Keeper) RefundGas(ctx sdk.Context, msg core.Message, leftoverGas uint64, denom string) error {
|
|
// Return EVM tokens for remaining gas, exchanged at the original rate.
|
|
remaining := new(big.Int).Mul(new(big.Int).SetUint64(leftoverGas), msg.GasPrice())
|
|
|
|
switch remaining.Sign() {
|
|
case -1:
|
|
// negative refund errors
|
|
return errorsmod.Wrapf(types.ErrInvalidRefund, "refunded amount value cannot be negative %d", remaining.Int64())
|
|
case 1:
|
|
// positive amount refund
|
|
refundedCoins := sdk.Coins{sdk.NewCoin(denom, sdkmath.NewIntFromBigInt(remaining))}
|
|
|
|
// refund to sender from the fee collector module account, which is the escrow account in charge of collecting tx fees
|
|
|
|
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, msg.From().Bytes(), refundedCoins)
|
|
if err != nil {
|
|
err = errorsmod.Wrapf(errortypes.ErrInsufficientFunds, "fee collector account failed to refund fees: %s", err.Error())
|
|
return errorsmod.Wrapf(err, "failed to refund %d leftover gas (%s)", leftoverGas, refundedCoins.String())
|
|
}
|
|
default:
|
|
// no refund, consume gas and update the tx gas meter
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ResetGasMeterAndConsumeGas reset first the gas meter consumed value to zero and set it back to the new value
|
|
// 'gasUsed'
|
|
func (k *Keeper) ResetGasMeterAndConsumeGas(ctx sdk.Context, gasUsed uint64) {
|
|
// reset the gas count
|
|
ctx.GasMeter().RefundGas(ctx.GasMeter().GasConsumed(), "reset the gas count")
|
|
ctx.GasMeter().ConsumeGas(gasUsed, "apply evm transaction")
|
|
}
|
|
|
|
// GetProposerAddress returns current block proposer's address when provided proposer address is empty.
|
|
func GetProposerAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) sdk.ConsAddress {
|
|
if len(proposerAddress) == 0 {
|
|
proposerAddress = ctx.BlockHeader().ProposerAddress
|
|
}
|
|
return proposerAddress
|
|
}
|
|
|
|
// GetCoinbaseAddress returns the block proposer's validator operator address.
|
|
func (k Keeper) GetCoinbaseAddress(ctx sdk.Context, proposerAddress sdk.ConsAddress) (common.Address, error) {
|
|
validator, found := k.stakingKeeper.GetValidatorByConsAddr(ctx, GetProposerAddress(ctx, proposerAddress))
|
|
if !found {
|
|
return common.Address{}, errorsmod.Wrapf(
|
|
stakingtypes.ErrNoValidatorFound,
|
|
"failed to retrieve validator from block proposer address %s",
|
|
proposerAddress.String(),
|
|
)
|
|
}
|
|
|
|
coinbase := common.BytesToAddress(validator.GetOperator())
|
|
return coinbase, nil
|
|
}
|