diff --git a/core/types/deposit_request.go b/core/types/deposit_request.go index 33638921322..a31134b8973 100644 --- a/core/types/deposit_request.go +++ b/core/types/deposit_request.go @@ -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 ( @@ -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, @@ -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) { diff --git a/tests/exec_spec_test.go b/tests/exec_spec_test.go index 974f3106c99..0e7c76e2783 100644 --- a/tests/exec_spec_test.go +++ b/tests/exec_spec_test.go @@ -37,6 +37,7 @@ 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/`) checkStateRoot := true