Skip to content

Commit c4cb036

Browse files
trantienduchnholimanfjl
authored
all: refactor names & singner 7702 (#46)
* eth/tracers/logger: make structlog/json-log stack hex again (#28628) * common/hexutil: define hex wrappers for uint256.Int * eth/tracers/logger: make structlog/json-log stack hex again * common/hexutil: goimports * pick up ethereum/go-ethereum#30926 ethereum/go-ethereum#30926 * pick up ethereum/go-ethereum#30933 ethereum/go-ethereum#30933 * core/types: rename SetCodeAuthorization 'v' to 'yParity' The API spec requires the name yParity. * pick up ethereum/go-ethereum#30935 ethereum/go-ethereum#30935 * fixup! pick up ethereum/go-ethereum#30935 --------- Co-authored-by: Martin Holst Swende <[email protected]> Co-authored-by: Felix Lange <[email protected]>
1 parent 68bfda5 commit c4cb036

File tree

21 files changed

+254
-144
lines changed

21 files changed

+254
-144
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,18 @@ type callMsg struct {
801801
ethereum.CallMsg
802802
}
803803

804-
func (m callMsg) From() common.Address { return m.CallMsg.From }
805-
func (m callMsg) Nonce() uint64 { return 0 }
806-
func (m callMsg) IsFake() bool { return true }
807-
func (m callMsg) To() *common.Address { return m.CallMsg.To }
808-
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
809-
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
810-
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
811-
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
812-
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
813-
func (m callMsg) Data() []byte { return m.CallMsg.Data }
814-
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
815-
func (m callMsg) AuthList() []types.Authorization { return nil }
804+
func (m callMsg) From() common.Address { return m.CallMsg.From }
805+
func (m callMsg) Nonce() uint64 { return 0 }
806+
func (m callMsg) IsFake() bool { return true }
807+
func (m callMsg) To() *common.Address { return m.CallMsg.To }
808+
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
809+
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
810+
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
811+
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
812+
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
813+
func (m callMsg) Data() []byte { return m.CallMsg.Data }
814+
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
815+
func (m callMsg) SetCodeAuthorizations() []types.SetCodeAuthorization { return nil }
816816

817817
// FIXME: support sponsored transaction in callMsg
818818
func (m callMsg) Payer() common.Address { return m.CallMsg.From }

cmd/evm/internal/t8ntool/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func Transaction(ctx *cli.Context) error {
139139
r.Address = sender
140140
}
141141
// Check intrinsic gas
142-
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.AuthList(), tx.To() == nil,
142+
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil,
143143
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(new(big.Int))); err != nil {
144144
r.Error = err
145145
results = append(results, r)

common/hexutil/json.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ import (
2323
"math/big"
2424
"reflect"
2525
"strconv"
26+
27+
"github.com/holiman/uint256"
2628
)
2729

2830
var (
2931
bytesT = reflect.TypeOf(Bytes(nil))
3032
bigT = reflect.TypeOf((*Big)(nil))
3133
uintT = reflect.TypeOf(Uint(0))
3234
uint64T = reflect.TypeOf(Uint64(0))
35+
u256T = reflect.TypeOf((*uint256.Int)(nil))
3336
)
3437

3538
// Bytes marshals/unmarshals as a JSON string with 0x prefix.
@@ -225,6 +228,48 @@ func (b *Big) UnmarshalGraphQL(input interface{}) error {
225228
return err
226229
}
227230

231+
// U256 marshals/unmarshals as a JSON string with 0x prefix.
232+
// The zero value marshals as "0x0".
233+
type U256 uint256.Int
234+
235+
// MarshalText implements encoding.TextMarshaler
236+
func (b U256) MarshalText() ([]byte, error) {
237+
u256 := (*uint256.Int)(&b)
238+
return []byte(u256.Hex()), nil
239+
}
240+
241+
// UnmarshalJSON implements json.Unmarshaler.
242+
func (b *U256) UnmarshalJSON(input []byte) error {
243+
// The uint256.Int.UnmarshalJSON method accepts "dec", "0xhex"; we must be
244+
// more strict, hence we check string and invoke SetFromHex directly.
245+
if !isString(input) {
246+
return errNonString(u256T)
247+
}
248+
// The hex decoder needs to accept empty string ("") as '0', which uint256.Int
249+
// would reject.
250+
if len(input) == 2 {
251+
(*uint256.Int)(b).Clear()
252+
return nil
253+
}
254+
err := (*uint256.Int)(b).SetFromHex(string(input[1 : len(input)-1]))
255+
if err != nil {
256+
return &json.UnmarshalTypeError{Value: err.Error(), Type: u256T}
257+
}
258+
return nil
259+
}
260+
261+
// UnmarshalText implements encoding.TextUnmarshaler
262+
func (b *U256) UnmarshalText(input []byte) error {
263+
// The uint256.Int.UnmarshalText method accepts "dec", "0xhex"; we must be
264+
// more strict, hence we check string and invoke SetFromHex directly.
265+
return (*uint256.Int)(b).SetFromHex(string(input))
266+
}
267+
268+
// String returns the hex encoding of b.
269+
func (b *U256) String() string {
270+
return (*uint256.Int)(b).Hex()
271+
}
272+
228273
// Uint64 marshals/unmarshals as a JSON string with 0x prefix.
229274
// The zero value marshals as "0x0".
230275
type Uint64 uint64

common/hexutil/json_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"errors"
2424
"math/big"
2525
"testing"
26+
27+
"github.com/holiman/uint256"
2628
)
2729

2830
func checkError(t *testing.T, input string, got, want error) bool {
@@ -176,6 +178,64 @@ func TestUnmarshalBig(t *testing.T) {
176178
}
177179
}
178180

181+
var unmarshalU256Tests = []unmarshalTest{
182+
// invalid encoding
183+
{input: "", wantErr: errJSONEOF},
184+
{input: "null", wantErr: errNonString(u256T)},
185+
{input: "10", wantErr: errNonString(u256T)},
186+
{input: `"0"`, wantErr: wrapTypeError(ErrMissingPrefix, u256T)},
187+
{input: `"0x"`, wantErr: wrapTypeError(ErrEmptyNumber, u256T)},
188+
{input: `"0x01"`, wantErr: wrapTypeError(ErrLeadingZero, u256T)},
189+
{input: `"0xx"`, wantErr: wrapTypeError(ErrSyntax, u256T)},
190+
{input: `"0x1zz01"`, wantErr: wrapTypeError(ErrSyntax, u256T)},
191+
{
192+
input: `"0x10000000000000000000000000000000000000000000000000000000000000000"`,
193+
wantErr: wrapTypeError(ErrBig256Range, u256T),
194+
},
195+
196+
// valid encoding
197+
{input: `""`, want: big.NewInt(0)},
198+
{input: `"0x0"`, want: big.NewInt(0)},
199+
{input: `"0x2"`, want: big.NewInt(0x2)},
200+
{input: `"0x2F2"`, want: big.NewInt(0x2f2)},
201+
{input: `"0X2F2"`, want: big.NewInt(0x2f2)},
202+
{input: `"0x1122aaff"`, want: big.NewInt(0x1122aaff)},
203+
{input: `"0xbBb"`, want: big.NewInt(0xbbb)},
204+
{input: `"0xfffffffff"`, want: big.NewInt(0xfffffffff)},
205+
{
206+
input: `"0x112233445566778899aabbccddeeff"`,
207+
want: referenceBig("112233445566778899aabbccddeeff"),
208+
},
209+
{
210+
input: `"0xffffffffffffffffffffffffffffffffffff"`,
211+
want: referenceBig("ffffffffffffffffffffffffffffffffffff"),
212+
},
213+
{
214+
input: `"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"`,
215+
want: referenceBig("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
216+
},
217+
}
218+
219+
func TestUnmarshalU256(t *testing.T) {
220+
for _, test := range unmarshalU256Tests {
221+
var v U256
222+
err := json.Unmarshal([]byte(test.input), &v)
223+
if !checkError(t, test.input, err, test.wantErr) {
224+
continue
225+
}
226+
if test.want == nil {
227+
continue
228+
}
229+
want := new(uint256.Int)
230+
want.SetFromBig(test.want.(*big.Int))
231+
have := (*uint256.Int)(&v)
232+
if want.Cmp(have) != 0 {
233+
t.Errorf("input %s: value mismatch: have %x, want %x", test.input, have, want)
234+
continue
235+
}
236+
}
237+
}
238+
179239
func BenchmarkUnmarshalBig(b *testing.B) {
180240
input := []byte(`"0x123456789abcdef123456789abcdef"`)
181241
for i := 0; i < b.N; i++ {

core/blockchain_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,16 +4780,16 @@ func TestEIP7702(t *testing.T) {
47804780
// 1. tx -> addr1 which is delegated to 0xaaaa
47814781
// 2. addr1:0xaaaa calls into addr2:0xbbbb
47824782
// 3. addr2:0xbbbb writes to storage
4783-
auth1, _ := types.SignAuth(types.Authorization{
4783+
auth1, _ := types.SignSetCode(key1, types.SetCodeAuthorization{
47844784
ChainID: gspec.Config.ChainID.Uint64(),
47854785
Address: aa,
47864786
Nonce: 1,
4787-
}, key1)
4788-
auth2, _ := types.SignAuth(types.Authorization{
4787+
})
4788+
auth2, _ := types.SignSetCode(key2, types.SetCodeAuthorization{
47894789
ChainID: 0,
47904790
Address: bb,
47914791
Nonce: 0,
4792-
}, key2)
4792+
})
47934793

47944794
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
47954795
b.SetCoinbase(aa)
@@ -4800,7 +4800,7 @@ func TestEIP7702(t *testing.T) {
48004800
Gas: 500000,
48014801
GasFeeCap: uint256.MustFromBig(newGwei(5)),
48024802
GasTipCap: uint256.NewInt(2),
4803-
AuthList: []types.Authorization{auth1, auth2},
4803+
AuthList: []types.SetCodeAuthorization{auth1, auth2},
48044804
}
48054805
tx := types.MustSignNewTx(key1, signer, txdata)
48064806
b.AddTx(tx)

core/state_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestStateProcessorErrors(t *testing.T) {
9494
}), signer, key1)
9595
return tx
9696
}
97-
var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.Authorization) *types.Transaction {
97+
var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.SetCodeAuthorization) *types.Transaction {
9898
tx, err := types.SignTx(types.NewTx(&types.SetCodeTx{
9999
Nonce: nonce,
100100
GasTipCap: uint256.MustFromBig(gasTipCap),

core/state_transition.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type Message interface {
8282
IsFake() bool
8383
Data() []byte
8484
AccessList() types.AccessList
85-
AuthList() []types.Authorization
85+
SetCodeAuthorizations() []types.SetCodeAuthorization
8686

8787
// In legacy transaction, this is the same as From.
8888
// In sponsored transaction, this is the payer's
@@ -131,7 +131,7 @@ func (result *ExecutionResult) Revert() []byte {
131131
}
132132

133133
// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
134-
func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Authorization, isContractCreation, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) {
134+
func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.SetCodeAuthorization, isContractCreation, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) {
135135
// Set the starting gas for the raw transaction
136136
var gas uint64
137137
if isContractCreation && isHomestead {
@@ -397,11 +397,11 @@ func (st *StateTransition) preCheck() error {
397397
}
398398

399399
// Check that EIP-7702 authorization list signatures are well formed.
400-
if msg.AuthList() != nil {
400+
if msg.SetCodeAuthorizations() != nil {
401401
if msg.To() == nil {
402402
return fmt.Errorf("%w (sender %v)", ErrSetCodeTxCreate, msg.From())
403403
}
404-
if len(msg.AuthList()) == 0 {
404+
if len(msg.SetCodeAuthorizations()) == 0 {
405405
return fmt.Errorf("%w (sender %v)", ErrEmptyAuthList, msg.From())
406406
}
407407
}
@@ -458,7 +458,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
458458

459459
// Check clauses 4-5, subtract intrinsic gas if everything is correct
460460
if !st.evm.Config.IsSystemTransaction {
461-
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), st.msg.AuthList(), contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai)
461+
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), st.msg.SetCodeAuthorizations(), contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai)
462462
if err != nil {
463463
return nil, err
464464
}
@@ -494,8 +494,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
494494
st.state.SetNonce(msg.From(), st.state.GetNonce(msg.From())+1)
495495

496496
// Apply EIP-7702 authorizations.
497-
if msg.AuthList() != nil {
498-
for _, auth := range msg.AuthList() {
497+
if msg.SetCodeAuthorizations() != nil {
498+
for _, auth := range msg.SetCodeAuthorizations() {
499499
// Note errors are ignored, we simply skip invalid authorizations here.
500500
st.applyAuthorization(&auth)
501501
}
@@ -556,7 +556,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
556556
}
557557

558558
// validateAuthorization validates an EIP-7702 authorization against the state.
559-
func (st *StateTransition) validateAuthorization(auth *types.Authorization) (authority common.Address, err error) {
559+
func (st *StateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) {
560560
// Verify chain ID is 0 or equal to current chain ID.
561561
if auth.ChainID != 0 && st.evm.ChainConfig().ChainID.Uint64() != auth.ChainID {
562562
return authority, ErrAuthorizationWrongChainID
@@ -587,7 +587,7 @@ func (st *StateTransition) validateAuthorization(auth *types.Authorization) (aut
587587
}
588588

589589
// applyAuthorization applies an EIP-7702 code delegation to the state.
590-
func (st *StateTransition) applyAuthorization(auth *types.Authorization) error {
590+
func (st *StateTransition) applyAuthorization(auth *types.SetCodeAuthorization) error {
591591
authority, err := st.validateAuthorization(auth)
592592
if err != nil {
593593
return err

core/txpool/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
131131
}
132132
// Ensure the transaction has more gas than the bare minimum needed to cover
133133
// the transaction metadata
134-
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.AuthList(), tx.To() == nil, true, opts.Config.IsIstanbul(head.Number), opts.Config.IsShanghai(head.Number))
134+
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, true, opts.Config.IsIstanbul(head.Number), opts.Config.IsShanghai(head.Number))
135135
if err != nil {
136136
return err
137137
}

core/types/gen_authorization.go

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)