Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
eb8c0a0
sae: Add C-chain custom tx serialization
StephenButtolph Apr 25, 2026
e248997
sae: Implement AsOp
StephenButtolph Apr 25, 2026
253c255
wip
StephenButtolph Apr 25, 2026
3cca8aa
comments
StephenButtolph Apr 25, 2026
6346d2e
reduce exported identifiers
StephenButtolph Apr 25, 2026
ab83fe6
wip
StephenButtolph Apr 26, 2026
8f3f888
wip
StephenButtolph Apr 26, 2026
83cc38b
wip
StephenButtolph Apr 26, 2026
d606762
Extend fuzz tests
StephenButtolph Apr 26, 2026
0a82734
nit
StephenButtolph Apr 26, 2026
5b86b6b
wip
StephenButtolph Apr 26, 2026
3d92bd5
wip
StephenButtolph Apr 26, 2026
893e17e
wip
StephenButtolph Apr 26, 2026
83b0ec0
wip
StephenButtolph Apr 26, 2026
c46bcc2
nit
StephenButtolph Apr 26, 2026
e92638f
nit
StephenButtolph Apr 26, 2026
f2faffb
lint
StephenButtolph Apr 26, 2026
7447b08
lint
StephenButtolph Apr 26, 2026
8c3b6f0
nits
StephenButtolph Apr 27, 2026
0369966
fix bazel
StephenButtolph Apr 28, 2026
85ae854
ci: free runner disk before publishing Antithesis images (#5310)
JonathanOppenheimer Apr 28, 2026
88a234a
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 28, 2026
4e261c6
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 28, 2026
7073c57
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 28, 2026
d63857d
merged
StephenButtolph Apr 28, 2026
06d2a41
nit
StephenButtolph Apr 28, 2026
c28b2d2
fuzz full op
StephenButtolph Apr 28, 2026
aba7590
mark as compatibility
StephenButtolph Apr 28, 2026
ca2a5ea
nit
StephenButtolph Apr 28, 2026
4be05cf
nit
StephenButtolph Apr 28, 2026
e721e6c
wip
StephenButtolph Apr 28, 2026
9b4c83f
nit
StephenButtolph Apr 28, 2026
5d9dd0d
merged
StephenButtolph Apr 28, 2026
2929163
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 28, 2026
af11c7e
sae: Implement AtomicRequests on custom txs
StephenButtolph Apr 28, 2026
57b2f73
wip
StephenButtolph Apr 28, 2026
c583599
lint + bazel
StephenButtolph Apr 28, 2026
2ffbf74
fix flake
StephenButtolph Apr 28, 2026
093fbdc
nit
StephenButtolph Apr 28, 2026
7e58c8e
nit
StephenButtolph Apr 28, 2026
ae780ec
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 28, 2026
d657fa3
nit
StephenButtolph Apr 28, 2026
8573565
nit
StephenButtolph Apr 28, 2026
2d50a62
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 28, 2026
5bb64d8
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 28, 2026
6741731
wip
StephenButtolph Apr 29, 2026
e70eabb
simplify
StephenButtolph Apr 29, 2026
e74bda2
wip
StephenButtolph Apr 29, 2026
5a741ec
wip
StephenButtolph Apr 29, 2026
7709421
wip
StephenButtolph Apr 29, 2026
2f01ee8
Unblock myself for sae progress
StephenButtolph Apr 29, 2026
b28d132
sae: Smarter tx fuzzing
StephenButtolph Apr 29, 2026
f12a1b4
nit
StephenButtolph Apr 29, 2026
258df6f
nit
StephenButtolph Apr 29, 2026
8cefe95
nit
StephenButtolph Apr 29, 2026
fa25c9a
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 29, 2026
95e7256
nit
StephenButtolph Apr 29, 2026
5d2ef23
want got
StephenButtolph Apr 29, 2026
46814f4
want got
StephenButtolph Apr 29, 2026
58306f5
Merge branch 'StephenButtolph/atomic-tx-rewrite.1' of github.com:ava-…
StephenButtolph Apr 29, 2026
88c09d1
merged
StephenButtolph Apr 29, 2026
271658d
nit
StephenButtolph Apr 29, 2026
9da6af8
nit
StephenButtolph Apr 29, 2026
7bcb962
ci
StephenButtolph Apr 29, 2026
34b1457
nosec
StephenButtolph Apr 29, 2026
692f899
merged
StephenButtolph Apr 29, 2026
eedd62e
nit
StephenButtolph Apr 29, 2026
e1ece39
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 29, 2026
9e3bb98
ci
StephenButtolph Apr 29, 2026
1220398
merged
StephenButtolph Apr 29, 2026
a4bad9b
remove duplicate code
StephenButtolph Apr 29, 2026
56850ce
nit
StephenButtolph Apr 29, 2026
a41e9a6
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 29, 2026
22ebf97
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 29, 2026
c74091e
nit
StephenButtolph Apr 29, 2026
cefd09f
nit
StephenButtolph Apr 29, 2026
2ed8fcb
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 29, 2026
bd9366e
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 29, 2026
f662e76
merged
StephenButtolph Apr 29, 2026
163274f
nit
StephenButtolph Apr 29, 2026
05ddba9
oops
StephenButtolph Apr 29, 2026
192a266
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 29, 2026
3fd9a97
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 29, 2026
1ecbbbe
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 29, 2026
9b0449c
why
StephenButtolph Apr 29, 2026
7e35e32
ci
StephenButtolph Apr 29, 2026
fca7808
no moar recursion pls
StephenButtolph Apr 29, 2026
f47cf40
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 29, 2026
5bdb2df
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 29, 2026
68a4263
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 29, 2026
1ede276
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 29, 2026
01cc4cf
Merge branch 'StephenButtolph/atomic-tx-rewrite.1' into StephenButtol…
StephenButtolph Apr 29, 2026
bc6aed5
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 29, 2026
666066d
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 29, 2026
affa630
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 29, 2026
0de4a41
nit
StephenButtolph Apr 29, 2026
87d29d2
nit
StephenButtolph Apr 29, 2026
8535be8
nit
StephenButtolph Apr 29, 2026
61c3b90
nit
StephenButtolph Apr 29, 2026
6e9545c
Use the identifier rather than where the identifier is used
StephenButtolph Apr 30, 2026
47fe30d
Update visability
StephenButtolph Apr 30, 2026
adeaa57
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 30, 2026
6350008
merged
StephenButtolph Apr 30, 2026
05bb2f4
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
ba1afe1
nit
StephenButtolph Apr 30, 2026
166a9c2
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
e9487dc
merged
StephenButtolph Apr 30, 2026
51fa5f8
merged
StephenButtolph Apr 30, 2026
3e3e6aa
ci
StephenButtolph Apr 30, 2026
9ffcd6c
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
980daa5
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
2523cbe
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 30, 2026
963c295
remove jank, use cmp
StephenButtolph Apr 30, 2026
937c6f8
merged
StephenButtolph Apr 30, 2026
8ae1a82
fix
StephenButtolph Apr 30, 2026
3d11e3b
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
d39ed4d
nit
StephenButtolph Apr 30, 2026
18c3c2b
merged
StephenButtolph Apr 30, 2026
ce459c0
merged
StephenButtolph Apr 30, 2026
05930e4
missed one
StephenButtolph Apr 30, 2026
9e0ffe5
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
7f3d20d
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
f40a866
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 30, 2026
3937331
more cmp
StephenButtolph Apr 30, 2026
a6aca7c
nit
StephenButtolph Apr 30, 2026
99f52e1
nit
StephenButtolph Apr 30, 2026
18a656e
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
63fb810
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
13afb7e
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 30, 2026
8bb04f6
bazel
StephenButtolph Apr 30, 2026
e6a1d35
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
28419a7
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
d75cd34
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 30, 2026
149b1cb
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.1
StephenButtolph Apr 30, 2026
a781d21
Merge branch 'StephenButtolph/atomic-tx-rewrite.1' into StephenButtol…
StephenButtolph Apr 30, 2026
23b9916
Add comment
StephenButtolph Apr 30, 2026
c1b9fa8
nit
StephenButtolph Apr 30, 2026
b4d98b5
nit
StephenButtolph Apr 30, 2026
81c3c02
nit
StephenButtolph Apr 30, 2026
9e36643
nit
StephenButtolph Apr 30, 2026
61dcfbd
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
ca7c26b
merged
StephenButtolph Apr 30, 2026
268f6ed
Merge branch 'StephenButtolph/smart-atomic-tx-fuzzing' into StephenBu…
StephenButtolph Apr 30, 2026
5334079
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
9b3d867
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 30, 2026
40c3ba6
cleanup
StephenButtolph Apr 30, 2026
3ed6547
cleanup
StephenButtolph Apr 30, 2026
f0515ec
Add more cases
StephenButtolph Apr 30, 2026
6dbe653
add comments
StephenButtolph Apr 30, 2026
9ae76cc
Add interface check
StephenButtolph Apr 30, 2026
6838983
nit
StephenButtolph Apr 30, 2026
4e67fcf
merged
StephenButtolph Apr 30, 2026
97b4ba8
merged
StephenButtolph Apr 30, 2026
d44b9e6
grammar
StephenButtolph Apr 30, 2026
c5df5ae
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
f84b71e
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph Apr 30, 2026
900d328
nit
StephenButtolph Apr 30, 2026
bcc4037
nit
StephenButtolph Apr 30, 2026
5370371
more succinct
StephenButtolph Apr 30, 2026
7eb1978
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
b9c18ef
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
21cdd76
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' of github.com:ava-…
StephenButtolph Apr 30, 2026
cfd18da
merged
StephenButtolph Apr 30, 2026
b555a85
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph Apr 30, 2026
a5c21d1
pedantic
StephenButtolph Apr 30, 2026
eb701ee
ok
StephenButtolph Apr 30, 2026
1ad0654
Document codec weirdness
StephenButtolph Apr 30, 2026
1f860c9
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph May 1, 2026
921d35d
cleanup
StephenButtolph May 1, 2026
e340ee9
nit
StephenButtolph May 1, 2026
38c857d
nit
StephenButtolph May 1, 2026
26a19a4
nit
StephenButtolph May 1, 2026
0277d22
nit
StephenButtolph May 1, 2026
342b458
nit
StephenButtolph May 1, 2026
f37215f
nit
StephenButtolph May 1, 2026
f456eac
address nit
StephenButtolph May 1, 2026
ac82445
simplify
StephenButtolph May 2, 2026
cab3300
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.2
StephenButtolph May 2, 2026
8fe92a5
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph May 2, 2026
3f7b7c6
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.2
StephenButtolph May 2, 2026
efca198
Merge branch 'StephenButtolph/atomic-tx-rewrite.2' into StephenButtol…
StephenButtolph May 2, 2026
51a986d
reduce diff
StephenButtolph May 2, 2026
86b2b6e
oops
StephenButtolph May 2, 2026
f6faf2d
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph May 2, 2026
904a654
nit
StephenButtolph May 2, 2026
a24de25
nit
StephenButtolph May 2, 2026
61a40ce
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph May 2, 2026
c4b9ef4
nit
StephenButtolph May 2, 2026
7240e8e
Merge branch 'StephenButtolph/atomic-tx-rewrite.4' of github.com:ava-…
StephenButtolph May 2, 2026
ba626f8
wip
StephenButtolph May 3, 2026
66ed39e
nit expand test
StephenButtolph May 4, 2026
03f7e3e
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph May 4, 2026
fcc28ad
reduce diff
StephenButtolph May 4, 2026
458729d
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph May 4, 2026
0845724
Merge branch 'master' into StephenButtolph/atomic-tx-rewrite.3
StephenButtolph May 4, 2026
19b2c1a
Merge branch 'StephenButtolph/atomic-tx-rewrite.3' into StephenButtol…
StephenButtolph May 4, 2026
6feb25b
kiss
StephenButtolph May 4, 2026
7ec149a
bazel
StephenButtolph May 4, 2026
517e895
test full state
StephenButtolph May 4, 2026
03c4e8f
nits
StephenButtolph May 4, 2026
da34043
nit
StephenButtolph May 4, 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
6 changes: 6 additions & 0 deletions vms/saevm/cchain/tx/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
"//chains/atomic",
"//codec",
"//codec/linearcodec",
"//graft/coreth/core/extstate",
"//graft/coreth/plugin/evm/atomic",
"//graft/coreth/plugin/evm/upgrade/ap5",
"//ids",
Expand All @@ -44,6 +45,8 @@ go_test(
embed = [":tx"],
deps = [
"//chains/atomic",
"//graft/coreth/core/extstate",
"//graft/coreth/plugin/evm",
"//graft/coreth/plugin/evm/atomic",
"//graft/coreth/plugin/evm/atomic/vm",
"//ids",
Expand All @@ -57,6 +60,9 @@ go_test(
"//vms/saevm/hook",
"//vms/secp256k1fx",
"@com_github_ava_labs_libevm//common",
"@com_github_ava_labs_libevm//core/rawdb",
"@com_github_ava_labs_libevm//core/state",
"@com_github_ava_labs_libevm//core/types",
"@com_github_google_go_cmp//cmp",
"@com_github_google_go_cmp//cmp/cmpopts",
"@com_github_holiman_uint256//:uint256",
Expand Down
65 changes: 60 additions & 5 deletions vms/saevm/cchain/tx/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import (
"encoding/json"
"math"
"math/big"
"testing"

Expand All @@ -15,7 +16,9 @@
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/graft/coreth/core/extstate"
"github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/atomic"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/components/gas"
"github.com/ava-labs/avalanchego/vms/saevm/cchain/tx/txtest"
Expand All @@ -24,10 +27,17 @@
. "github.com/ava-labs/avalanchego/vms/saevm/cchain/tx"
)

// fuzz seeds f with [NewTxs] and fuzzes the test.
// fuzz seeds f with [NewTxs], specifies simple alphabets used to bias the
Comment thread
StephenButtolph marked this conversation as resolved.
// fuzzer, and fuzzes the test.
func fuzz(f *testing.F, ff func(t *testing.T, tx *Tx)) {
fuzzer := &txtest.F{
F: f,
Addresses: []common.Address{
{1},
Comment thread
StephenButtolph marked this conversation as resolved.
},
AssetIDs: []ids.ID{
AVAXAssetID,
},
}
for _, tx := range NewTxs {
fuzzer.Add(tx)
Expand Down Expand Up @@ -128,17 +138,15 @@
}

func (*asOpStateDB) GetBalance(common.Address) *uint256.Int {
// Large enough to never underflow, but small enough to never overflow.
return new(uint256.Int).Lsh(uint256.NewInt(1), 128)
return largeUint256()
}

func (*asOpStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}

func (*asOpStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}

func (*asOpStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int {
// Large enough to never underflow, but small enough to never overflow.
return new(big.Int).Lsh(big.NewInt(1), 128)
return largeBigInt()
}

func (s *asOpStateDB) SetNonce(addr common.Address, nonce uint64) {
Expand All @@ -165,3 +173,50 @@
assert.Equal(t, wantRequests, gotRequests, "requests")
})
}

func FuzzTransferNonAVAXCompatibility(f *testing.F) {
fuzz(f, func(t *testing.T, newTx *Tx) {
op, err := newTx.AsOp(AVAXAssetID)
if err != nil {
t.Skip("invalid tx")
}

oldState := NewEmptyStateDB(t)
newState := NewEmptyStateDB(t)
states := []*extstate.StateDB{oldState, newState}
Comment thread
StephenButtolph marked this conversation as resolved.

if tx, ok := newTx.Unsigned.(*Export); ok {
for _, in := range tx.Ins {
// Coreth silently overflows the nonce, whereas SAE will leave
// the nonce unmodified. This difference doesn't matter on live
// networks.
if in.Nonce == math.MaxUint64 {
t.Skip("nonce overflow")
}

for _, state := range states {
state.AddBalance(in.Address, largeUint256())
state.SetNonce(in.Address, in.Nonce)
state.AddBalanceMultiCoin(in.Address, common.Hash(in.AssetID), largeBigInt())
}
}
Comment thread
StephenButtolph marked this conversation as resolved.
}

var (
oldTx = ToOldTx(t, newTx)
ctx = &snow.Context{AVAXAssetID: AVAXAssetID}
)
require.NoErrorf(t, oldTx.EVMStateTransfer(ctx, oldState), "%T.EVMStateTransfer()", oldTx)
require.NoErrorf(t, newTx.TransferNonAVAX(AVAXAssetID, newState), "%T.TransferNonAVAX()", newTx)
require.NoErrorf(t, op.ApplyTo(newState.StateDB), "%T.ApplyTo(%T)", op, newState.StateDB)

if diff := CompareStateDBs(oldState, newState); diff != "" {
t.Errorf("%T.TransferNonAVAX() diff (-want +got):\n%s", newTx, diff)

Check warning on line 214 in vms/saevm/cchain/tx/compatibility_test.go

View workflow job for this annotation

GitHub Actions / Lint

`t.Errorf`" consider the assert and require libraries for succinct tests
}
})
}

// largeUint256 and largeBigInt return a balance large enough to never underflow
// but small enough to never overflow during test arithmetic.
func largeUint256() *uint256.Int { return new(uint256.Int).Lsh(uint256.NewInt(1), 128) }
func largeBigInt() *big.Int { return new(big.Int).Lsh(big.NewInt(1), 128) }
Comment thread
JonathanOppenheimer marked this conversation as resolved.
21 changes: 21 additions & 0 deletions vms/saevm/cchain/tx/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ package tx
import (
"errors"
"fmt"
"math/big"

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

// Imported for [atomic.UnsignedExportTx.Burned] comment resolution.
_ "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/atomic"

"github.com/ava-labs/avalanchego/graft/coreth/core/extstate"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we weren't import graft?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the transition logic, we need to share the libevm registrations during the SAE migration.

We can either:

  1. Have SAE depend on coreth for the libevm registrations
  2. Move the libevm registrations into SAE and have coreth depend on SAE.

I felt like (1) was less work and wouldn't require moving anything non-SAE related into the SAE codebase (since I presume there is some sprawl in these areas that will be removed once we are in an SAE only world).

But you're right that we should be extremely conservative with any dependencies on coreth. I think it should only be for the libevm registrations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a slippery slope and I don't like importing graft -- I feel like we could get lazy with this. Can we have an SAE package that will be explicitly deprecated and must be removed for things to be 'good', in a similar way we did the RPC stubs and temporary package.

Copy link
Copy Markdown
Contributor

@powerslider powerslider May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options here are either to just start working on the migration of those packages or just to decouple with port interfaces. We will inevitably hit these issues so we just need to decide if we will lean on dependency inversion (at least temporary) or just accept importing from graft.
Here is an example of how I've applied this pattern in graft/evm when I did not want to import any graft/coreth packages in the code.

This way my only dependency is the interface while the implementation sits in graft/coreth.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would make sense to try to add some interface indirection. That really only works if you want to own the top and bottom of the stack, but not the middle... For SAE, we want to own the top (but not the bottom) of the stack... So we would need to import graft anyways in that world.

I agree that importing graft is something we need to do very sparingly, but I don't think adding a file with a bunch of aliases really helps us that much... It'll be very easy to see where graft is used (by just searching for the imports) and we will need to inspect the usage as we go around whether or not it makes sense to actually depend on that component within graft.

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand Down Expand Up @@ -136,3 +138,22 @@ func (e *Export) atomicRequests(txID ids.ID) (ids.ID, *chainsatomic.Requests, er
}
return e.DestinationChain, &chainsatomic.Requests{PutRequests: elems}, nil
}

var errInsufficientFunds = errors.New("insufficient funds")

// TransferNonAVAX subtracts the non-AVAX balances from the statedb.
func (e *Export) TransferNonAVAX(avaxAssetID ids.ID, statedb *extstate.StateDB) error {
Comment thread
StephenButtolph marked this conversation as resolved.
for _, in := range e.Ins {
if in.AssetID == avaxAssetID {
continue
}

coinID := common.Hash(in.AssetID)
amount := new(big.Int).SetUint64(in.Amount)
if balance := statedb.GetBalanceMultiCoin(in.Address, coinID); balance.Cmp(amount) < 0 {
return fmt.Errorf("%w: address %s asset %s has %d want %d", errInsufficientFunds, in.Address, coinID, balance, amount)
}
statedb.SubBalanceMultiCoin(in.Address, coinID, amount)
}
return nil
}
16 changes: 16 additions & 0 deletions vms/saevm/cchain/tx/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ package tx
import (
"errors"
"fmt"
"math/big"

"github.com/ava-labs/libevm/common"
"github.com/holiman/uint256"

// Imported for [atomic.UnsignedImportTx.Burned] comment resolution.
_ "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/atomic"

"github.com/ava-labs/avalanchego/graft/coreth/core/extstate"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand Down Expand Up @@ -121,3 +123,17 @@ func (i *Import) atomicRequests(ids.ID) (ids.ID, *chainsatomic.Requests, error)
}
return i.SourceChain, &chainsatomic.Requests{RemoveRequests: utxoIDs}, nil
}

// TransferNonAVAX adds the non-AVAX balances to the statedb.
func (i *Import) TransferNonAVAX(avaxAssetID ids.ID, statedb *extstate.StateDB) error {
for _, out := range i.Outs {
if out.AssetID == avaxAssetID {
continue
}

coinID := common.Hash(out.AssetID)
amount := new(big.Int).SetUint64(out.Amount)
statedb.AddBalanceMultiCoin(out.Address, coinID, amount)
}
return nil
}
15 changes: 11 additions & 4 deletions vms/saevm/cchain/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// Imported for [atomic.TxBytesGas] comment resolution.
_ "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/atomic"

"github.com/ava-labs/avalanchego/graft/coreth/core/extstate"
"github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap5"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/hashing"
Expand All @@ -36,9 +37,15 @@ type Tx struct {

// Unsigned is a common interface implemented by [Import] and [Export].
//
// TODO(StephenButtolph): Expand this interface to include UTXO handling,
// verification, and state execution.
// TODO(StephenButtolph): Expand this interface to include UTXO handling and
// verification.
type Unsigned interface {
// TransferNonAVAX transfers the non-AVAX balances requested by this
// transaction.
//
// Non-AVAX transfers were only allowed prior to the Banff upgrade.
TransferNonAVAX(avaxAssetID ids.ID, statedb *extstate.StateDB) error
Comment thread
JonathanOppenheimer marked this conversation as resolved.
Comment thread
StephenButtolph marked this conversation as resolved.

// burned returns the amount of assetID that is consumed but not produced by
// this transaction.
burned(assetID ids.ID) (uint64, error)
Expand All @@ -47,8 +54,8 @@ type Unsigned interface {
// transaction.
numSigs() (uint64, error)

// asOp returns the operation that this transaction performs on the EVM
// state.
// asOp returns the operation that this transaction performs on the
// EVM-native state. Ops do not include any non-AVAX balance changes.
asOp(avaxAssetID ids.ID) (op, error)

// atomicRequests returns the operations that should be applied to shared
Expand Down
Loading
Loading