mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Deneb - web3signer (#12767)
* wip * adding deneb block * adding in support for blobs and fixing unit tests for deneb * fixing linting * gaz * adding support for new web3signer version * fixing tag name * addressing feedback * fixing tests * adding unit test for review * updating test name * updating unit tests and length logic * adding in lengthfor root * adjusting max blob length * fixing mock * fixing another mock * gaz * adding network configs * removing duplicate * changing based on nishant's feedback * Update validator/keymanager/remote-web3signer/v1/requests.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * Update validator/keymanager/remote-web3signer/metrics.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * sammy's suggestions * removing temp file --------- Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -96,7 +96,7 @@ func SlashingsRoot(slashings []uint64) ([32]byte, error) {
|
||||
func TransactionsRoot(txs [][]byte) ([32]byte, error) {
|
||||
txRoots := make([][32]byte, 0)
|
||||
for i := 0; i < len(txs); i++ {
|
||||
rt, err := transactionRoot(txs[i])
|
||||
rt, err := ByteSliceRoot(txs[i], fieldparams.MaxBytesPerTxLength) // getting the transaction root here
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
@@ -141,19 +141,21 @@ func WithdrawalSliceRoot(withdrawals []*enginev1.Withdrawal, limit uint64) ([32]
|
||||
return MixInLength(bytesRoot, bytesRootBufRoot), nil
|
||||
}
|
||||
|
||||
func transactionRoot(tx []byte) ([32]byte, error) {
|
||||
chunkedRoots, err := PackByChunk([][]byte{tx})
|
||||
// ByteSliceRoot is a helper func to merkleize an arbitrary List[Byte, N]
|
||||
// this func runs Chunkify + MerkleizeVector
|
||||
// max length is dividable by 32 ( root length )
|
||||
func ByteSliceRoot(slice []byte, maxLength uint64) ([32]byte, error) {
|
||||
chunkedRoots, err := PackByChunk([][]byte{slice})
|
||||
if err != nil {
|
||||
return [32]byte{}, err
|
||||
}
|
||||
|
||||
maxLength := (fieldparams.MaxBytesPerTxLength + 31) / 32
|
||||
bytesRoot, err := BitwiseMerkleize(chunkedRoots, uint64(len(chunkedRoots)), uint64(maxLength))
|
||||
maxRootLength := (maxLength + 31) / 32 // nearest number divisible by root length (32)
|
||||
bytesRoot, err := BitwiseMerkleize(chunkedRoots, uint64(len(chunkedRoots)), maxRootLength)
|
||||
if err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not compute merkleization")
|
||||
}
|
||||
bytesRootBuf := new(bytes.Buffer)
|
||||
if err := binary.Write(bytesRootBuf, binary.LittleEndian, uint64(len(tx))); err != nil {
|
||||
if err := binary.Write(bytesRootBuf, binary.LittleEndian, uint64(len(slice))); err != nil {
|
||||
return [32]byte{}, errors.Wrap(err, "could not marshal length")
|
||||
}
|
||||
bytesRootBufRoot := make([]byte, 32)
|
||||
|
||||
@@ -122,6 +122,58 @@ func TestTransactionsRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteSliceRoot(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
slice []byte
|
||||
maxLength uint64
|
||||
want [32]byte
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
slice: nil,
|
||||
want: [32]byte{245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169, 39, 89, 251, 75},
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
slice: []byte{},
|
||||
want: [32]byte{245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169, 39, 89, 251, 75},
|
||||
},
|
||||
{
|
||||
name: "byte slice 3 values",
|
||||
slice: []byte{1, 2, 3},
|
||||
want: [32]byte{20, 159, 26, 252, 247, 204, 44, 159, 161, 135, 211, 195, 106, 59, 220, 149, 199, 163, 228, 155, 113, 118, 64, 126, 173, 223, 102, 1, 241, 158, 164, 185},
|
||||
},
|
||||
{
|
||||
name: "byte slice 32 values",
|
||||
slice: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32},
|
||||
want: [32]byte{7, 30, 46, 77, 237, 240, 59, 126, 232, 232, 232, 6, 145, 210, 31, 18, 117, 12, 217, 40, 204, 141, 90, 236, 241, 128, 221, 45, 126, 39, 39, 202},
|
||||
},
|
||||
{
|
||||
name: "over max length",
|
||||
slice: make([]byte, fieldparams.RootLength+1),
|
||||
want: [32]byte{},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.maxLength == 0 {
|
||||
tt.maxLength = fieldparams.RootLength
|
||||
}
|
||||
got, err := ssz.ByteSliceRoot(tt.slice, tt.maxLength)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ByteSliceRoot() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ByteSliceRoot() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackByChunk_SingleList(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user