Skip to content
Merged
Show file tree
Hide file tree
Changes from 102 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
a620a92
refactor: use slices for precompile config test tables
JonathanOppenheimer Mar 19, 2026
f9588d3
build: add precompile interface and build
JonathanOppenheimer Jan 16, 2026
fcf11e7
feat: add acp224 precompile
JonathanOppenheimer Jan 16, 2026
c103b0f
fix: collisions and non zero
JonathanOppenheimer Jan 16, 2026
bc3cf91
refactor: use new spec
JonathanOppenheimer Mar 4, 2026
0b0f4ba
chore: new test error
JonathanOppenheimer Mar 4, 2026
7f1e2db
chore: unexport errors
JonathanOppenheimer Mar 4, 2026
ba6971d
chore: lint
JonathanOppenheimer Mar 4, 2026
ba9166f
chore: copilot review comments
JonathanOppenheimer Mar 4, 2026
fe02d3d
chore: lint
JonathanOppenheimer Mar 4, 2026
ab3cb77
chore: further hardcode address
JonathanOppenheimer Mar 4, 2026
9519ce0
chore: more address
JonathanOppenheimer Mar 4, 2026
b4138c6
chore: build bazel
JonathanOppenheimer Mar 17, 2026
786ade2
test: add tests
JonathanOppenheimer Mar 18, 2026
320adb2
chore: bazel
JonathanOppenheimer Mar 18, 2026
680e6f2
fix: remove invalid validation check
JonathanOppenheimer Mar 18, 2026
add6e93
Update graft/subnet-evm/commontype/fee_config.go
JonathanOppenheimer Mar 18, 2026
a0138f6
refactor: Cey feedback
JonathanOppenheimer Mar 18, 2026
3d440a2
chore: bazel
JonathanOppenheimer Mar 18, 2026
1fae150
chore: lint
JonathanOppenheimer Mar 18, 2026
317ca7f
refactor: tests + copilot feedback
JonathanOppenheimer Mar 18, 2026
446203c
fix: nil
JonathanOppenheimer Mar 18, 2026
24a7788
chore: claude nits
JonathanOppenheimer Mar 18, 2026
734067a
fix: nil fee config
JonathanOppenheimer Mar 18, 2026
a56e576
chore: revert
JonathanOppenheimer Mar 18, 2026
cfac83d
docs: godoc
JonathanOppenheimer Mar 18, 2026
1e0b887
chore: organize contract.go
JonathanOppenheimer Mar 18, 2026
4721e0d
test: use table
JonathanOppenheimer Mar 18, 2026
9eaaf02
chore: remove duplication verification
JonathanOppenheimer Mar 18, 2026
83763bc
chore: Cey review
JonathanOppenheimer Mar 19, 2026
316f2e8
fix: tests
JonathanOppenheimer Mar 19, 2026
c6d91d2
test: don't use init()
JonathanOppenheimer Mar 19, 2026
a27af0f
Revert "refactor: use slices for precompile config test tables"
JonathanOppenheimer Mar 20, 2026
b7c27a5
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 20, 2026
4e08c51
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 23, 2026
49691d4
chore: Cey review
JonathanOppenheimer Mar 25, 2026
d469314
Update graft/subnet-evm/precompile/contracts/acp224feemanager/config.go
JonathanOppenheimer Mar 25, 2026
de42e5d
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 25, 2026
bf26095
refactor: fall back to default config
JonathanOppenheimer Mar 25, 2026
14de17d
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 25, 2026
1ad2df6
chore: lint
JonathanOppenheimer Mar 25, 2026
ecad503
chore: lint
JonathanOppenheimer Mar 25, 2026
dc3a8e1
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 30, 2026
816351e
docs: add uint comment
JonathanOppenheimer Mar 30, 2026
79cd64e
docs: document per uint
JonathanOppenheimer Mar 31, 2026
23c83fa
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 31, 2026
4a0d14f
Update graft/subnet-evm/commontype/acp224_fee_config.go
JonathanOppenheimer Mar 31, 2026
095aa9b
Update graft/subnet-evm/commontype/acp224_fee_config.go
JonathanOppenheimer Mar 31, 2026
fb88e4d
Update graft/subnet-evm/commontype/acp224_fee_config.go
JonathanOppenheimer Mar 31, 2026
bf97714
chore: Austin review
JonathanOppenheimer Mar 31, 2026
da32c31
chore: bazel
JonathanOppenheimer Mar 31, 2026
5293c45
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Mar 31, 2026
13bd5a4
chore: lint
JonathanOppenheimer Mar 31, 2026
01cd7ce
chore: revert one Austin suggestion
JonathanOppenheimer Mar 31, 2026
a7d2595
chore: Austin comments
JonathanOppenheimer Apr 1, 2026
428e5a3
fix: nolint
JonathanOppenheimer Apr 1, 2026
b6c0ada
Update graft/subnet-evm/precompile/contracts/acp224feemanager/module.go
JonathanOppenheimer Apr 2, 2026
99067b2
chore: Arran feedback
JonathanOppenheimer Apr 2, 2026
eda0e76
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 2, 2026
4f3b020
fix: use uint64 directly
JonathanOppenheimer Apr 9, 2026
c2d66e0
chore: remove abi bridge code
JonathanOppenheimer Apr 9, 2026
3eb9e0c
chore: un-inline error
JonathanOppenheimer Apr 9, 2026
a4e1ab9
docs: precompile comments
JonathanOppenheimer Apr 9, 2026
42faaff
Update graft/subnet-evm/precompile/contracts/acp224feemanager/contrac…
JonathanOppenheimer Apr 9, 2026
c323071
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 9, 2026
c135ec5
Merge branch 'JonathanOppenheimer/acp224-add-precompile' of github.co…
JonathanOppenheimer Apr 9, 2026
2ac9012
Update graft/subnet-evm/commontype/acp224_fee_config_test.go
JonathanOppenheimer Apr 9, 2026
2e3d644
Merge branch 'JonathanOppenheimer/acp224-add-precompile' of github.co…
JonathanOppenheimer Apr 9, 2026
d089ed2
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 9, 2026
d465d46
Update graft/subnet-evm/commontype/acp224_fee_config_test.go
JonathanOppenheimer Apr 10, 2026
2a9bd38
Update graft/subnet-evm/commontype/acp224_fee_config_test.go
JonathanOppenheimer Apr 10, 2026
d0dbc94
Update graft/subnet-evm/commontype/acp224_fee_config_test.go
JonathanOppenheimer Apr 10, 2026
e30a9ed
Update graft/subnet-evm/precompile/contracts/acp224feemanager/config.go
JonathanOppenheimer Apr 10, 2026
6fd3b7f
chore: Arran review
JonathanOppenheimer Apr 10, 2026
2b7770a
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 10, 2026
4142b2f
chore: fix auto-apply
JonathanOppenheimer Apr 10, 2026
78d2129
fix: ordering + lint
JonathanOppenheimer Apr 10, 2026
09c8d2b
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 10, 2026
abbdb71
style: take 2
JonathanOppenheimer Apr 10, 2026
b074422
chore: Cey review
JonathanOppenheimer Apr 13, 2026
9d11237
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 13, 2026
ccd5efb
test: convert fuzz to table test
JonathanOppenheimer Apr 13, 2026
fd16177
chore: bazel
JonathanOppenheimer Apr 13, 2026
886df70
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 13, 2026
906252a
chore: lint
JonathanOppenheimer Apr 13, 2026
5e99002
test: properly fuzz graft targets
JonathanOppenheimer Apr 14, 2026
6d21d50
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 14, 2026
1f262ee
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 15, 2026
b990bb5
test: add fuzz corpora
JonathanOppenheimer Apr 15, 2026
6e293fe
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
ceyonur Apr 17, 2026
570a4d0
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer Apr 27, 2026
30cf7f9
chore: bazel metadata
JonathanOppenheimer Apr 27, 2026
b32f61d
Update graft/subnet-evm/commontype/acp224_fee_config.go
JonathanOppenheimer May 1, 2026
77b0c6f
Update graft/subnet-evm/precompile/contracts/acp224feemanager/config.go
JonathanOppenheimer May 1, 2026
7f927ef
Apply suggestions from code review
JonathanOppenheimer May 1, 2026
e0c6473
fix: suggestion
JonathanOppenheimer May 1, 2026
2f052cb
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer May 1, 2026
f2bdf43
chore: Austin feedback
JonathanOppenheimer May 1, 2026
dd1ad0f
chore: lint
JonathanOppenheimer May 5, 2026
5a8a0e4
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer May 5, 2026
414fd7a
style: call gas price manager
JonathanOppenheimer May 5, 2026
e07e7d1
style: reorder contract.go file
JonathanOppenheimer May 5, 2026
497500a
chore: austin comments
JonathanOppenheimer May 6, 2026
d5156f4
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer May 6, 2026
aa8c530
Merge branch 'master' into JonathanOppenheimer/acp224-add-precompile
JonathanOppenheimer May 6, 2026
c2911ab
chore: revert go mod changes
JonathanOppenheimer May 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME=
go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
13 changes: 11 additions & 2 deletions graft/subnet-evm/commontype/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
name = "commontype",
srcs = [
"fee_config.go",
"gas_price_config.go",
"test_fee_config.go",
],
importpath = "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype",
Expand All @@ -21,7 +22,15 @@ go_library(

graft_go_test(
name = "commontype_test",
srcs = ["fee_config_test.go"],
srcs = [
"fee_config_test.go",
"gas_price_config_test.go",
],
data = glob(["testdata/**"]),
embed = [":commontype"],
deps = ["@com_github_stretchr_testify//require"],
deps = [
"//utils",
"@com_github_ava_labs_libevm//common",
"@com_github_stretchr_testify//require",
],
)
112 changes: 112 additions & 0 deletions graft/subnet-evm/commontype/gas_price_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (C) 2019, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package commontype

import (
"encoding/binary"
"errors"

"github.com/ava-labs/libevm/common"
)

const MinTargetGas uint64 = 1_000_000

// DefaultGasPriceConfig returns a default gas price config for the dynamic
// gas limit mechanism.
//
// The default values are:
// - TargetGas: 1_000_000
// - MinGasPrice: 1
// - TimeToDouble: 60
func DefaultGasPriceConfig() GasPriceConfig {
return GasPriceConfig{
TargetGas: 1_000_000,
MinGasPrice: 1,
TimeToDouble: 60,
}
}
Comment thread
JonathanOppenheimer marked this conversation as resolved.

var (
ErrMinGasPriceTooLow = errors.New("minGasPrice must be greater than 0")

errTargetGasMustBeZero = errors.New("targetGas must be 0 when validatorTargetGas is true")
errTargetGasBelowMin = errors.New("targetGas must be at least MinTargetGas")
errTimeToDoubleTooLow = errors.New("timeToDouble must be greater than 0")
errTimeToDoubleMustBeZero = errors.New("timeToDouble must be 0 when staticPricing is true")
)

// GasPriceConfig specifies the parameters for the dynamic gas limit and
// gas price mechanism.
// See [GasPriceConfig.Verify] for validation constraints between fields.
type GasPriceConfig struct {
ValidatorTargetGas bool `json:"validatorTargetGas"` // when true, validators control targetGas via node preferences
TargetGas uint64 `json:"targetGas"` // target gas consumption per second
StaticPricing bool `json:"staticPricing"` // when true, gas price is always minGasPrice
MinGasPrice uint64 `json:"minGasPrice"` // minimum gas price in wei
TimeToDouble uint64 `json:"timeToDouble"` // seconds for gas price to double at max capacity
}

// Verify returns an error if the config violates any field constraints.
func (a *GasPriceConfig) Verify() error {
switch {
case a.MinGasPrice == 0:
return ErrMinGasPriceTooLow
case a.ValidatorTargetGas && a.TargetGas != 0:
return errTargetGasMustBeZero
case !a.ValidatorTargetGas && a.TargetGas < MinTargetGas:
return errTargetGasBelowMin
case a.StaticPricing && a.TimeToDouble != 0:
return errTimeToDoubleMustBeZero
case !a.StaticPricing && a.TimeToDouble == 0:
return errTimeToDoubleTooLow
default:
return nil
}
}

// Pack encodes the gas price config into a single common.Hash (32 bytes).
//
// Layout (26 bytes used, 6 bytes padding):
//
// h[0] ValidatorTargetGas (bool)
// h[1:9] TargetGas (uint64)
// h[9] StaticPricing (bool)
// h[10:18] MinGasPrice (uint64)
// h[18:26] TimeToDouble (uint64)
func (a *GasPriceConfig) Pack() common.Hash {
var h common.Hash
put := binary.BigEndian.PutUint64

if a.ValidatorTargetGas {
h[0] = 1
}
put(h[1:], a.TargetGas)
if a.StaticPricing {
h[9] = 1
}
put(h[10:], a.MinGasPrice)
put(h[18:], a.TimeToDouble)
return h
}

// UnpackFrom decodes a packed common.Hash into the gas price config fields.
// See [GasPriceConfig.Pack] for the byte layout.
func (a *GasPriceConfig) UnpackFrom(h common.Hash) {
u64 := binary.BigEndian.Uint64

a.ValidatorTargetGas = h[0] != 0
a.TargetGas = u64(h[1:])
a.StaticPricing = h[9] != 0
a.MinGasPrice = u64(h[10:])
a.TimeToDouble = u64(h[18:])
}

// Equal returns true if both configs are nil or have identical field values.
func (a *GasPriceConfig) Equal(other *GasPriceConfig) bool {
if a == nil || other == nil {
return a == other
}

return *a == *other
}
220 changes: 220 additions & 0 deletions graft/subnet-evm/commontype/gas_price_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Copyright (C) 2019, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package commontype

import (
"math"
"testing"

"github.com/ava-labs/libevm/common"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/utils"
)

func TestGasPriceConfigVerify(t *testing.T) {
tests := []struct {
name string
config GasPriceConfig
want error
}{
{
name: "valid config",
config: DefaultGasPriceConfig(),
},
{
name: "valid with validatorTargetGas",
config: GasPriceConfig{
ValidatorTargetGas: true,
MinGasPrice: 1,
TimeToDouble: 60,
},
},
{
name: "valid with staticPricing",
config: GasPriceConfig{
TargetGas: MinTargetGas,
StaticPricing: true,
MinGasPrice: 1,
},
},
{
name: "valid with both validatorTargetGas and staticPricing",
config: GasPriceConfig{
ValidatorTargetGas: true,
StaticPricing: true,
MinGasPrice: 1,
},
},
{
name: "minGasPrice zero",
config: GasPriceConfig{
TargetGas: MinTargetGas,
TimeToDouble: 60,
},
want: ErrMinGasPriceTooLow,
},
{
name: "targetGas must be zero when validatorTargetGas is true",
config: GasPriceConfig{
ValidatorTargetGas: true,
TargetGas: MinTargetGas,
MinGasPrice: 1,
TimeToDouble: 60,
},
want: errTargetGasMustBeZero,
},
{
name: "targetGas below minimum",
config: GasPriceConfig{
TargetGas: MinTargetGas - 1,
MinGasPrice: 1,
TimeToDouble: 60,
},
want: errTargetGasBelowMin,
},
{
name: "targetGas at minimum boundary",
config: GasPriceConfig{
TargetGas: MinTargetGas,
MinGasPrice: 1,
TimeToDouble: 1,
},
},
{
name: "timeToDouble must be zero when staticPricing is true",
config: GasPriceConfig{
TargetGas: MinTargetGas,
StaticPricing: true,
MinGasPrice: 1,
TimeToDouble: 60,
},
want: errTimeToDoubleMustBeZero,
},
{
name: "timeToDouble must be positive when staticPricing is false",
config: GasPriceConfig{
TargetGas: MinTargetGas,
MinGasPrice: 1,
},
want: errTimeToDoubleTooLow,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.config.Verify()
require.ErrorIs(t, err, tt.want, "Verify")
})
}
}

// TestGasPriceConfigPackFormat asserts exact packed bytes for known configs.
// This catches backward-incompatible format changes that round-trip tests miss.
func TestGasPriceConfigPackFormat(t *testing.T) {
tests := []struct {
name string
config GasPriceConfig
want common.Hash
}{
{
name: "default config",
config: DefaultGasPriceConfig(),
want: common.HexToHash("0x0000000000000f4240000000000000000001000000000000003c000000000000"),
},
{
name: "all flags true and max uint64",
config: GasPriceConfig{
ValidatorTargetGas: true,
TargetGas: math.MaxUint64,
StaticPricing: true,
MinGasPrice: math.MaxUint64,
TimeToDouble: math.MaxUint64,
},
want: common.HexToHash("0x01ffffffffffffffff01ffffffffffffffffffffffffffffffff000000000000"),
},
{
name: "validatorTargetGas mode",
config: GasPriceConfig{
ValidatorTargetGas: true,
MinGasPrice: 1,
TimeToDouble: 60,
},
want: common.HexToHash("0x010000000000000000000000000000000001000000000000003c000000000000"),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, tt.config.Pack(), "Pack")
})
}
}

func FuzzGasPriceConfigPacking(f *testing.F) {
f.Add(false, false, uint64(0), uint64(0), uint64(0))
f.Add(true, true, uint64(math.MaxUint64), uint64(math.MaxUint64), uint64(math.MaxUint64))
f.Add(false, false, MinTargetGas, uint64(1), uint64(60))
f.Add(true, false, uint64(0), uint64(1), uint64(60))
f.Add(false, true, MinTargetGas, uint64(1), uint64(0))
f.Add(true, true, uint64(0), uint64(1), uint64(0))

f.Fuzz(func(t *testing.T, validator, static bool, target, minGas, double uint64) {
in := &GasPriceConfig{validator, target, static, minGas, double}
got := new(GasPriceConfig)
got.UnpackFrom(in.Pack())
Comment thread
JonathanOppenheimer marked this conversation as resolved.
require.Equalf(t, *in, *got, "%T.UnpackFrom(%[1]T.Pack()) round trip", in)
require.Truef(t, got.Equal(in), "%T.Equal([packed original])", got)
})
}

