diff --git a/core/blockchain_test.go b/core/blockchain_test.go index c756374b5a..74b7c7b020 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -4273,16 +4273,16 @@ func TestEIP7702(t *testing.T) { // 1. tx -> addr1 which is delegated to 0xaaaa // 2. addr1:0xaaaa calls into addr2:0xbbbb // 3. addr2:0xbbbb writes to storage - auth1, _ := types.SignAuth(types.SetCodeAuthorization{ + auth1, _ := types.SignAuthorization(key1, types.SetCodeAuthorization{ ChainID: gspec.Config.ChainID.Uint64(), Address: aa, Nonce: 1, - }, key1) - auth2, _ := types.SignAuth(types.SetCodeAuthorization{ + }) + auth2, _ := types.SignAuthorization(key2, types.SetCodeAuthorization{ ChainID: 0, Address: bb, Nonce: 0, - }, key2) + }) _, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) { b.SetCoinbase(aa) diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index 324bab8d60..92d6ac29dd 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -87,28 +87,22 @@ type authorizationMarshaling struct { S hexutil.U256 } -// SignAuth signs the provided authorization. -func SignAuth(auth SetCodeAuthorization, prv *ecdsa.PrivateKey) (SetCodeAuthorization, error) { +// SignAuthorization sets the signature of a code authorization. +func SignAuthorization(prv *ecdsa.PrivateKey, auth SetCodeAuthorization) (SetCodeAuthorization, error) { sighash := auth.sigHash() sig, err := crypto.Sign(sighash[:], prv) if err != nil { return SetCodeAuthorization{}, err } - return auth.withSignature(sig), nil -} - -// withSignature updates the signature of an Authorization to be equal the -// decoded signature provided in sig. -func (a *SetCodeAuthorization) withSignature(sig []byte) SetCodeAuthorization { r, s, _ := decodeSignature(sig) return SetCodeAuthorization{ - ChainID: a.ChainID, - Address: a.Address, - Nonce: a.Nonce, + ChainID: auth.ChainID, + Address: auth.Address, + Nonce: auth.Nonce, V: sig[64], R: *uint256.MustFromBig(r), S: *uint256.MustFromBig(s), - } + }, nil } func (a *SetCodeAuthorization) sigHash() common.Hash {