mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
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(),
})
This commit is contained in:
parent
e243812b97
commit
eceab538ce
2 changed files with 10 additions and 16 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue