Skip to content

Commit 846c14e

Browse files
colinlyguos1na
andauthored
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 <[email protected]>
1 parent 1591d16 commit 846c14e

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

core/blockchain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4099,7 +4099,7 @@ func TestEIP7702(t *testing.T) {
40994099
// The way the auths are combined, it becomes
41004100
// 1. tx -> addr1 which is delegated to 0xaaaa
41014101
// 2. addr1:0xaaaa calls into addr2:0xbbbb
4102-
// 3. addr2:0xbbbb writes to storage
4102+
// 3. addr2:0xbbbb writes to storage
41034103
auth1, _ := types.SignSetCode(key1, types.SetCodeAuthorization{
41044104
ChainID: *uint256.MustFromBig(gspec.Config.ChainID),
41054105
Address: aa,

core/state_processor_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ func TestStateProcessorErrors(t *testing.T) {
255255
},
256256
want: "could not apply tx 0 [0xc18d10f4c809dbdfa1a074c3300de9bc4b7f16a20f0ec667f6f67312b71b956a]: EIP-7702 transaction with empty auth list (sender 0x71562b71999873DB5b286dF957af199Ec94617F7)",
257257
},
258-
// ErrSetCodeTxCreate cannot be tested: it is impossible to create a SetCode-tx with nil `to`.
258+
// ErrSetCodeTxCreate cannot be tested here: it is impossible to create a SetCode-tx with nil `to`.
259+
// The EstimateGas API tests test this case.
259260
} {
260261
block := GenerateBadBlock(gspec.ToBlock(), beacon.New(ethash.NewFaker()), tt.txs, gspec.Config, false)
261262
_, err := blockchain.InsertChain(types.Blocks{block})

ethclient/ethclient.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
754754
if msg.BlobHashes != nil {
755755
arg["blobVersionedHashes"] = msg.BlobHashes
756756
}
757+
if msg.AuthorizationList != nil {
758+
arg["authorizationList"] = msg.AuthorizationList
759+
}
757760
return arg
758761
}
759762

ethclient/gethclient/gethclient.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
251251
if msg.BlobHashes != nil {
252252
arg["blobVersionedHashes"] = msg.BlobHashes
253253
}
254+
if msg.AuthorizationList != nil {
255+
arg["authorizationList"] = msg.AuthorizationList
256+
}
254257
return arg
255258
}
256259

interfaces.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ type CallMsg struct {
156156
// For BlobTxType
157157
BlobGasFeeCap *big.Int
158158
BlobHashes []common.Hash
159+
160+
// For SetCodeTxType
161+
AuthorizationList []types.SetCodeAuthorization
159162
}
160163

161164
// A ContractCaller provides contract calls, essentially transactions that are executed by

internal/ethapi/api_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ func TestEstimateGas(t *testing.T) {
668668
b.SetPoS()
669669
}))
670670

671+
setCodeAuthorization, _ := types.SignSetCode(accounts[0].key, types.SetCodeAuthorization{
672+
Address: accounts[0].addr,
673+
Nonce: uint64(genBlocks + 1),
674+
})
675+
671676
var testSuite = []struct {
672677
blockNumber rpc.BlockNumber
673678
call TransactionArgs
@@ -846,6 +851,50 @@ func TestEstimateGas(t *testing.T) {
846851
},
847852
want: 21000,
848853
},
854+
// Should be able to estimate SetCodeTx.
855+
{
856+
blockNumber: rpc.LatestBlockNumber,
857+
call: TransactionArgs{
858+
From: &accounts[0].addr,
859+
To: &accounts[1].addr,
860+
Value: (*hexutil.Big)(big.NewInt(0)),
861+
AuthorizationList: []types.SetCodeAuthorization{setCodeAuthorization},
862+
},
863+
want: 46000,
864+
},
865+
// Should retrieve the code of 0xef0001 || accounts[0].addr and return an invalid opcode error.
866+
{
867+
blockNumber: rpc.LatestBlockNumber,
868+
call: TransactionArgs{
869+
From: &accounts[0].addr,
870+
To: &accounts[0].addr,
871+
Value: (*hexutil.Big)(big.NewInt(0)),
872+
AuthorizationList: []types.SetCodeAuthorization{setCodeAuthorization},
873+
},
874+
expectErr: errors.New("invalid opcode: opcode 0xef not defined"),
875+
},
876+
// SetCodeTx with empty authorization list should fail.
877+
{
878+
blockNumber: rpc.LatestBlockNumber,
879+
call: TransactionArgs{
880+
From: &accounts[0].addr,
881+
To: &common.Address{},
882+
Value: (*hexutil.Big)(big.NewInt(0)),
883+
AuthorizationList: []types.SetCodeAuthorization{},
884+
},
885+
expectErr: core.ErrEmptyAuthList,
886+
},
887+
// SetCodeTx with nil `to` should fail.
888+
{
889+
blockNumber: rpc.LatestBlockNumber,
890+
call: TransactionArgs{
891+
From: &accounts[0].addr,
892+
To: nil,
893+
Value: (*hexutil.Big)(big.NewInt(0)),
894+
AuthorizationList: []types.SetCodeAuthorization{setCodeAuthorization},
895+
},
896+
expectErr: core.ErrSetCodeTxCreate,
897+
},
849898
}
850899
for i, tc := range testSuite {
851900
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) {
855904
continue
856905
}
857906
if !errors.Is(err, tc.expectErr) {
858-
if !reflect.DeepEqual(err, tc.expectErr) {
907+
if err.Error() != tc.expectErr.Error() {
859908
t.Errorf("test %d: error mismatch, want %v, have %v", i, tc.expectErr, err)
860909
}
861910
}

0 commit comments

Comments
 (0)