Skip to content

Commit 44d7e43

Browse files
committed
doc: Pack() and Sign() functions
1 parent c6915d1 commit 44d7e43

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

libevm/precompiles/p256verify/p256verify.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ func (in *input) bigWord(index int) *big.Int {
8383
return new(big.Int).SetBytes(in.word(index))
8484
}
8585

86-
// Sign signs `hash` with the private key, returning a byte slice compatible
87-
// with [Precompile.Run]. It uses [rand.Reader] as the first argument to
88-
// [ecdsa.Sign].
86+
// Sign signs `hash` with the private key, using [rand.Reader] as the first
87+
// argument to [ecdsa.Sign]. It returns a signature payload constructed with
88+
// [Pack], which can therefore be passed directly to the precompile.
8989
func Sign(priv *ecdsa.PrivateKey, hash [32]byte) ([]byte, error) {
9090
r, s, err := ecdsa.Sign(rand.Reader, priv, hash[:])
9191
if err != nil {
@@ -94,6 +94,10 @@ func Sign(priv *ecdsa.PrivateKey, hash [32]byte) ([]byte, error) {
9494
return Pack(hash, r, s, &priv.PublicKey), nil
9595
}
9696

97+
// Pack packs the arguments into a byte slice compatible with [Precompile.Run].
98+
// It does NOT perform any validation on its inputs and therefore may panic if,
99+
// for example, a [big.Int] with >256 bits is received. Keys and signatures
100+
// generated with [elliptic.GenerateKey] and [ecdsa.Sign] are valid inputs.
97101
func Pack(hash [32]byte, r, s *big.Int, key *ecdsa.PublicKey) []byte {
98102
var in input
99103
copy(in.word(0), hash[:])

0 commit comments

Comments
 (0)