func TestGasPriceConfigEqual(t *testing.T) {
tests := []struct {
name string
a *GasPriceConfig
b *GasPriceConfig
want bool
}{
{
name: "both equal",
a: utils.PointerTo(DefaultGasPriceConfig()),
b: utils.PointerTo(DefaultGasPriceConfig()),
want: true,
},
{
name: "different targetGas",
a: utils.PointerTo(DefaultGasPriceConfig()),
b: func() *GasPriceConfig {
c := DefaultGasPriceConfig()
c.TargetGas++
return &c
}(),
want: false,
},
{
name: "other nil",
a: utils.PointerTo(DefaultGasPriceConfig()),
b: nil,
want: false,
},
{
name: "receiver nil",
a: nil,
b: utils.PointerTo(DefaultGasPriceConfig()),
want: false,
},
{
name: "both nil",
a: nil,
b: nil,
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equalf(t, tt.want, tt.a.Equal(tt.b), "%T(%+v).Equal(%+v)", tt.a, tt.a, tt.b)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go test fuzz v1
bool(true)
bool(false)
uint64(6148914691236517205)
uint64(12297829382473034410)
uint64(6148914691236517205)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go test fuzz v1
bool(true)
bool(true)
uint64(9223372036854775808)
uint64(9223372036854775807)
uint64(4294967296)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go test fuzz v1
bool(true)
bool(false)
uint64(1)
uint64(1)
uint64(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go test fuzz v1
bool(false)
bool(false)
uint64(1000002)
uint64(1)
uint64(60)
Loading
Loading