Skip to content

Commit fadf84a

Browse files
holimanfjl
andauthored
internal/ethapi: default to zero address for calls (#20702)
This makes eth_call and eth_estimateGas use the zero address as sender when the "from" parameter is not supplied. Co-authored-by: Felix Lange <[email protected]>
1 parent 2a5ed1a commit fadf84a

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

internal/ethapi/api.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -764,17 +764,13 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
764764
if state == nil || err != nil {
765765
return nil, 0, false, err
766766
}
767-
// Set sender address or use a default if none specified
767+
768+
// Set sender address or use zero address if none specified.
768769
var addr common.Address
769-
if args.From == nil {
770-
if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
771-
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
772-
addr = accounts[0].Address
773-
}
774-
}
775-
} else {
770+
if args.From != nil {
776771
addr = *args.From
777772
}
773+
778774
// Override the fields of specified contracts before execution.
779775
for addr, account := range overrides {
780776
// Override account nonce.
@@ -906,17 +902,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
906902
}
907903
cap = hi
908904

909-
// Set sender address or use a default if none specified
910-
if args.From == nil {
911-
if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
912-
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
913-
args.From = &accounts[0].Address
914-
}
915-
}
916-
}
917-
// Use zero-address if none other is available
905+
// Use zero address if sender unspecified.
918906
if args.From == nil {
919-
args.From = &common.Address{}
907+
args.From = new(common.Address)
920908
}
921909
// Create a helper to check if a gas allowance results in an executable transaction
922910
executable := func(gas uint64) bool {

0 commit comments

Comments
 (0)