-
Notifications
You must be signed in to change notification settings - Fork 246
feat: Ensure Header integrity on DA #2948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alpe
wants to merge
2
commits into
main
Choose a base branch
from
alex/daheader_envelope
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package syncing | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/evstack/ev-node/pkg/config" | ||
| "github.com/evstack/ev-node/pkg/genesis" | ||
| "github.com/evstack/ev-node/types" | ||
| ) | ||
|
|
||
| func TestDARetriever_StrictEnvelopeMode_Switch(t *testing.T) { | ||
| // Setup keys | ||
| addr, pub, signer := buildSyncTestSigner(t) | ||
| gen := genesis.Genesis{ChainID: "tchain", InitialHeight: 1, StartTime: time.Now().Add(-time.Second), ProposerAddress: addr} | ||
|
|
||
| r := newTestDARetriever(t, nil, config.DefaultConfig(), gen) | ||
|
|
||
| // 1. Create a Legacy Header (SignedHeader marshaled directly) | ||
| // This simulates old blobs on the network before the upgrade. | ||
| legacyHeader := &types.SignedHeader{ | ||
| Header: types.Header{ | ||
| BaseHeader: types.BaseHeader{ChainID: gen.ChainID, Height: 1, Time: uint64(time.Now().UnixNano())}, | ||
| ProposerAddress: addr, | ||
| }, | ||
| Signer: types.Signer{PubKey: pub, Address: addr}, | ||
| } | ||
| // Sign it | ||
| bz, err := types.DefaultAggregatorNodeSignatureBytesProvider(&legacyHeader.Header) | ||
| require.NoError(t, err) | ||
| sig, err := signer.Sign(bz) | ||
| require.NoError(t, err) | ||
| legacyHeader.Signature = sig | ||
|
|
||
| legacyBlob, err := legacyHeader.MarshalBinary() | ||
| require.NoError(t, err) | ||
|
|
||
| // 2. Create an Envelope Header (DAHeaderEnvelope) | ||
| // This simulates a new blob after upgrade. | ||
| envelopeHeader := &types.SignedHeader{ | ||
| Header: types.Header{ | ||
| BaseHeader: types.BaseHeader{ChainID: gen.ChainID, Height: 2, Time: uint64(time.Now().UnixNano())}, | ||
| ProposerAddress: addr, | ||
| }, | ||
| Signer: types.Signer{PubKey: pub, Address: addr}, | ||
| } | ||
| // Sign content | ||
| bz2, err := types.DefaultAggregatorNodeSignatureBytesProvider(&envelopeHeader.Header) | ||
| require.NoError(t, err) | ||
| sig2, err := signer.Sign(bz2) | ||
| require.NoError(t, err) | ||
| envelopeHeader.Signature = sig2 | ||
|
|
||
| // Create Envelope | ||
| // We need to sign the envelope itself. | ||
| // The `SubmitHeaders` logic wraps it. We emulate it here using `MarshalDAEnvelope`. | ||
| // First get canonical content bytes (fields 1-3) | ||
| contentBytes, err := envelopeHeader.MarshalBinary() | ||
| require.NoError(t, err) | ||
| // Sign envelope | ||
| envSig, err := signer.Sign(contentBytes) | ||
| require.NoError(t, err) | ||
| // Marshal to envelope | ||
| envelopeBlob, err := envelopeHeader.MarshalDAEnvelope(envSig) | ||
| require.NoError(t, err) | ||
|
|
||
| // --- Test Scenario --- | ||
|
|
||
| // A. Initial State: StrictMode is false. Legacy blob should be accepted. | ||
| assert.False(t, r.strictMode) | ||
|
|
||
| decodedLegacy := r.tryDecodeHeader(legacyBlob, 100) | ||
| require.NotNil(t, decodedLegacy) | ||
| assert.Equal(t, uint64(1), decodedLegacy.Height()) | ||
|
|
||
| // StrictMode should still be false because it was a legacy blob | ||
| assert.False(t, r.strictMode) | ||
|
|
||
| // B. Receiving Envelope: Should be accepted and Switch StrictMode to true. | ||
| decodedEnvelope := r.tryDecodeHeader(envelopeBlob, 101) | ||
| require.NotNil(t, decodedEnvelope) | ||
| assert.Equal(t, uint64(2), decodedEnvelope.Height()) | ||
|
|
||
| assert.True(t, r.strictMode, "retriever should have switched to strict mode") | ||
|
|
||
| // C. Receiving Legacy again: Should be REJECTED now. | ||
| // We reuse the same legacyBlob (or a new one, doesn't matter, structure is legacy). | ||
| decodedLegacyAgain := r.tryDecodeHeader(legacyBlob, 102) | ||
| assert.Nil(t, decodedLegacyAgain, "legacy blob should be rejected in strict mode") | ||
|
|
||
| // D. Receiving Envelope again: Should still be accepted. | ||
| decodedEnvelopeAgain := r.tryDecodeHeader(envelopeBlob, 103) | ||
| require.NotNil(t, decodedEnvelopeAgain) | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check appears to be redundant. Based on the logic flow, if
r.strictModeistruewhen this function is called,isValidEnvelopemust also betruefor execution to reach this line. Any case wherer.strictModeistrueandisValidEnvelopewould befalse(e.g., failed unmarshal, invalid signature, no signature) results in an early return from the function. Therefore, this conditional block seems to be unreachable and can be removed to simplify the code.