-
Notifications
You must be signed in to change notification settings - Fork 22
Add Header to Hotshot Payload #751
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
base: integration
Are you sure you want to change the base?
Changes from 2 commits
b81ad9d
9e161d4
9e154be
17cb56b
47a7ec1
f6e8b67
68c2765
bfcb745
a35744a
7219336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,8 @@ func TestParsePayload(t *testing.T) { | |
| } | ||
|
|
||
| // Parse the signed payload | ||
| signature, userDataHash, indices, messages, err := ParseHotShotPayload(signedPayload) | ||
| txType := ParseHotshotPayloadForHeader(signedPayload) | ||
| signature, userDataHash, indices, messages, err := ParseHotShotPayload(signedPayload, txType) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse payload: %v", err) | ||
| } | ||
|
|
@@ -123,7 +124,7 @@ func TestParsePayloadInvalidCases(t *testing.T) { | |
|
|
||
| for _, tc := range invalidPayloads { | ||
| t.Run(tc.description, func(t *testing.T) { | ||
| _, _, _, _, err := ParseHotShotPayload(tc.payload) | ||
| _, _, _, _, err := ParseHotShotPayload(tc.payload, nil) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a test to show that it will work with new transaction format as well as legacy? |
||
| if err == nil { | ||
| t.Errorf("expected error for case '%s', but got none", tc.description) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,11 +246,73 @@ func (s *EspressoStreamer) verifyLegacy(attestation []byte, signature [32]byte) | |
| return err | ||
| } | ||
|
|
||
| func (s *EspressoStreamer) verify(data []byte, userDataHashArr [32]byte, l1Height uint64, transactionType *arbutil.TransactionType) error { | ||
| if transactionType != nil { | ||
| txType := *transactionType | ||
| switch txType { | ||
| case arbutil.Legacy: | ||
| if s.espressoSGXVerifier == nil { | ||
| return fmt.Errorf("failed to verify attestation quote, legacy header found but sgx verifier is nil") | ||
| } | ||
| err := s.verifyLegacy(data, userDataHashArr) | ||
| if err != nil { | ||
| log.Warn("failed to verify attestation quote", "err", err) | ||
| return err | ||
| } | ||
| case arbutil.EphemeralKey: | ||
| err := s.verifyBatchPosterSignature(data, userDataHashArr, l1Height) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we create functions for each case instead of all this in one verify function? |
||
| if err == nil { | ||
| return nil | ||
| } else if strings.Contains(err.Error(), ErrRetryParsingHotShotPayload.Error()) { | ||
| log.Warn("retrying to verify batch poster signature", "err", err) | ||
| return err | ||
| } else { | ||
| log.Warn("failed to verify batch poster signature", "err", err) | ||
| return err | ||
| } | ||
| default: | ||
| return fmt.Errorf("failed to verify transaction, received unexpected transaction type: %d", txType) | ||
| } | ||
| } else { | ||
| var success bool | ||
| err := s.verifyBatchPosterSignature(data, userDataHashArr, l1Height) | ||
| if err == nil { | ||
| success = true | ||
| } else if strings.Contains(err.Error(), ErrRetryParsingHotShotPayload.Error()) { | ||
| log.Warn("retrying to verify batch poster signature", "err", err) | ||
| return err | ||
| } else { | ||
| log.Warn("failed to verify batch poster signature", "err", err) | ||
| } | ||
|
|
||
| if !success { | ||
| if s.espressoSGXVerifier == nil { | ||
| return fmt.Errorf("failed to verify attestation quote, legacy header found but sgx verifier is nil. %w", err) | ||
| } | ||
| err = s.verifyLegacy(data, userDataHashArr) | ||
| if err != nil { | ||
| log.Warn("failed to verify attestation quote", "err", err) | ||
| return err | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (s *EspressoStreamer) parseEspressoTransaction(tx espressoTypes.Bytes, l1Height uint64) ([]*MessageWithMetadataAndPos, error) { | ||
| signature, userDataHash, indices, messages, err := arbutil.ParseHotShotPayload(tx) | ||
| transactionType := arbutil.ParseHotshotPayloadForHeader(tx) | ||
| signature, userDataHash, indices, messages, err := arbutil.ParseHotShotPayload(tx, transactionType) | ||
| if err != nil { | ||
| log.Warn("failed to parse hotshot payload", "err", err) | ||
| return nil, err | ||
| if transactionType != nil { | ||
| // in case somehow we parsed a header and there wasnt one, try again | ||
| transactionType = nil | ||
| signature, userDataHash, indices, messages, err = arbutil.ParseHotShotPayload(tx, transactionType) | ||
| if err != nil { | ||
| log.Warn("failed to parse hotshot payload", "err", err) | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| } | ||
| if len(messages) == 0 { | ||
| return nil, ErrPayloadHadNoMessages | ||
|
|
@@ -260,25 +322,9 @@ func (s *EspressoStreamer) parseEspressoTransaction(tx espressoTypes.Bytes, l1He | |
| return nil, ErrUserDataHashNot32Bytes | ||
| } | ||
|
|
||
| userDataHashArr := [32]byte(userDataHash) | ||
|
|
||
| var success bool | ||
| err = s.verifyBatchPosterSignature(signature, userDataHashArr, l1Height) | ||
| if err == nil { | ||
| success = true | ||
| } else if strings.Contains(err.Error(), ErrRetryParsingHotShotPayload.Error()) { | ||
| log.Warn("retrying to verify batch poster signature", "err", err) | ||
| err = s.verify(signature, [32]byte(userDataHash), l1Height, transactionType) | ||
| if err != nil { | ||
| return nil, err | ||
| } else { | ||
| log.Warn("failed to verify batch poster signature", "err", err) | ||
| } | ||
|
|
||
| if !success && s.espressoSGXVerifier != nil { | ||
| err = s.verifyLegacy(signature, userDataHashArr) | ||
| if err != nil { | ||
| log.Warn("failed to verify attestation quote", "err", err) | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| result := []*MessageWithMetadataAndPos{} | ||
|
|
||
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.
can you also add comments on what each of this fields signifies?