Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
consolidations := misc.DequeueConsolidationRequests7251(syscall)
rs = append(rs, consolidations...)
if requestsInBlock != nil || header.RequestsRoot != nil {
rh := types.DeriveSha(rs)
rh := rs.Hash()
if *header.RequestsRoot != rh {
return nil, nil, nil, fmt.Errorf("error: invalid requests root hash in header, expected: %v, got :%v", header.RequestsRoot, rh)
}
Expand Down
71 changes: 33 additions & 38 deletions core/types/deposit_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import (
"github.com/erigontech/erigon-lib/common/hexutil"
"github.com/erigontech/erigon-lib/common/hexutility"

rlp2 "github.com/erigontech/erigon-lib/rlp"
"github.com/erigontech/erigon/accounts/abi"
"github.com/erigontech/erigon/rlp"
)

const (
Expand Down Expand Up @@ -70,37 +68,42 @@ type DepositRequestJson struct {

func (d *DepositRequest) RequestType() byte { return DepositRequestType }
func (d *DepositRequest) EncodeRLP(w io.Writer) (err error) {
var buf bytes.Buffer
bb := make([]byte, 10)
if err = rlp.Encode(&buf, d.Pubkey); err != nil {
b := []byte{}
b = append(b, DepositRequestType)
b = append(b, d.Pubkey[:]...)
b = append(b, d.WithdrawalCredentials.Bytes()...)
b = binary.LittleEndian.AppendUint64(b, d.Amount)
b = append(b, d.Signature[:]...)
b = binary.LittleEndian.AppendUint64(b, d.Index)

if _, err = w.Write(b); err != nil {
return err
}
if err = rlp.Encode(&buf, d.WithdrawalCredentials); err != nil {
return err
}
if err = rlp.EncodeInt(d.Amount, &buf, bb); err != nil {
return err
}
if err = rlp.Encode(&buf, d.Signature); err != nil {
return err
}
if err = rlp.EncodeInt(d.Index, &buf, bb); err != nil {
return err
}
rlp2.EncodeListPrefix(buf.Len(), bb)
if _, err = w.Write([]byte{DepositRequestType}); err != nil {
return err
}
if _, err = w.Write(bb[0:2]); err != nil {
return err
}
if _, err = w.Write(buf.Bytes()); err != nil {
return err
}

return
}
func (d *DepositRequest) DecodeRLP(input []byte) error { return rlp.DecodeBytes(input[1:], d) }
func (d *DepositRequest) DecodeRLP(input []byte) error {
if len(input) != d.EncodingSize() {
return errors.New("Error decoding Deposit Request RLP - size mismatch in input")
}
i := 1
d.Pubkey = [BLSPubKeyLen]byte(input[i : i+BLSPubKeyLen])
i += BLSPubKeyLen
d.WithdrawalCredentials = libcommon.Hash(input[i : i+WithdrawalCredentialsLen])
i += WithdrawalCredentialsLen
d.Amount = binary.LittleEndian.Uint64(input[i : i+8])
i += 8
d.Signature = [BLSSigLen]byte(input[i : i+BLSSigLen])
i += BLSSigLen
d.Index = binary.LittleEndian.Uint64(input[i : i+8])
return nil
}

func (d *DepositRequest) Encode() []byte {
b := bytes.NewBuffer([]byte{})
d.EncodeRLP(b)
return b.Bytes()
}

func (d *DepositRequest) copy() Request {
return &DepositRequest{
Pubkey: d.Pubkey,
Expand All @@ -112,15 +115,7 @@ func (d *DepositRequest) copy() Request {
}

func (d *DepositRequest) EncodingSize() (encodingSize int) {
encodingSize++
encodingSize += rlp.IntLenExcludingHead(d.Amount)
encodingSize++
encodingSize += rlp.IntLenExcludingHead(d.Index)

encodingSize += 180 // 1 + 48 + 1 + 32 + 1 + 1 + 96 (0x80 + pLen, 0x80 + wLen, 0xb8 + 2 + sLen)
encodingSize += rlp2.ListPrefixLen(encodingSize)
encodingSize += 1 //RequestType
return
return 1 + BLSPubKeyLen + WithdrawalCredentialsLen + 8 + BLSSigLen + 8 //
}

func (d *DepositRequest) MarshalJSON() ([]byte, error) {
Expand Down
15 changes: 15 additions & 0 deletions core/types/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
"math/bits"

"github.com/erigontech/erigon-lib/common"
libcommon "github.com/erigontech/erigon-lib/common"
rlp2 "github.com/erigontech/erigon-lib/rlp"
"github.com/erigontech/erigon/crypto"
"github.com/erigontech/erigon/crypto/cryptopool"
"github.com/erigontech/erigon/rlp"
)

Expand All @@ -38,6 +41,7 @@ type Request interface {
EncodeRLP(io.Writer) error
DecodeRLP([]byte) error
RequestType() byte
Encode() []byte
copy() Request
EncodingSize() int
}
Expand Down Expand Up @@ -99,6 +103,7 @@ func (r *Requests) DecodeRLP(s *rlp.Stream) (err error) {
}
}


func (r *Requests) EncodeRLP(w io.Writer) {
if r == nil {
return
Expand Down Expand Up @@ -130,6 +135,16 @@ func (r *Requests) EncodingSize() int {
return c
}

func (r *Requests) Hash() (h libcommon.Hash) {
sha := crypto.NewKeccakState()
for _, req := range *r {
sha.Write(crypto.Keccak256(req.Encode()))
}
sha.Read(h[:]) //nolint:errcheck
cryptopool.ReturnToPoolKeccak256(sha)
return h
}

func (r Requests) Deposits() DepositRequests {
deposits := make(DepositRequests, 0, len(r))
for _, req := range r {
Expand Down
38 changes: 19 additions & 19 deletions erigon-lib/gointerfaces/typesproto/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/exec_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func TestExecutionSpec(t *testing.T) {
bt.skipLoad(`^prague/eip2935_historical_block_hashes_from_state/block_hashes/block_hashes_history.json`)
bt.skipLoad(`^prague/eip7251_consolidations/`)
bt.skipLoad(`^prague/eip7685_general_purpose_el_requests/`)
bt.skipLoad(`^prague/eip6110_deposits/`)
bt.skipLoad(`^prague/eip7002_el_triggerable_withdrawals/`)
bt.skipLoad(`^prague/eip6110_deposits/`)
bt.skipLoad(`^prague/eip7002_el_triggerable_withdrawals/`)
checkStateRoot := true

Expand Down
Loading