-
Notifications
You must be signed in to change notification settings - Fork 1k
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
payload electra cloning #14239
Merged
james-prysm
merged 12 commits into
develop
from
execution-payload-electra-cloner-fuzzing
Jul 19, 2024
Merged
payload electra cloning #14239
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e5f8c51
poc for payload electra cloning
james-prysm 5ef48eb
partial fixes
james-prysm 2276d85
fixing build
james-prysm 0acd1c6
addressing kasey's comment
james-prysm e755a79
Merge branch 'develop' into execution-payload-electra-cloner-fuzzing
james-prysm 72e5f45
forgot to unexport interface
james-prysm 317622f
making test more generic
james-prysm 0947bb4
making fuzzing slightly more robust
james-prysm 74ffc00
Merge branch 'develop' into execution-payload-electra-cloner-fuzzing
james-prysm 704bee6
renaming based on kasey's comment
james-prysm 686f2e0
using fuzz test in same package to avoid exporting interface
james-prysm 1b767f6
fixing build
james-prysm 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 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 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,92 @@ | ||
package enginev1 | ||
|
||
import "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" | ||
|
||
type copier[T any] interface { | ||
Copy() T | ||
} | ||
|
||
func copySlice[T any, C copier[T]](original []C) []T { | ||
// Create a new slice with the same length as the original | ||
newSlice := make([]T, len(original)) | ||
for i := 0; i < len(newSlice); i++ { | ||
newSlice[i] = original[i].Copy() | ||
} | ||
return newSlice | ||
} | ||
|
||
func (w *Withdrawal) Copy() *Withdrawal { | ||
if w == nil { | ||
return nil | ||
} | ||
|
||
return &Withdrawal{ | ||
Index: w.Index, | ||
ValidatorIndex: w.ValidatorIndex, | ||
Address: bytesutil.SafeCopyBytes(w.Address), | ||
Amount: w.Amount, | ||
} | ||
} | ||
|
||
func (d *DepositRequest) Copy() *DepositRequest { | ||
if d == nil { | ||
return nil | ||
} | ||
return &DepositRequest{ | ||
Pubkey: bytesutil.SafeCopyBytes(d.Pubkey), | ||
WithdrawalCredentials: bytesutil.SafeCopyBytes(d.WithdrawalCredentials), | ||
Amount: d.Amount, | ||
Signature: bytesutil.SafeCopyBytes(d.Signature), | ||
Index: d.Index, | ||
} | ||
} | ||
|
||
func (wr *WithdrawalRequest) Copy() *WithdrawalRequest { | ||
if wr == nil { | ||
return nil | ||
} | ||
return &WithdrawalRequest{ | ||
SourceAddress: bytesutil.SafeCopyBytes(wr.SourceAddress), | ||
ValidatorPubkey: bytesutil.SafeCopyBytes(wr.ValidatorPubkey), | ||
Amount: wr.Amount, | ||
} | ||
} | ||
|
||
func (cr *ConsolidationRequest) Copy() *ConsolidationRequest { | ||
if cr == nil { | ||
return nil | ||
} | ||
return &ConsolidationRequest{ | ||
SourceAddress: bytesutil.SafeCopyBytes(cr.SourceAddress), | ||
SourcePubkey: bytesutil.SafeCopyBytes(cr.SourcePubkey), | ||
TargetPubkey: bytesutil.SafeCopyBytes(cr.TargetPubkey), | ||
} | ||
} | ||
|
||
func (payload *ExecutionPayloadElectra) Copy() *ExecutionPayloadElectra { | ||
if payload == nil { | ||
return nil | ||
} | ||
return &ExecutionPayloadElectra{ | ||
ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), | ||
FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), | ||
StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), | ||
ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), | ||
LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), | ||
PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), | ||
BlockNumber: payload.BlockNumber, | ||
GasLimit: payload.GasLimit, | ||
GasUsed: payload.GasUsed, | ||
Timestamp: payload.Timestamp, | ||
ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), | ||
BaseFeePerGas: bytesutil.SafeCopyBytes(payload.BaseFeePerGas), | ||
BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), | ||
Transactions: bytesutil.SafeCopy2dBytes(payload.Transactions), | ||
Withdrawals: copySlice(payload.Withdrawals), | ||
BlobGasUsed: payload.BlobGasUsed, | ||
ExcessBlobGas: payload.ExcessBlobGas, | ||
DepositRequests: copySlice(payload.DepositRequests), | ||
WithdrawalRequests: copySlice(payload.WithdrawalRequests), | ||
ConsolidationRequests: copySlice(payload.ConsolidationRequests), | ||
} | ||
} |
This file contains 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,30 @@ | ||
package enginev1_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
) | ||
|
||
func TestCopyExecutionPayload_Fuzz(t *testing.T) { | ||
fuzzCopies(t, &enginev1.ExecutionPayloadElectra{}) | ||
} | ||
|
||
func fuzzCopies[T any, C enginev1.Copier[T]](t *testing.T, obj C) { | ||
fuzzer := fuzz.NewWithSeed(0) | ||
amount := 1000 | ||
t.Run(fmt.Sprintf("%T", obj), func(t *testing.T) { | ||
for i := 0; i < amount; i++ { | ||
fuzzer.Fuzz(obj) // Populate thing with random values | ||
got := obj.Copy() | ||
require.DeepEqual(t, obj, got) | ||
// check shallow copy working | ||
fuzzer.Fuzz(got) | ||
require.DeepNotEqual(t, obj, got) | ||
// TODO: think of deeper not equal fuzzing | ||
} | ||
}) | ||
} |
This file contains 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,3 @@ | ||
package enginev1 | ||
|
||
type Copier[T any] copier[T] |
This file contains 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 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.
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.
I'm going to approve so you can move on, but my nitpick is that we should name the interface after the method (
Cloneable
does not follow intuitively fromCopy
- the reflexive naming here should be something more likeCopyer
). If you want to address that now I'd appreciate it and give a fast follow-up approval, or you can do it in the follow-up PRs. Also, should the interface be exported?