sae: Add C-chain custom tx serialization#5307
Conversation
| var ( | ||
| tests = []struct { | ||
| name string | ||
| old *atomic.Tx |
There was a problem hiding this comment.
This package includes both old and new in the tests to ensure compatibility with the prior code. Technically we could remove old and just treat the bytes as canonical... But it made me more confident in the change.
| func FuzzParseCompatibility(f *testing.F) { | ||
| for _, test := range tests { | ||
| f.Add(test.bytes) | ||
| } | ||
| f.Fuzz(func(t *testing.T, data []byte) { | ||
| _, oldErr := parseOldTx(data) | ||
| oldOk := oldErr == nil | ||
|
|
||
| _, newErr := Parse(data) | ||
| newOk := newErr == nil | ||
|
|
||
| assert.Equal(t, oldOk, newOk, "Parse(b) == parseOldTx(b)") | ||
| }) | ||
| } |
There was a problem hiding this comment.
The testdata included for this test did fail during development, so those are intentionally kept as regression tests. I actually wasn't aware prior to this that the old tx parsing logic could result in non-secp256k1fx.Credentials being parsed into the credential type.
It is safe, as we verify the types later during verification... But it caused this test to fail.
I have since verified that such type confusion can no longer happen with this package.
There was a problem hiding this comment.
Pull request overview
This PR introduces a dedicated vms/saevm/cchain/tx package to provide canonical (binary + JSON) serialization/parsing for C-Chain atomic import/export transactions, factoring out logic from the earlier work and tightening codec/type restrictions.
Changes:
- Added a new C-Chain atomic tx package with its own unexported codec manager and helpers to marshal/parse single txs and tx slices.
- Added unit + fuzz tests to ensure binary/JSON compatibility with the existing coreth atomic tx encoding and known mainnet tx fixtures.
- Introduced small supporting API changes:
secp256k1fx.Credential.Self(),ids.ShortFromStringOrPanic, and exportedatomic.ErrMissingAtomicTxs.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
vms/saevm/cchain/tx/tx.go |
Defines the new signed tx type, ID/Bytes helpers, and slice marshal/parse helpers. |
vms/saevm/cchain/tx/codec.go |
Creates an internal codec manager with explicit type registration order. |
vms/saevm/cchain/tx/import.go |
Adds the unsigned Import tx definition and C-Chain Output type. |
vms/saevm/cchain/tx/export.go |
Adds the unsigned Export tx definition and C-Chain Input type. |
vms/saevm/cchain/tx/tx_test.go |
Adds known-vector tests plus fuzzers for compatibility and round-trips. |
vms/saevm/cchain/tx/testdata/fuzz/** |
Adds fuzz corpora for regression and coverage. |
vms/saevm/cchain/tx/BUILD.bazel |
Bazel build/test targets for the new package and its tests. |
vms/secp256k1fx/credential.go |
Adds Self() to support restricting credential types in the new codec-facing interface. |
ids/short.go |
Adds ShortFromStringOrPanic helper. |
graft/coreth/plugin/evm/atomic/codec.go |
Exports the “missing atomic txs” error as ErrMissingAtomicTxs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
635de64 to
f58a0aa
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d3e8110 to
eb8c0a0
Compare
alarso16
left a comment
There was a problem hiding this comment.
Having seen the final form of the atomic txs, I think this is fine. I don't love the test format, only because it would be really difficult to maintain. However, I'm approving with the hope that we will delete it all after the H upgrade.
I felt like using the prior code made these tests stronger... Once we remove coreth, the compatibility fuzzing will go away, but the test vectors will still exist. |
JonathanOppenheimer
left a comment
There was a problem hiding this comment.
I believe the bazel metadata has to be re-generated
| "//tests/reexecute/c", | ||
| "//tests/reexecute/chaos", | ||
| "//vms/evm/emulate", | ||
| "//vms/saevm/cchain/...", |
There was a problem hiding this comment.
@ARR4N is this an anti-pattern? I could just expose this to the packages as needed rather than for the whole sub-tree.
There was a problem hiding this comment.
Not an anti-pattern, just a question of what we believe the most appropriate scope to be. The others are only fine-grained because I had my agent (Maru) do it (with his agent). I think we could reasonably allow anything in //tests/... too but there's no need right now.
To me the more important thing is that the other //vms/saevm packages never import the //vms/saevm/cchain ones.
There was a problem hiding this comment.
I updated the visibility logic to match graft/coreth.
…labs/avalanchego into StephenButtolph/atomic-tx-rewrite.1
| "//tests/reexecute/c", | ||
| "//tests/reexecute/chaos", | ||
| "//vms/evm/emulate", | ||
| "//vms/saevm/cchain/...", |
There was a problem hiding this comment.
Not an anti-pattern, just a question of what we believe the most appropriate scope to be. The others are only fine-grained because I had my agent (Maru) do it (with his agent). I think we could reasonably allow anything in //tests/... too but there's no need right now.
To me the more important thing is that the other //vms/saevm packages never import the //vms/saevm/cchain ones.
Why this should be merged
This PR factors out tx serialization from #5303.
How this works
The new
txpackage still relies on the avalanchego codec for serialization, however some changes were made to the transactions to provide a better QoL when interacting with the custom Txs.txshould be manually marshaling or unmarshaling transactions.secp256k1fx.Inputandsecp256k1fx.OutputOwners. Those are removed.tx.Credsslice to be populated with types that are disallowed by later type-checks:secp256k1fx.Input,secp256k1fx.OutputOwners,secp256k1fx.TransferOutput, andsecp256k1fx.TransferInput. The new transaction type disallows this within the codec.atomic.Metadatawithin the unsigned transaction implementations was removed. We may choose to add caching back in later, but if done, it should be done at theTxlevel once, rather than in bothExportandImport.I'm marking myself as the only code-owner of this folder (at least until @ARR4N comes back from PTO)
How this was tested
ImportandExporttxs from mainnet C-chain as known valid transactions.Need to be documented in RELEASES.md?
No