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
|
// 1. tx -> addr1 which is delegated to 0xaaaa
|
||||||
// 2. addr1:0xaaaa calls into addr2:0xbbbb
|
// 2. addr1:0xaaaa calls into addr2:0xbbbb
|
||||||
// 3. addr2:0xbbbb writes to storage
|
// 3. addr2:0xbbbb writes to storage
|
||||||
auth1, _ := types.SignAuth(types.SetCodeAuthorization{
|
auth1, _ := types.SignAuthorization(key1, types.SetCodeAuthorization{
|
||||||
ChainID: gspec.Config.ChainID.Uint64(),
|
ChainID: gspec.Config.ChainID.Uint64(),
|
||||||
Address: aa,
|
Address: aa,
|
||||||
Nonce: 1,
|
Nonce: 1,
|
||||||
}, key1)
|
})
|
||||||
auth2, _ := types.SignAuth(types.SetCodeAuthorization{
|
auth2, _ := types.SignAuthorization(key2, types.SetCodeAuthorization{
|
||||||
ChainID: 0,
|
ChainID: 0,
|
||||||
Address: bb,
|
Address: bb,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
}, key2)
|
})
|
||||||
|
|
||||||
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
|
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {
|
||||||
b.SetCoinbase(aa)
|
b.SetCoinbase(aa)
|
||||||
|
|
|
||||||
|
|
@ -87,28 +87,22 @@ type authorizationMarshaling struct {
|
||||||
S hexutil.U256
|
S hexutil.U256
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignAuth signs the provided authorization.
|
// SignAuthorization sets the signature of a code authorization.
|
||||||
func SignAuth(auth SetCodeAuthorization, prv *ecdsa.PrivateKey) (SetCodeAuthorization, error) {
|
func SignAuthorization(prv *ecdsa.PrivateKey, auth SetCodeAuthorization) (SetCodeAuthorization, error) {
|
||||||
sighash := auth.sigHash()
|
sighash := auth.sigHash()
|
||||||
sig, err := crypto.Sign(sighash[:], prv)
|
sig, err := crypto.Sign(sighash[:], prv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SetCodeAuthorization{}, err
|
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)
|
r, s, _ := decodeSignature(sig)
|
||||||
return SetCodeAuthorization{
|
return SetCodeAuthorization{
|
||||||
ChainID: a.ChainID,
|
ChainID: auth.ChainID,
|
||||||
Address: a.Address,
|
Address: auth.Address,
|
||||||
Nonce: a.Nonce,
|
Nonce: auth.Nonce,
|
||||||
V: sig[64],
|
V: sig[64],
|
||||||
R: *uint256.MustFromBig(r),
|
R: *uint256.MustFromBig(r),
|
||||||
S: *uint256.MustFromBig(s),
|
S: *uint256.MustFromBig(s),
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *SetCodeAuthorization) sigHash() common.Hash {
|
func (a *SetCodeAuthorization) sigHash() common.Hash {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue