1
0
Fork 0
forked from forks/go-ethereum

ethclient: allow passing AuthorizationList to calls (#31198)

This PR adds the `AuthorizationList` field to the `CallMsg` interface to support `eth_call`
and `eth_estimateGas` of set-code transactions.

---------

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
This commit is contained in:
colin 2025-04-24 03:01:03 +08:00 committed by GitHub
parent 1591d165c4
commit 846c14e21f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 62 additions and 3 deletions

View file

@ -4099,7 +4099,7 @@ func TestEIP7702(t *testing.T) {
// The way the auths are combined, it becomes
// 1. tx -> addr1 which is delegated to 0xaaaa
// 2. addr1:0xaaaa calls into addr2:0xbbbb
// 3. addr2:0xbbbb writes to storage
// 3. addr2:0xbbbb writes to storage
auth1, _ := types.SignSetCode(key1, types.SetCodeAuthorization{
ChainID: *uint256.MustFromBig(gspec.Config.ChainID),
Address: aa,

View file

@ -255,7 +255,8 @@ func TestStateProcessorErrors(t *testing.T) {
},
want: "could not apply tx 0 [0xc18d10f4c809dbdfa1a074c3300de9bc4b7f16a20f0ec667f6f67312b71b956a]: EIP-7702 transaction with empty auth list (sender 0x71562b71999873DB5b286dF957af199Ec94617F7)",
},
// ErrSetCodeTxCreate cannot be tested: it is impossible to create a SetCode-tx with nil `to`.
// ErrSetCodeTxCreate cannot be tested here: it is impossible to create a SetCode-tx with nil `to`.
// The EstimateGas API tests test this case.
} {
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
_, err := blockchain.InsertChain(types.Blocks{block})

View file

@ -754,6 +754,9 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
if msg.BlobHashes != nil {
arg["blobVersionedHashes"] = msg.BlobHashes
}
if msg.AuthorizationList != nil {
arg["authorizationList"] = msg.AuthorizationList
}
return arg
}

View file

@ -251,6 +251,9 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
if msg.BlobHashes != nil {
arg["blobVersionedHashes"] = msg.BlobHashes
}
if msg.AuthorizationList != nil {
arg["authorizationList"] = msg.AuthorizationList
}
return arg
}

View file

@ -156,6 +156,9 @@ type CallMsg struct {
// For BlobTxType
BlobGasFeeCap *big.Int
BlobHashes []common.Hash
// For SetCodeTxType
AuthorizationList []types.SetCodeAuthorization
}
// A ContractCaller provides contract calls, essentially transactions that are executed by

View file

@ -668,6 +668,11 @@ func TestEstimateGas(t *testing.T) {
b.SetPoS()
}))
setCodeAuthorization, _ := types.SignSetCode(accounts[0].key, types.SetCodeAuthorization{
Address: accounts[0].addr,
Nonce: uint64(genBlocks + 1),
})
var testSuite = []struct {
blockNumber rpc.BlockNumber
call TransactionArgs
@ -846,6 +851,50 @@ func TestEstimateGas(t *testing.T) {
},
want: 21000,
},
// Should be able to estimate SetCodeTx.
{
blockNumber: rpc.LatestBlockNumber,
call: TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(0)),
AuthorizationList: []types.SetCodeAuthorization{setCodeAuthorization},
},
want: 46000,
},
// Should retrieve the code of 0xef0001 || accounts[0].addr and return an invalid opcode error.
{
blockNumber: rpc.LatestBlockNumber,
call: TransactionArgs{
From: &accounts[0].addr,
To: &accounts[0].addr,
Value: (*hexutil.Big)(big.NewInt(0)),
AuthorizationList: []types.SetCodeAuthorization{setCodeAuthorization},
},
expectErr: errors.New("invalid opcode: opcode 0xef not defined"),
},
// SetCodeTx with empty authorization list should fail.
{
blockNumber: rpc.LatestBlockNumber,
call: TransactionArgs{
From: &accounts[0].addr,
To: &common.Address{},
Value: (*hexutil.Big)(big.NewInt(0)),
AuthorizationList: []types.SetCodeAuthorization{},
},
expectErr: core.ErrEmptyAuthList,
},
// SetCodeTx with nil `to` should fail.
{
blockNumber: rpc.LatestBlockNumber,
call: TransactionArgs{
From: &accounts[0].addr,
To: nil,
Value: (*hexutil.Big)(big.NewInt(0)),
AuthorizationList: []types.SetCodeAuthorization{setCodeAuthorization},
},
expectErr: core.ErrSetCodeTxCreate,
},
}
for i, tc := range testSuite {
result, err := api.EstimateGas(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides)
@ -855,7 +904,7 @@ func TestEstimateGas(t *testing.T) {
continue
}
if !errors.Is(err, tc.expectErr) {
if !reflect.DeepEqual(err, tc.expectErr) {
if err.Error() != tc.expectErr.Error() {
t.Errorf("test %d: error mismatch, want %v, have %v", i, tc.expectErr, err)
}
}