Skip to content
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

Modify EIP-7702 Txn impl per pectra-devnet-4 specs #12416

Merged
merged 31 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
163f729
Rename requestsRoot to requestsHash
somnathb1 Oct 18, 2024
bbfd5bb
Go mod tidy
somnathb1 Oct 18, 2024
793c6cb
Remove requests from body, block and exeution payload
somnathb1 Oct 18, 2024
b42189c
Lint
somnathb1 Oct 18, 2024
a29c2f1
Revert unnecessary
somnathb1 Oct 18, 2024
9f26d39
Remove reqs from stEnv
somnathb1 Oct 18, 2024
460a971
Add flat request hash and engine api sidecar
somnathb1 Oct 18, 2024
bcffdd5
Add exec spec tests back
somnathb1 Oct 18, 2024
22a297b
Change FlatRequests to slice rather than ptr
somnathb1 Oct 18, 2024
4969caf
Merge branch 'som/flat_requests' into som/pectra4_engine_api
somnathb1 Oct 18, 2024
8faeab7
Merge branch 'main' into som/remove_req_from_body
somnathb1 Oct 18, 2024
d374c62
Merge branch 'main' into som/rename_req_root
somnathb1 Oct 18, 2024
495debd
Merge branch 'som/rename_req_root' into som/remove_req_from_body
somnathb1 Oct 18, 2024
8c183cd
Merge branch 'som/remove_req_from_body' into som/pectra4_engine_api
somnathb1 Oct 18, 2024
1991a12
Modify Flat reqs a bit
somnathb1 Oct 20, 2024
8d6ea72
Remove rlp encoding methods from deposit req
somnathb1 Oct 20, 2024
3e369ad
Use FlatRequest type for Deposit requests
somnathb1 Oct 20, 2024
0826438
Remove request tests
somnathb1 Oct 22, 2024
ef0276c
Update AuthBaseCost
somnathb1 Oct 22, 2024
c2fe612
Merge branch 'main' into som/remove_req_from_body
somnathb1 Oct 22, 2024
ff5581b
Merge branch 'som/remove_req_from_body' into som/pectra4_engine_api
somnathb1 Oct 22, 2024
2ceb3af
Remove depoist req RLP encode
somnathb1 Oct 22, 2024
dd73bde
Update 7702 checks
somnathb1 Oct 22, 2024
2aa25cc
Re-enable all spec tests
somnathb1 Oct 22, 2024
2e6c077
Merge branch 'som/pectra4_engine_api' into som/remove_deposit_req
somnathb1 Oct 22, 2024
6fc953b
Merge branch 'main' into som/remove_deposit_req
somnathb1 Oct 23, 2024
4a2b481
Merge branch 'main' into som/remove_deposit_req
somnathb1 Oct 23, 2024
93e8829
Remove unnecessary comment
somnathb1 Oct 23, 2024
81f92bd
Merge branch 'som/remove_deposit_req' into som/fix_7702_pectra4
somnathb1 Oct 23, 2024
3fe6632
Merge branch 'main' into som/fix_7702_pectra4
somnathb1 Oct 24, 2024
4026c8b
Fix lint
somnathb1 Oct 24, 2024
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
5 changes: 2 additions & 3 deletions consensus/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
for _, rec := range receipts {
allLogs = append(allLogs, rec.Logs...)
}
depositReqs, err := types.ParseDepositLogs(allLogs, config.DepositContract)
depositReqs, err := misc.ParseDepositLogs(allLogs, config.DepositContract)
if err != nil {
return nil, nil, nil, fmt.Errorf("error: could not parse requests logs: %v", err)
}
rs = append(rs, types.FlatRequest{Type: types.DepositRequestType, RequestData: depositReqs.Encode()})
rs = append(rs, *depositReqs)
withdrawalReq := misc.DequeueWithdrawalRequests7002(syscall)
rs = append(rs, *withdrawalReq)
consolidations := misc.DequeueConsolidationRequests7251(syscall)
Expand All @@ -207,7 +207,6 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
return nil, nil, nil, fmt.Errorf("error: invalid requests root hash in header, expected: %v, got :%v", header.RequestsHash, rh)
}
}

}

return txs, receipts, rs, nil
Expand Down
85 changes: 85 additions & 0 deletions consensus/misc/eip6110.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.

