Skip to content

Commit 37dba0a

Browse files
evm: rewrite eth_estimateGas for panic safety and performance (#2424)
* fix(evm): add panic safety to eth_estimateGas. Fix usage of incorrect SDB context in successive estimation calls. * fix(evm): use geth efficiency improvements and improved BinSearch with lo bias * fix(evm-e2e): newer assertion is more lenient * fix: add suggestion from Cursor bot * fix: bug with ineffectual assignment * ci: add new gen-changelog command to automate its maintenance more * more pr feedback --------- Co-authored-by: Oleg Nikonychev <[email protected]>
1 parent e1401f6 commit 37dba0a

File tree

12 files changed

+291
-193
lines changed

12 files changed

+291
-193
lines changed

.github/workflows/changelog-check.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

CHANGELOG-UNRELEASED.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Changelog Chunk
2+
* fix: bug with ineffectual assignment
3+
* fix: add suggestion from Cursor bot
4+
* fix(evm-e2e): newer assertion is more lenient
5+
* fix(evm): use geth efficiency improvements and improved BinSearch with lo bias
6+
* fix(evm): add panic safety to eth_estimateGas. Fix usage of incorrect SDB context in successive estimation calls.
7+
* docs(bank): README fixes
8+
* docs(bank): improve documentation and add section on Nibiru changes in [#2421](https://github.com/NibiruChain/nibiru/pull/2421) - ([172c008](https://github.com/NibiruChain/nibiru/commit/172c008068f8436081ee571f2fb7c01f607297f3)) by @Unique-Divine
9+
* feat: add recursive check for nested authz exec messages and enforce … in [#2420](https://github.com/NibiruChain/nibiru/pull/2420) - ([3cdc810](https://github.com/NibiruChain/nibiru/commit/3cdc8107069c149bbfc538a6e3b7b0dd17b9cf2e)) by @expertdicer
10+
* ci: simplify Go caching in CI to prevent file collisions in [#2419](https://github.com/NibiruChain/nibiru/pull/2419) - ([b1d1c22](https://github.com/NibiruChain/nibiru/commit/b1d1c22319eed8af11152b460fca6d9f54ad067a)) by @Unique-Divine
11+
* fix(evmstate/test): stabilize trace tx tests with deterministic ERC20 transfer recipient in [#2418](https://github.com/NibiruChain/nibiru/pull/2418) - ([b47e3bd](https://github.com/NibiruChain/nibiru/commit/b47e3bd8ef89e01134fe3e3e0d60bea3e34c9561)) by @Unique-Divine
12+
* feat: custom ante NewDeductFeeDecorator allowing 0 fee for zero gas actors in [#2415](https://github.com/NibiruChain/nibiru/pull/2415) - ([09e58ab](https://github.com/NibiruChain/nibiru/commit/09e58abd5a636b18303434aa1d5d0a526a7e65cb)) by @onikonychev
13+
* ci: add back coverage reporting using gocovmerge; bring README more up to date in [#2416](https://github.com/NibiruChain/nibiru/pull/2416) - ([63257f0](https://github.com/NibiruChain/nibiru/commit/63257f0c749543478e8ce7be4aebec899d906f2e)) by @Unique-Divine
14+
* refactor(upgrades): simplify upgrade hanlder code to use less abstractions and combine micro-packages in [#2413](https://github.com/NibiruChain/nibiru/pull/2413) - ([74cb33e](https://github.com/NibiruChain/nibiru/commit/74cb33eee6854cf55be26b26f5a85e6542625071)) by @Unique-Divine
15+
* fix(evm-rpc): remove unsafe debug API methods. in [#2412](https://github.com/NibiruChain/nibiru/pull/2412) - ([e2a1ee8](https://github.com/NibiruChain/nibiru/commit/e2a1ee84e651dff9202ba25b0b7b54b64036697a)) by @Unique-Divine
16+
* chore: v2.8.0 upgrade handler in [#2411](https://github.com/NibiruChain/nibiru/pull/2411) - ([9000cf3](https://github.com/NibiruChain/nibiru/commit/9000cf3a16797670769643e4feae4f9d07f38518)) by @onikonychev
17+
* fix(evm-trace-block): handle native tracer errors JSON-RPC errors for "debug_traceBlockByNumber". Fixes [Nibiru#2400 bug](https://github.com/NibiruChain/nibiru/issues/2400) in [#2409](https://github.com/NibiruChain/nibiru/pull/2409) - ([e44cbc5](https://github.com/NibiruChain/nibiru/commit/e44cbc5c4e2f8be3a6756baf6aa5866ef642e63a)) by @Unique-Divine
18+
* docs: merge PR from @yinwenyu6 . Comments only
19+
* feat(evm/grpc-query): Update the "/eth.evm.v1.Query/Balance" query to work with "0x" Ethereum hex and "nibi"-prefixed Bech32 address formats in [#2410](https://github.com/NibiruChain/nibiru/pull/2410) - ([1bfc24d](https://github.com/NibiruChain/nibiru/commit/1bfc24d35401fccf120d1e82e1d184b57ca989d4)) by @Unique-Divine
20+
* feat(proto): REST API doc generation for bank, auth, and txs in [#2394](https://github.com/NibiruChain/nibiru/pull/2394) - ([5dbb398](https://github.com/NibiruChain/nibiru/commit/5dbb3984e86a87c4d91c984c4fcd96d36cde25f5)) by @expertdicer
21+
* feat(sudo-ante): implement zero gas actors for invoking whitelisted contract in [#2407](https://github.com/NibiruChain/nibiru/pull/2407) - ([6316bcd](https://github.com/NibiruChain/nibiru/commit/6316bcd66593dcf2dd370e7a1f0daf5d4fef3676)) by @Unique-Divine
22+
* chore: added monad logo svg in [#2406](https://github.com/NibiruChain/nibiru/pull/2406) - ([90b951c](https://github.com/NibiruChain/nibiru/commit/90b951c43f7ad0c793d6b84bd6d087fc767bb190)) by @onikonychev
23+
* chore: additional coin logos which could be used externally in [#2405](https://github.com/NibiruChain/nibiru/pull/2405) - ([6bb649b](https://github.com/NibiruChain/nibiru/commit/6bb649b7c3d3f73a985914e55772f04bbbbc07c6)) by @onikonychev
24+
* feat(epic-evm): rearchitecture for StateDB safety, fix for consensus failures, performance improvements, consistent simulations, and nonce resolution for pending txs in the mempool in [#2397](https://github.com/NibiruChain/nibiru/pull/2397) - ([a252c9b](https://github.com/NibiruChain/nibiru/commit/a252c9bcdf37faa99e60fc59088e2867bd6c461f)) by @Unique-Divine
25+
* chore: erc20 token registry new token: ynETHx in [#2395](https://github.com/NibiruChain/nibiru/pull/2395) - ([9219a94](https://github.com/NibiruChain/nibiru/commit/9219a94448940c1835106cb3d82dc61f50948234)) by @onikonychev
26+
* feat(proto): impl script for gRPC Gateway REST doc generation in [#2391](https://github.com/NibiruChain/nibiru/pull/2391) - ([eb4b67e](https://github.com/NibiruChain/nibiru/commit/eb4b67ea858f889fb996cf2248c225d03a090b17)) by @Unique-Divine
27+
* chore: erc20 token registry new tokens: cbBTC, uBTC in [#2388](https://github.com/NibiruChain/nibiru/pull/2388) - ([c1229d0](https://github.com/NibiruChain/nibiru/commit/c1229d0547ef743c156295218896acdeaa89c008)) by @onikonychev
28+
* feat(evm): 63/64 gas clamp for ERC20 calls. Improved VM error surfacing. Add composite Chainlink-like oracle in [#2385](https://github.com/NibiruChain/nibiru/pull/2385) - ([2f7dbb5](https://github.com/NibiruChain/nibiru/commit/2f7dbb5060e35dab4128a203b63cae3ed1821105)) by @Unique-Divine
29+
* feat(.github/pr-title-lint): Enable "/", capital letters, and "evm" prefix in pull request titles in [#2387](https://github.com/NibiruChain/nibiru/pull/2387) - ([4d1e13d](https://github.com/NibiruChain/nibiru/commit/4d1e13d2fbae61b1a7f3a6dd18515872c125f8df)) by @Unique-Divine
30+
* feat(ai): start .cursorignore and Gemini code reviews in [#2386](https://github.com/NibiruChain/nibiru/pull/2386) - ([412abe7](https://github.com/NibiruChain/nibiru/commit/412abe7ceb0acf6e68211bf494106d2d8b498aab)) by @Unique-Divine
31+
32+
<!-- custom git-cliff template -->

cliff.toml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[remote.github]
5+
owner = "NibiruChain"
6+
repo = "nibiru"
7+
# token = ""
8+
9+
[changelog]
10+
# A Tera template to be rendered for each release in the changelog.
11+
# See https://keats.github.io/tera/docs/#introduction
12+
body = """
13+
## Changelog Chunk {%- if version %}- {{ version }} {%- endif -%}
14+
15+
{%- if version %} in {{ version | trim_start_matches(pat="v") }}{%- endif -%}
16+
{% for commit in commits %}
17+
{% if commit.remote.pr_title -%}
18+
{%- set commit_message = commit.remote.pr_title -%}
19+
{%- else -%}
20+
{%- set commit_message = commit.message -%}
21+
{%- endif -%}
22+
* {{ commit_message | split(pat="\n") | first | trim }}\
23+
24+
{% if commit.remote.pr_number %} in \
25+
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
26+
- ([{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }})) \
27+
{% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
28+
{%- endif %}
29+
{%- endfor -%}
30+
31+
{% if version %}
32+
{% if previous.version %}
33+
**Full Changelog**: {{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }}
34+
{% endif %}
35+
{% else -%}
36+
{% raw %}\n{% endraw %}
37+
{% endif %}
38+
39+
{%- macro remote_url() -%}
40+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
41+
{%- endmacro -%}
42+
"""
43+
# Remove leading and trailing whitespaces from the changelog's body.
44+
trim = true
45+
# A Tera template to be rendered as the changelog's footer.
46+
# See https://keats.github.io/tera/docs/#introduction
47+
footer = """
48+
<!-- custom git-cliff template -->
49+
"""
50+
# An array of regex based postprocessors to modify the changelog.
51+
# Replace the placeholder `<REPO>` with a URL.
52+
postprocessors = []
53+
54+
[git]
55+
# Parse commits according to the conventional commits specification.
56+
# See https://www.conventionalcommits.org
57+
conventional_commits = false
58+
# Exclude commits that do not match the conventional commits specification.
59+
filter_unconventional = true
60+
# Split commits on newlines, treating each line as an individual commit.
61+
split_commits = false
62+
# An array of regex based parsers to modify commit messages prior to further processing.
63+
commit_preprocessors = [{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" }]
64+
# Exclude commits that are not matched by any commit parser.
65+
filter_commits = false
66+
# Order releases topologically instead of chronologically.
67+
topo_order = false
68+
# Order of commits in each group/release within the changelog.
69+
# Allowed values: newest, oldest
70+
sort_commits = "newest"
71+
# tag_pattern: Chooses which tags create their own sections.
72+
tag_pattern = '^v\\d+\\.\\d+\\.\\d+$' # only vX.Y.Z count as releases

evm-e2e/test/eth_queries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("eth queries", () => {
2828
}
2929
const estimatedGas = await provider.estimateGas(tx)
3030
expect(estimatedGas).toBeGreaterThan(BigInt(0))
31-
expect(estimatedGas).toEqual(INTRINSIC_TX_GAS)
31+
expect(estimatedGas - INTRINSIC_TX_GAS).toBeLessThan(INTRINSIC_TX_GAS / BigInt(20))
3232
})
3333

3434
it("eth_feeHistory", async () => {

justfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ gen-embeds:
4646
go run "gen-abi/main.go"
4747
log_success "Saved ABI JSON files to $embeds_dir/abi for npm publishing"
4848

49+
# Generates CHANGELOG-UNRELEASED.md based on commits and pull requests.
50+
gen-changelog:
51+
#!/usr/bin/env bash
52+
source contrib/bashlib.sh
53+
which_ok cargo
54+
if ! which_ok git-cliff; then
55+
echo "Installing git-cliff with cargo"
56+
cargo install git-cliff
57+
fi
58+
59+
which_ok git-cliff
60+
61+
LAST_VER="v2.7.0"
62+
start_branch="$(git branch --show-current)"
63+
git checkout main
64+
git-cliff "$LAST_VER.." -o CHANGELOG-UNRELEASED.md
65+
git checkout "$start_branch"
66+
log_success "Created CHANGELOG-UNRELEASED.md with changes since $LAST_VER"
67+
git add CHANGELOG-UNRELEASED.md
68+
4969
# Generate the Nibiru Token Registry files
5070
gen-token-registry:
5171
go run token-registry/main/main.go

x/evm/const.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ const (
3636
Erc20GasLimitExecute uint64 = 200_000
3737
)
3838

39+
type contextKey string
40+
41+
const (
42+
CtxKeyEvmSimulation contextKey = "evm_simulation"
43+
CtxKeyGasEstimateZeroTolerance contextKey = "gas_estimate_zero_tolerance"
44+
)
45+
3946
// BASE_FEE_MICRONIBI is the global base fee value for the network. It has a
4047
// constant value of 1 unibi (micronibi) == 10^12 wei.
4148
var (
@@ -123,15 +130,6 @@ const (
123130
updateParamsName = "evm/MsgUpdateParams"
124131
)
125132

126-
type CallType int
127-
128-
const (
129-
// CallTypeRPC call type is used on requests to eth_estimateGas rpc API endpoint
130-
CallTypeRPC CallType = iota + 1
131-
// CallTypeSmart call type is used in case of smart contract methods calls
132-
CallTypeSmart
133-
)
134-
135133
var (
136134
EVM_MODULE_ADDRESS gethcommon.Address
137135
EVM_MODULE_ADDRESS_NIBI sdk.AccAddress

x/evm/evm.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ package evm
33

44
import (
55
"fmt"
6-
"strings"
76

87
"github.com/cometbft/cometbft/crypto/tmhash"
98
sdk "github.com/cosmos/cosmos-sdk/types"
109
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
1110
gethcommon "github.com/ethereum/go-ethereum/common"
12-
"github.com/ethereum/go-ethereum/core/vm"
1311

1412
"github.com/NibiruChain/nibiru/v2/eth"
1513
)
@@ -114,38 +112,6 @@ func ValidateFunTokenBankMetadata(
114112
return out, nil
115113
}
116114

117-
// HandleOutOfGasPanic captures an sdk.ErrorOutOfGas panic and folds it into
118-
// *errp, an error pointer.
119-
// - If *errp is nil: sets *errp = vm.ErrOutOfGas
120-
// - If *errp is non-nil: preserves it (do not overwrite)
121-
// - Always applies `format` wrapping if *errp is non-nil after recovery
122-
// - Re-panics for any non-OutOfGas panic
123-
func HandleOutOfGasPanic(errp *error, format string) func() {
124-
return func() {
125-
if perr := recover(); perr != nil {
126-
_, isOutOfGasPanic := perr.(sdk.ErrorOutOfGas)
127-
switch {
128-
case isOutOfGasPanic:
129-
if errp != nil && *errp == nil {
130-
*errp = vm.ErrOutOfGas
131-
}
132-
// else: preserve existing detailed error
133-
case strings.Contains(fmt.Sprint(perr), vm.ErrOutOfGas.Error()):
134-
if errp == nil {
135-
errp = new(error)
136-
}
137-
*errp = fmt.Errorf("%s: %w", perr, vm.ErrOutOfGas)
138-
default:
139-
// Non-OOG panics are not handled here
140-
panic(perr)
141-
}
142-
}
143-
if errp != nil && *errp != nil && format != "" {
144-
*errp = fmt.Errorf("%s: %w", format, *errp)
145-
}
146-
}
147-
}
148-
149115
// Gracefully handles "out of gas"
150116
func SafeConsumeGas(ctx sdk.Context, amount uint64, descriptor string) (err error) {
151117
defer func() {

0 commit comments

Comments
 (0)