mirror of https://github.com/ethereum/go-ethereum
all: implement eip-7702 set code tx (#30078)
This PR implements EIP-7702: "Set EOA account code". Specification: https://eips.ethereum.org/EIPS/eip-7702 > Add a new transaction type that adds a list of `[chain_id, address, nonce, y_parity, r, s]` authorization tuples. For each tuple, write a delegation designator `(0xef0100 ++ address)` to the signing account’s code. All code reading operations must load the code pointed to by the designator. --------- Co-authored-by: Mario Vega <marioevz@gmail.com> Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Felix Lange <fjl@twurst.com>pull/30441/head^2
parent
804d45cc2e
commit
f808d7357e
@ -0,0 +1 @@ |
||||
This test sets some EIP-7702 delegations and calls them. |
@ -0,0 +1,30 @@ |
||||
{ |
||||
"0x8a0a19589531694250d570040a0c4b74576919b8": { |
||||
"nonce": "0x00", |
||||
"balance": "0x0de0b6b3a7640000", |
||||
"code": "0x600060006000600060007310000000000000000000000000000000000000015af1600155600060006000600060007310000000000000000000000000000000000000025af16002553d600060003e600051600355", |
||||
"storage": { |
||||
"0x01": "0x0100", |
||||
"0x02": "0x0100", |
||||
"0x03": "0x0100" |
||||
} |
||||
}, |
||||
"0x000000000000000000000000000000000000aaaa": { |
||||
"nonce": "0x00", |
||||
"balance": "0x4563918244f40000", |
||||
"code": "0x58808080600173703c4b2bd70c169f5717101caee543299fc946c75af100", |
||||
"storage": {} |
||||
}, |
||||
"0x000000000000000000000000000000000000bbbb": { |
||||
"nonce": "0x00", |
||||
"balance": "0x29a2241af62c0000", |
||||
"code": "0x6042805500", |
||||
"storage": {} |
||||
}, |
||||
"0x71562b71999873DB5b286dF957af199Ec94617F7": { |
||||
"nonce": "0x00", |
||||
"balance": "0x6124fee993bc0000", |
||||
"code": "0x", |
||||
"storage": {} |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
{ |
||||
"currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", |
||||
"currentGasLimit": "71794957647893862", |
||||
"currentNumber": "1", |
||||
"currentTimestamp": "1000", |
||||
"currentRandom": "0", |
||||
"currentDifficulty": "0", |
||||
"blockHashes": {}, |
||||
"ommers": [], |
||||
"currentBaseFee": "7", |
||||
"parentUncleHash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"withdrawals": [], |
||||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000" |
||||
} |
@ -0,0 +1,62 @@ |
||||
{ |
||||
"alloc": { |
||||
"0x000000000000000000000000000000000000aaaa": { |
||||
"code": "0x58808080600173703c4b2bd70c169f5717101caee543299fc946c75af100", |
||||
"balance": "0x4563918244f40000" |
||||
}, |
||||
"0x000000000000000000000000000000000000bbbb": { |
||||
"code": "0x6042805500", |
||||
"balance": "0x29a2241af62c0000" |
||||
}, |
||||
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { |
||||
"balance": "0x2bf52" |
||||
}, |
||||
"0x703c4b2bd70c169f5717101caee543299fc946c7": { |
||||
"code": "0xef0100000000000000000000000000000000000000bbbb", |
||||
"storage": { |
||||
"0x0000000000000000000000000000000000000000000000000000000000000042": "0x0000000000000000000000000000000000000000000000000000000000000042" |
||||
}, |
||||
"balance": "0x1", |
||||
"nonce": "0x1" |
||||
}, |
||||
"0x71562b71999873db5b286df957af199ec94617f7": { |
||||
"code": "0xef0100000000000000000000000000000000000000aaaa", |
||||
"balance": "0x6124fee993afa30e", |
||||
"nonce": "0x2" |
||||
}, |
||||
"0x8a0a19589531694250d570040a0c4b74576919b8": { |
||||
"code": "0x600060006000600060007310000000000000000000000000000000000000015af1600155600060006000600060007310000000000000000000000000000000000000025af16002553d600060003e600051600355", |
||||
"storage": { |
||||
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000100", |
||||
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x0000000000000000000000000000000000000000000000000000000000000100", |
||||
"0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000100" |
||||
}, |
||||
"balance": "0xde0b6b3a7640000" |
||||
} |
||||
}, |
||||
"result": { |
||||
"stateRoot": "0x9fdcacd4510e93c4488e537dc51578b5c6d505771db64a2610036eeb4be7b26f", |
||||
"txRoot": "0x5d13a0b074e80388dc754da92b22922313a63417b3e25a10f324935e09697a53", |
||||
"receiptsRoot": "0x504c5d86c34391f70d210e6c482615b391db4bdb9f43479366399d9c5599850a", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","receipts": [{ |
||||
"type": "0x4", |
||||
"root": "0x", |
||||
"status": "0x1", |
||||
"cumulativeGasUsed": "0x15fa9", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","logs": null,"transactionHash": "0x0417aab7c1d8a3989190c3167c132876ce9b8afd99262c5a0f9d06802de3d7ef", |
||||
"contractAddress": "0x0000000000000000000000000000000000000000", |
||||
"gasUsed": "0x15fa9", |
||||
"effectiveGasPrice": null, |
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"transactionIndex": "0x0" |
||||
} |
||||
], |
||||
"currentDifficulty": null, |
||||
"gasUsed": "0x15fa9", |
||||
"currentBaseFee": "0x7", |
||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", |
||||
"requests": [] |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
[ |
||||
{ |
||||
"type": "0x4", |
||||
"chainId": "0x1", |
||||
"nonce": "0x0", |
||||
"to": "0x71562b71999873db5b286df957af199ec94617f7", |
||||
"gas": "0x7a120", |
||||
"gasPrice": null, |
||||
"maxPriorityFeePerGas": "0x2", |
||||
"maxFeePerGas": "0x12a05f200", |
||||
"value": "0x0", |
||||
"input": "0x", |
||||
"accessList": [], |
||||
"authorizationList": [ |
||||
{ |
||||
"chainId": "0x1", |
||||
"address": "0x000000000000000000000000000000000000aaaa", |
||||
"nonce": "0x1", |
||||
"v": "0x1", |
||||
"r": "0xf7e3e597fc097e71ed6c26b14b25e5395bc8510d58b9136af439e12715f2d721", |
||||
"s": "0x6cf7c3d7939bfdb784373effc0ebb0bd7549691a513f395e3cdabf8602724987" |
||||
}, |
||||
{ |
||||
"chainId": "0x0", |
||||
"address": "0x000000000000000000000000000000000000bbbb", |
||||
"nonce": "0x0", |
||||
"v": "0x1", |
||||
"r": "0x5011890f198f0356a887b0779bde5afa1ed04e6acb1e3f37f8f18c7b6f521b98", |
||||
"s": "0x56c3fa3456b103f3ef4a0acb4b647b9cab9ec4bc68fbcdf1e10b49fb2bcbcf61" |
||||
} |
||||
], |
||||
"secretKey": "0xb71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291", |
||||
"v": "0x0", |
||||
"r": "0x0", |
||||
"s": "0x0" |
||||
} |
||||
] |
@ -0,0 +1,75 @@ |
||||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package types |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"errors" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
"github.com/holiman/uint256" |
||||
) |
||||
|
||||
var _ = (*authorizationMarshaling)(nil) |
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (a Authorization) MarshalJSON() ([]byte, error) { |
||||
type Authorization struct { |
||||
ChainID hexutil.Uint64 `json:"chainId" gencodec:"required"` |
||||
Address common.Address `json:"address" gencodec:"required"` |
||||
Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"` |
||||
V hexutil.Uint64 `json:"v" gencodec:"required"` |
||||
R uint256.Int `json:"r" gencodec:"required"` |
||||
S uint256.Int `json:"s" gencodec:"required"` |
||||
} |
||||
var enc Authorization |
||||
enc.ChainID = hexutil.Uint64(a.ChainID) |
||||
enc.Address = a.Address |
||||
enc.Nonce = hexutil.Uint64(a.Nonce) |
||||
enc.V = hexutil.Uint64(a.V) |
||||
enc.R = a.R |
||||
enc.S = a.S |
||||
return json.Marshal(&enc) |
||||
} |
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (a *Authorization) UnmarshalJSON(input []byte) error { |
||||
type Authorization struct { |
||||
ChainID *hexutil.Uint64 `json:"chainId" gencodec:"required"` |
||||
Address *common.Address `json:"address" gencodec:"required"` |
||||
Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` |
||||
V *hexutil.Uint64 `json:"v" gencodec:"required"` |
||||
R *uint256.Int `json:"r" gencodec:"required"` |
||||
S *uint256.Int `json:"s" gencodec:"required"` |
||||
} |
||||
var dec Authorization |
||||
if err := json.Unmarshal(input, &dec); err != nil { |
||||
return err |
||||
} |
||||
if dec.ChainID == nil { |
||||
return errors.New("missing required field 'chainId' for Authorization") |
||||
} |
||||
a.ChainID = uint64(*dec.ChainID) |
||||
if dec.Address == nil { |
||||
return errors.New("missing required field 'address' for Authorization") |
||||
} |
||||
a.Address = *dec.Address |
||||
if dec.Nonce == nil { |
||||
return errors.New("missing required field 'nonce' for Authorization") |
||||
} |
||||
a.Nonce = uint64(*dec.Nonce) |
||||
if dec.V == nil { |
||||
return errors.New("missing required field 'v' for Authorization") |
||||
} |
||||
a.V = uint8(*dec.V) |
||||
if dec.R == nil { |
||||
return errors.New("missing required field 'r' for Authorization") |
||||
} |
||||
a.R = *dec.R |
||||
if dec.S == nil { |
||||
return errors.New("missing required field 's' for Authorization") |
||||
} |
||||
a.S = *dec.S |
||||
return nil |
||||
} |
@ -0,0 +1,226 @@ |
||||
// Copyright 2024 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library 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.
|
||||
//
|
||||
// The go-ethereum library 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 the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package types |
||||
|
||||
import ( |
||||
"bytes" |
||||
"crypto/ecdsa" |
||||
"errors" |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/hexutil" |
||||
"github.com/ethereum/go-ethereum/crypto" |
||||
"github.com/ethereum/go-ethereum/rlp" |
||||
"github.com/holiman/uint256" |
||||
) |
||||
|
||||
// DelegationPrefix is used by code to denote the account is delegating to
|
||||
// another account.
|
||||
var DelegationPrefix = []byte{0xef, 0x01, 0x00} |
||||
|
||||
// ParseDelegation tries to parse the address from a delegation slice.
|
||||
func ParseDelegation(b []byte) (common.Address, bool) { |
||||
if len(b) != 23 || !bytes.HasPrefix(b, DelegationPrefix) { |
||||
return common.Address{}, false |
||||
} |
||||
return common.BytesToAddress(b[len(DelegationPrefix):]), true |
||||
} |
||||
|
||||
// AddressToDelegation adds the delegation prefix to the specified address.
|
||||
func AddressToDelegation(addr common.Address) []byte { |
||||
return append(DelegationPrefix, addr.Bytes()...) |
||||
} |
||||
|
||||
// SetCodeTx implements the EIP-7702 transaction type which temporarily installs
|
||||
// the code at the signer's address.
|
||||
type SetCodeTx struct { |
||||
ChainID uint64 |
||||
Nonce uint64 |
||||
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
|
||||
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
|
||||
Gas uint64 |
||||
To common.Address |
||||
Value *uint256.Int |
||||
Data []byte |
||||
AccessList AccessList |
||||
AuthList []Authorization |
||||
|
||||
// Signature values
|
||||
V *uint256.Int `json:"v" gencodec:"required"` |
||||
R *uint256.Int `json:"r" gencodec:"required"` |
||||
S *uint256.Int `json:"s" gencodec:"required"` |
||||
} |
||||
|
||||
//go:generate go run github.com/fjl/gencodec -type Authorization -field-override authorizationMarshaling -out gen_authorization.go
|
||||
|
||||
// Authorization is an authorization from an account to deploy code at its address.
|
||||
type Authorization struct { |
||||
ChainID uint64 `json:"chainId" gencodec:"required"` |
||||
Address common.Address `json:"address" gencodec:"required"` |
||||
Nonce uint64 `json:"nonce" gencodec:"required"` |
||||
V uint8 `json:"v" gencodec:"required"` |
||||
R uint256.Int `json:"r" gencodec:"required"` |
||||
S uint256.Int `json:"s" gencodec:"required"` |
||||
} |
||||
|
||||
// field type overrides for gencodec
|
||||
type authorizationMarshaling struct { |
||||
ChainID hexutil.Uint64 |
||||
Nonce hexutil.Uint64 |
||||
V hexutil.Uint64 |
||||
} |
||||
|
||||
// SignAuth signs the provided authorization.
|
||||
func SignAuth(auth Authorization, prv *ecdsa.PrivateKey) (Authorization, error) { |
||||
sighash := auth.sigHash() |
||||
sig, err := crypto.Sign(sighash[:], prv) |
||||
if err != nil { |
||||
return Authorization{}, err |
||||
} |
||||
return auth.withSignature(sig), nil |
||||
} |
||||
|
||||
// withSignature updates the signature of an Authorization to be equal the
|
||||
// decoded signature provided in sig.
|
||||
func (a *Authorization) withSignature(sig []byte) Authorization { |
||||
r, s, _ := decodeSignature(sig) |
||||
return Authorization{ |
||||
ChainID: a.ChainID, |
||||
Address: a.Address, |
||||
Nonce: a.Nonce, |
||||
V: sig[64], |
||||
R: *uint256.MustFromBig(r), |
||||
S: *uint256.MustFromBig(s), |
||||
} |
||||
} |
||||
|
||||
func (a *Authorization) sigHash() common.Hash { |
||||
return prefixedRlpHash(0x05, []any{ |
||||
a.ChainID, |
||||
a.Address, |
||||
a.Nonce, |
||||
}) |
||||
} |
||||
|
||||
// Authority recovers the the authorizing account of an authorization.
|
||||
func (a *Authorization) Authority() (common.Address, error) { |
||||
sighash := a.sigHash() |
||||
if !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) { |
||||
return common.Address{}, ErrInvalidSig |
||||
} |
||||
// encode the signature in uncompressed format
|
||||
var sig [crypto.SignatureLength]byte |
||||
a.R.WriteToSlice(sig[:32]) |
||||
a.S.WriteToSlice(sig[32:64]) |
||||
sig[64] = a.V |
||||
// recover the public key from the signature
|
||||
pub, err := crypto.Ecrecover(sighash[:], sig[:]) |
||||
if err != nil { |
||||
return common.Address{}, err |
||||
} |
||||
if len(pub) == 0 || pub[0] != 4 { |
||||
return common.Address{}, errors.New("invalid public key") |
||||
} |
||||
var addr common.Address |
||||
copy(addr[:], crypto.Keccak256(pub[1:])[12:]) |
||||
return addr, nil |
||||
} |
||||
|
||||
// copy creates a deep copy of the transaction data and initializes all fields.
|
||||
func (tx *SetCodeTx) copy() TxData { |
||||
cpy := &SetCodeTx{ |
||||
Nonce: tx.Nonce, |
||||
To: tx.To, |
||||
Data: common.CopyBytes(tx.Data), |
||||
Gas: tx.Gas, |
||||
// These are copied below.
|
||||
AccessList: make(AccessList, len(tx.AccessList)), |
||||
AuthList: make([]Authorization, len(tx.AuthList)), |
||||
Value: new(uint256.Int), |
||||
ChainID: tx.ChainID, |
||||
GasTipCap: new(uint256.Int), |
||||
GasFeeCap: new(uint256.Int), |
||||
V: new(uint256.Int), |
||||
R: new(uint256.Int), |
||||
S: new(uint256.Int), |
||||
} |
||||
copy(cpy.AccessList, tx.AccessList) |
||||
copy(cpy.AuthList, tx.AuthList) |
||||
if tx.Value != nil { |
||||
cpy.Value.Set(tx.Value) |
||||
} |
||||
if tx.GasTipCap != nil { |
||||
cpy.GasTipCap.Set(tx.GasTipCap) |
||||
} |
||||
if tx.GasFeeCap != nil { |
||||
cpy.GasFeeCap.Set(tx.GasFeeCap) |
||||
} |
||||
if tx.V != nil { |
||||
cpy.V.Set(tx.V) |
||||
} |
||||
if tx.R != nil { |
||||
cpy.R.Set(tx.R) |
||||
} |
||||
if tx.S != nil { |
||||
cpy.S.Set(tx.S) |
||||
} |
||||
return cpy |
||||
} |
||||
|
||||
// accessors for innerTx.
|
||||
func (tx *SetCodeTx) txType() byte { return SetCodeTxType } |
||||
func (tx *SetCodeTx) chainID() *big.Int { return big.NewInt(int64(tx.ChainID)) } |
||||
func (tx *SetCodeTx) accessList() AccessList { return tx.AccessList } |
||||
func (tx *SetCodeTx) data() []byte { return tx.Data } |
||||
func (tx *SetCodeTx) gas() uint64 { return tx.Gas } |
||||
func (tx *SetCodeTx) gasFeeCap() *big.Int { return tx.GasFeeCap.ToBig() } |
||||
func (tx *SetCodeTx) gasTipCap() *big.Int { return tx.GasTipCap.ToBig() } |
||||
func (tx *SetCodeTx) gasPrice() *big.Int { return tx.GasFeeCap.ToBig() } |
||||
func (tx *SetCodeTx) value() *big.Int { return tx.Value.ToBig() } |
||||
func (tx *SetCodeTx) nonce() uint64 { return tx.Nonce } |
||||
func (tx *SetCodeTx) to() *common.Address { tmp := tx.To; return &tmp } |
||||
|
||||
func (tx *SetCodeTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { |
||||
if baseFee == nil { |
||||
return dst.Set(tx.GasFeeCap.ToBig()) |
||||
} |
||||
tip := dst.Sub(tx.GasFeeCap.ToBig(), baseFee) |
||||
if tip.Cmp(tx.GasTipCap.ToBig()) > 0 { |
||||
tip.Set(tx.GasTipCap.ToBig()) |
||||
} |
||||
return tip.Add(tip, baseFee) |
||||
} |
||||
|
||||
func (tx *SetCodeTx) rawSignatureValues() (v, r, s *big.Int) { |
||||
return tx.V.ToBig(), tx.R.ToBig(), tx.S.ToBig() |
||||
} |
||||
|
||||
func (tx *SetCodeTx) setSignatureValues(chainID, v, r, s *big.Int) { |
||||
tx.ChainID = chainID.Uint64() |
||||
tx.V.SetFromBig(v) |
||||
tx.R.SetFromBig(r) |
||||
tx.S.SetFromBig(s) |
||||
} |
||||
|
||||
func (tx *SetCodeTx) encode(b *bytes.Buffer) error { |
||||
return rlp.Encode(b, tx) |
||||
} |
||||
|
||||
func (tx *SetCodeTx) decode(input []byte) error { |
||||
return rlp.DecodeBytes(input, tx) |
||||
} |
@ -0,0 +1,70 @@ |
||||
// Copyright 2024 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library 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.
|
||||
//
|
||||
// The go-ethereum library 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 the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package types |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
) |
||||
|
||||
// TestParseDelegation tests a few possible delegation designator values and
|
||||
// ensures they are parsed correctly.
|
||||
func TestParseDelegation(t *testing.T) { |
||||
addr := common.Address{0x42} |
||||
for _, tt := range []struct { |
||||
val []byte |
||||
want *common.Address |
||||
}{ |
||||
{ // simple correct delegation
|
||||
val: append(DelegationPrefix, addr.Bytes()...), |
||||
want: &addr, |
||||
}, |
||||
{ // wrong address size
|
||||
val: append(DelegationPrefix, addr.Bytes()[0:19]...), |
||||
}, |
||||
{ // short address
|
||||
val: append(DelegationPrefix, 0x42), |
||||
}, |
||||
{ // long address
|
||||
val: append(append(DelegationPrefix, addr.Bytes()...), 0x42), |
||||
}, |
||||
{ // wrong prefix size
|
||||
val: append(DelegationPrefix[:2], addr.Bytes()...), |
||||
}, |
||||
{ // wrong prefix
|
||||
val: append([]byte{0xef, 0x01, 0x01}, addr.Bytes()...), |
||||
}, |
||||
{ // wrong prefix
|
||||
val: append([]byte{0xef, 0x00, 0x00}, addr.Bytes()...), |
||||
}, |
||||
{ // no prefix
|
||||
val: addr.Bytes(), |
||||
}, |
||||
{ // no address
|
||||
val: DelegationPrefix, |
||||
}, |
||||
} { |
||||
got, ok := ParseDelegation(tt.val) |
||||
if ok && tt.want == nil { |
||||
t.Fatalf("expected fail, got %s", got.Hex()) |
||||
} |
||||
if !ok && tt.want != nil { |
||||
t.Fatalf("failed to parse, want %s", tt.want.Hex()) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,82 @@ |
||||
{ |
||||
"genesis": { |
||||
"baseFeePerGas": "7", |
||||
"blobGasUsed": "0", |
||||
"difficulty": "0", |
||||
"excessBlobGas": "36306944", |
||||
"extraData": "0xd983010e00846765746888676f312e32312e308664617277696e", |
||||
"gasLimit": "15639172", |
||||
"hash": "0xc682259fda061bb9ce8ccb491d5b2d436cb73daf04e1025dd116d045ce4ad28c", |
||||
"miner": "0x0000000000000000000000000000000000000000", |
||||
"mixHash": "0xae1a5ba939a4c9ac38aabeff361169fb55a6fc2c9511457e0be6eff9514faec0", |
||||
"nonce": "0x0000000000000000", |
||||
"number": "315", |
||||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a", |
||||
"timestamp": "1709626771", |
||||
"withdrawals": [], |
||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"alloc": { |
||||
"0x0000000000000000000000000000000000000000": { |
||||
"balance": "0x272e0528" |
||||
}, |
||||
"0x000000000000000000000000000000000000aaaa": { |
||||
"code": "0x6000600060006000600173703c4b2bd70c169f5717101caee543299fc946c75af1", |
||||
"balance": "0x0" |
||||
}, |
||||
"0x000000000000000000000000000000000000bbbb": { |
||||
"code": "0x6042604255", |
||||
"balance": "0x0" |
||||
}, |
||||
"0x703c4b2bd70c169f5717101caee543299fc946c7": { |
||||
"balance": "0xde0b6b3a7640000" |
||||
}, |
||||
"0x71562b71999873db5b286df957af199ec94617f7": { |
||||
"balance": "0xde0b6b3a7640000" |
||||
} |
||||
}, |
||||
"config": { |
||||
"chainId": 1337, |
||||
"homesteadBlock": 0, |
||||
"eip150Block": 0, |
||||
"eip155Block": 0, |
||||
"eip158Block": 0, |
||||
"byzantiumBlock": 0, |
||||
"constantinopleBlock": 0, |
||||
"petersburgBlock": 0, |
||||
"istanbulBlock": 0, |
||||
"muirGlacierBlock": 0, |
||||
"berlinBlock": 0, |
||||
"londonBlock": 0, |
||||
"arrowGlacierBlock": 0, |
||||
"grayGlacierBlock": 0, |
||||
"shanghaiTime": 0, |
||||
"cancunTime": 0, |
||||
"pragueTime": 0, |
||||
"terminalTotalDifficulty": 0 |
||||
} |
||||
}, |
||||
"context": { |
||||
"number": "316", |
||||
"difficulty": "0", |
||||
"timestamp": "1709626785", |
||||
"gasLimit": "15654443", |
||||
"miner": "0x0000000000000000000000000000000000000000", |
||||
"baseFeePerGas": "7" |
||||
}, |
||||
"input": "04f90126820539800285012a05f2008307a1209471562b71999873db5b286df957af199ec94617f78080c0f8baf85c82053994000000000000000000000000000000000000aaaa0101a07ed17af7d2d2b9ba7d797a202125bf505b9a0f962a67b3b61b56783d8faf7461a001b73b6e586edc706dce6c074eaec28692fa6359fb3446a2442f36777e1c0669f85a8094000000000000000000000000000000000000bbbb8001a05011890f198f0356a887b0779bde5afa1ed04e6acb1e3f37f8f18c7b6f521b98a056c3fa3456b103f3ef4a0acb4b647b9cab9ec4bc68fbcdf1e10b49fb2bcbcf6101a0167b0ecfc343a497095c22ee4270d3cc3b971cc3599fc73bbff727e0d2ed432da01c003c72306807492bf1150e39b2f79da23b49a4e83eb6e9209ae30d3572368f", |
||||
"result": { |
||||
"0x0000000000000000000000000000000000000000": { |
||||
"balance": "0x272e0528" |
||||
}, |
||||
"0x703c4b2bd70c169f5717101caee543299fc946c7": { |
||||
"balance": "0xde0b6b3a7640000", |
||||
"storage": { |
||||
"0x0000000000000000000000000000000000000000000000000000000000000042": "0x0000000000000000000000000000000000000000000000000000000000000000" |
||||
} |
||||
}, |
||||
"0x71562b71999873db5b286df957af199ec94617f7": { |
||||
"balance": "0xde0b6b3a7640000" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,74 @@ |
||||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package tests |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"errors" |
||||
"math/big" |
||||
|
||||
"github.com/ethereum/go-ethereum/common" |
||||
"github.com/ethereum/go-ethereum/common/math" |
||||
) |
||||
|
||||
var _ = (*stAuthorizationMarshaling)(nil) |
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (s stAuthorization) MarshalJSON() ([]byte, error) { |
||||
type stAuthorization struct { |
||||
ChainID math.HexOrDecimal64 |
||||
Address common.Address `json:"address" gencodec:"required"` |
||||
Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"` |
||||
V math.HexOrDecimal64 `json:"v" gencodec:"required"` |
||||
R *math.HexOrDecimal256 `json:"r" gencodec:"required"` |
||||
S *math.HexOrDecimal256 `json:"s" gencodec:"required"` |
||||
} |
||||
var enc stAuthorization |
||||
enc.ChainID = math.HexOrDecimal64(s.ChainID) |
||||
enc.Address = s.Address |
||||
enc.Nonce = math.HexOrDecimal64(s.Nonce) |
||||
enc.V = math.HexOrDecimal64(s.V) |
||||
enc.R = (*math.HexOrDecimal256)(s.R) |
||||
enc.S = (*math.HexOrDecimal256)(s.S) |
||||
return json.Marshal(&enc) |
||||
} |
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (s *stAuthorization) UnmarshalJSON(input []byte) error { |
||||
type stAuthorization struct { |
||||
ChainID *math.HexOrDecimal64 |
||||
Address *common.Address `json:"address" gencodec:"required"` |
||||
Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"` |
||||
V *math.HexOrDecimal64 `json:"v" gencodec:"required"` |
||||
R *math.HexOrDecimal256 `json:"r" gencodec:"required"` |
||||
S *math.HexOrDecimal256 `json:"s" gencodec:"required"` |
||||
} |
||||
var dec stAuthorization |
||||
if err := json.Unmarshal(input, &dec); err != nil { |
||||
return err |
||||
} |
||||
if dec.ChainID != nil { |
||||
s.ChainID = uint64(*dec.ChainID) |
||||
} |
||||
if dec.Address == nil { |
||||
return errors.New("missing required field 'address' for stAuthorization") |
||||
} |
||||
s.Address = *dec.Address |
||||
if dec.Nonce == nil { |
||||
return errors.New("missing required field 'nonce' for stAuthorization") |
||||
} |
||||
s.Nonce = uint64(*dec.Nonce) |
||||
if dec.V == nil { |
||||
return errors.New("missing required field 'v' for stAuthorization") |
||||
} |
||||
s.V = uint8(*dec.V) |
||||
if dec.R == nil { |
||||
return errors.New("missing required field 'r' for stAuthorization") |
||||
} |
||||
s.R = (*big.Int)(dec.R) |
||||
if dec.S == nil { |
||||
return errors.New("missing required field 's' for stAuthorization") |
||||
} |
||||
s.S = (*big.Int)(dec.S) |
||||
return nil |
||||
} |
Loading…
Reference in new issue