diff --git a/core/types/gen_authorization.go b/core/types/gen_authorization.go index 45409f0624..b598b64ff7 100644 --- a/core/types/gen_authorization.go +++ b/core/types/gen_authorization.go @@ -5,10 +5,10 @@ package types import ( "encoding/json" "errors" - "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/holiman/uint256" ) var _ = (*authorizationMarshaling)(nil) @@ -20,16 +20,16 @@ func (a Authorization) MarshalJSON() ([]byte, error) { Address common.Address `json:"address" gencodec:"required"` Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"` V hexutil.Uint64 `json:"v" gencodec:"required"` - R *hexutil.Big `json:"r" gencodec:"required"` - S *hexutil.Big `json:"s" 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 = (*hexutil.Big)(a.R) - enc.S = (*hexutil.Big)(a.S) + enc.R = a.R + enc.S = a.S return json.Marshal(&enc) } @@ -40,8 +40,8 @@ func (a *Authorization) UnmarshalJSON(input []byte) error { Address *common.Address `json:"address" gencodec:"required"` Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` V *hexutil.Uint64 `json:"v" gencodec:"required"` - R *hexutil.Big `json:"r" gencodec:"required"` - S *hexutil.Big `json:"s" 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 { @@ -66,10 +66,10 @@ func (a *Authorization) UnmarshalJSON(input []byte) error { if dec.R == nil { return errors.New("missing required field 'r' for Authorization") } - a.R = (*big.Int)(dec.R) + a.R = *dec.R if dec.S == nil { return errors.New("missing required field 's' for Authorization") } - a.S = (*big.Int)(dec.S) + a.S = *dec.S return nil } diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index f2e3bd7550..6e0665fa68 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -75,8 +75,8 @@ type Authorization struct { Address common.Address `json:"address" gencodec:"required"` Nonce uint64 `json:"nonce" gencodec:"required"` V uint8 `json:"v" gencodec:"required"` - R *big.Int `json:"r" gencodec:"required"` - S *big.Int `json:"s" gencodec:"required"` + R uint256.Int `json:"r" gencodec:"required"` + S uint256.Int `json:"s" gencodec:"required"` } // field type overrides for gencodec @@ -84,8 +84,6 @@ type authorizationMarshaling struct { ChainID hexutil.Uint64 Nonce hexutil.Uint64 V hexutil.Uint64 - R *hexutil.Big - S *hexutil.Big } // SignAuth signs the provided authorization. @@ -114,12 +112,12 @@ func (a *Authorization) withSignature(sig []byte) Authorization { Address: a.Address, Nonce: a.Nonce, V: sig[64], - R: r, - S: s, + R: *uint256.MustFromBig(r), + S: *uint256.MustFromBig(s), } } -// Authority recovers the authorizing +// Authority recovers the the authorizing account of an authorization. func (a Authorization) Authority() (common.Address, error) { sighash := prefixedRlpHash( 0x05, @@ -128,17 +126,16 @@ func (a Authorization) Authority() (common.Address, error) { a.Address, a.Nonce, }) - if !crypto.ValidateSignatureValues(a.V, a.R, a.S, true) { + if !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) { return common.Address{}, ErrInvalidSig } // encode the signature in uncompressed format - r, s := a.R.Bytes(), a.S.Bytes() - sig := make([]byte, crypto.SignatureLength) - copy(sig[32-len(r):32], r) - copy(sig[64-len(s):64], s) + var sig [crypto.SignatureLength]byte + a.R.SetBytes32(sig[:32]) + a.R.SetBytes32(sig[32:64]) sig[64] = a.V // recover the public key from the signature - pub, err := crypto.Ecrecover(sighash[:], sig) + pub, err := crypto.Ecrecover(sighash[:], sig[:]) if err != nil { return common.Address{}, err } diff --git a/tests/gen_stauthorization.go b/tests/gen_stauthorization.go index fbafd6fdea..f40d32c721 100644 --- a/tests/gen_stauthorization.go +++ b/tests/gen_stauthorization.go @@ -5,10 +5,10 @@ package tests import ( "encoding/json" "errors" - "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" + "github.com/holiman/uint256" ) var _ = (*stAuthorizationMarshaling)(nil) @@ -17,19 +17,19 @@ var _ = (*stAuthorizationMarshaling)(nil) 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"` + Address common.Address `json:"address" gencodec:"required"` + Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"` + V math.HexOrDecimal64 `json:"v" gencodec:"required"` + R uint256.Int `json:"r" gencodec:"required"` + S uint256.Int `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) + enc.R = s.R + enc.S = s.S return json.Marshal(&enc) } @@ -37,11 +37,11 @@ func (s stAuthorization) MarshalJSON() ([]byte, error) { 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"` + Address *common.Address `json:"address" gencodec:"required"` + Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"` + V *math.HexOrDecimal64 `json:"v" gencodec:"required"` + R *uint256.Int `json:"r" gencodec:"required"` + S *uint256.Int `json:"s" gencodec:"required"` } var dec stAuthorization if err := json.Unmarshal(input, &dec); err != nil { @@ -65,10 +65,10 @@ func (s *stAuthorization) UnmarshalJSON(input []byte) error { if dec.R == nil { return errors.New("missing required field 'r' for stAuthorization") } - s.R = (*big.Int)(dec.R) + s.R = *dec.R if dec.S == nil { return errors.New("missing required field 's' for stAuthorization") } - s.S = (*big.Int)(dec.S) + s.S = *dec.S return nil } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 6a3ac952ed..a26d2da7b5 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -144,8 +144,8 @@ type stAuthorization struct { Address common.Address `json:"address" gencodec:"required"` Nonce uint64 `json:"nonce" gencodec:"required"` V uint8 `json:"v" gencodec:"required"` - R *big.Int `json:"r" gencodec:"required"` - S *big.Int `json:"s" gencodec:"required"` + R uint256.Int `json:"r" gencodec:"required"` + S uint256.Int `json:"s" gencodec:"required"` } // field type overrides for gencodec @@ -153,8 +153,6 @@ type stAuthorizationMarshaling struct { ChainID math.HexOrDecimal64 Nonce math.HexOrDecimal64 V math.HexOrDecimal64 - R *math.HexOrDecimal256 - S *math.HexOrDecimal256 } // GetChainConfig takes a fork definition and returns a chain config.