Skip to content

Commit eceab53

Browse files
committed
core/types: change parameter order of SignAuth and rename
The signing key should be passed first, because it is usually in a variable, while the authorization will often be a literal. Compare a, err := types.SignAuthorization(types.SetCodeAuthorization{ ChainID: getChainID(), Nonce: getNonce(), }, key) with a, err := types.SignAuthorization(key, types.SetCodeAuthorization{ ChainID: getChainID(), Nonce: getNonce(), })
1 parent e243812 commit eceab53

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

core/blockchain_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,16 +4273,16 @@ func TestEIP7702(t *testing.T) {
42734273
// 1. tx -> addr1 which is delegated to 0xaaaa
42744274
// 2. addr1:0xaaaa calls into addr2:0xbbbb
42754275
// 3. addr2:0xbbbb writes to storage
4276-
auth1, _ := types.SignAuth(types.SetCodeAuthorization{
4276+
auth1, _ := types.SignAuthorization(key1, types.SetCodeAuthorization{
42774277
ChainID: gspec.Config.ChainID.Uint64(),
42784278
Address: aa,
42794279
Nonce: 1,
4280-
}, key1)
4281-
auth2, _ := types.SignAuth(types.SetCodeAuthorization{
4280+
})
4281+
auth2, _ := types.SignAuthorization(key2, types.SetCodeAuthorization{
42824282
ChainID: 0,
42834283
Address: bb,
42844284
Nonce: 0,
4285-
}, key2)
4285+
})
42864286

42874287
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
42884288
b.SetCoinbase(aa)

core/types/tx_setcode.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,22 @@ type authorizationMarshaling struct {
8787
S hexutil.U256
8888
}
8989

90-
// SignAuth signs the provided authorization.
91-
func SignAuth(auth SetCodeAuthorization, prv *ecdsa.PrivateKey) (SetCodeAuthorization, error) {
90+
// SignAuthorization sets the signature of a code authorization.
91+
func SignAuthorization(prv *ecdsa.PrivateKey, auth SetCodeAuthorization) (SetCodeAuthorization, error) {
9292
sighash := auth.sigHash()
9393
sig, err := crypto.Sign(sighash[:], prv)
9494
if err != nil {
9595
return SetCodeAuthorization{}, err
9696
}
97-
return auth.withSignature(sig), nil
98-
}
99-
100-
// withSignature updates the signature of an Authorization to be equal the
101-
// decoded signature provided in sig.
102-
func (a *SetCodeAuthorization) withSignature(sig []byte) SetCodeAuthorization {
10397
r, s, _ := decodeSignature(sig)
10498
return SetCodeAuthorization{
105-
ChainID: a.ChainID,
106-
Address: a.Address,
107-
Nonce: a.Nonce,
99+
ChainID: auth.ChainID,
100+
Address: auth.Address,
101+
Nonce: auth.Nonce,
108102
V: sig[64],
109103
R: *uint256.MustFromBig(r),
110104
S: *uint256.MustFromBig(s),
111-
}
105+
}, nil
112106
}
113107

114108
func (a *SetCodeAuthorization) sigHash() common.Hash {

0 commit comments

Comments
 (0)