package misc

import (
"fmt"

libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon/accounts/abi"
"github.com/erigontech/erigon/core/types"
)

const (
BLSPubKeyLen = 48
WithdrawalCredentialsLen = 32 // withdrawalCredentials size
BLSSigLen = 96 // signature size
)

var (
// DepositABI is an ABI instance of beacon chain deposit events.
DepositABI = abi.ABI{Events: map[string]abi.Event{"DepositEvent": depositEvent}}
bytesT, _ = abi.NewType("bytes", "", nil)
depositEvent = abi.NewEvent("DepositEvent", "DepositEvent", false, abi.Arguments{
{Name: "pubkey", Type: bytesT, Indexed: false},
{Name: "withdrawal_credentials", Type: bytesT, Indexed: false},
{Name: "amount", Type: bytesT, Indexed: false},
{Name: "signature", Type: bytesT, Indexed: false},
{Name: "index", Type: bytesT, Indexed: false}},
)
)

// field type overrides for abi upacking
type depositUnpacking struct {
Pubkey []byte
WithdrawalCredentials []byte
Amount []byte
Signature []byte
Index []byte
}

// unpackDepositLog unpacks a serialized DepositEvent.
func unpackDepositLog(data []byte) ([]byte, error) {
var du depositUnpacking
if err := DepositABI.UnpackIntoInterface(&du, "DepositEvent", data); err != nil {
return nil, err
}
reqData := make([]byte, 0, types.DepositRequestDataLen)
reqData = append(reqData, du.Pubkey...)
reqData = append(reqData, du.WithdrawalCredentials...)
reqData = append(reqData, du.Amount...)
reqData = append(reqData, du.Signature...)
reqData = append(reqData, du.Index...)

return reqData, nil
}

// ParseDepositLogs extracts the EIP-6110 deposit values from logs emitted by
// BeaconDepositContract and returns a FlatRequest object ptr
func ParseDepositLogs(logs []*types.Log, depositContractAddress libcommon.Address) (*types.FlatRequest, error) {
reqData := make([]byte, 0, len(logs)*types.DepositRequestDataLen)
for _, log := range logs {
if log.Address == depositContractAddress {
d, err := unpackDepositLog(log.Data)
if err != nil {
return nil, fmt.Errorf("unable to parse deposit data: %v", err)
}
reqData = append(reqData, d...)
}
}
return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil
}
6 changes: 5 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype
}

// 7. set authority code
st.state.SetCode(authority, types.AddressToDelegation(auth.Address))
if auth.Address == (libcommon.Address{}) {
st.state.SetCode(authority, nil)
} else {
st.state.SetCode(authority, types.AddressToDelegation(auth.Address))
}

// 8. increase the nonce of authority
st.state.SetNonce(authority, authorityNonce+1)
Expand Down
10 changes: 10 additions & 0 deletions core/types/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ func (ath *Authorization) RecoverSigner(data *bytes.Buffer, b []byte) (*libcommo
copy(sig[32-len(r):32], r)
copy(sig[64-len(s):64], s)

if ath.Nonce == 1<<64-1 {
return nil, errors.New("Failed assertion: auth.nonce < 2**64 - 1")
}
if _, overflow := ath.ChainID.Uint64WithOverflow(); overflow {
return nil, fmt.Errorf("Failed assertion: auth.chain_id < 2**64")
}
if ath.V.GtUint64(1 << 8) {
return nil, fmt.Errorf("Failed assertion: auth.y_parity < 2**8")
}

if ath.V.Eq(u256.Num0) || ath.V.Eq(u256.Num1) {
sig[64] = byte(ath.V.Uint64())
} else {
Expand Down
195 changes: 0 additions & 195 deletions core/types/deposit_request.go

This file was deleted.

2 changes: 2 additions & 0 deletions core/types/eip7685_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const ConsolidationRequestDataLen = 116 // addr + sourcePubkey + targetPubkey

var KnownRequestTypes = []byte{DepositRequestType, WithdrawalRequestType, ConsolidationRequestType}

// FlatRequest carries serialized (flat) request data from any known Request type
// The RequestData slice can contain collated data for more than one request of the same type
type FlatRequest struct {
Type byte
RequestData []byte
Expand Down
Loading
Loading