Skip to content

Commit 855e90a

Browse files
committed
node: Add comments for hash input to file signer's Sign() method
1 parent 3bdaa36 commit 855e90a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

node/pkg/guardiansigner/filesigner.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,22 @@ func NewFileSigner(_ context.Context, unsafeDevMode bool, signerKeyPath string)
7474
}
7575

7676
// Sign signs a hash using the go-ethereum/crypto package's `Sign` function.
77+
//
78+
// As noted in the go-ethereum documentation, this function is subject to
79+
// chosen-plaintext attacks. As a result, the input to this function must
80+
// be a hash of the message that is being signed. This function will
81+
// return an error if the hash is not the correct size.
7782
func (fs *FileSigner) Sign(ctx context.Context, hash []byte) ([]byte, error) {
83+
84+
// Ensure hash is 32 bytes.
85+
// This check is also performed by the Sign() function below, but we do it here
86+
// to ensure the integrity of Guardian's signed messages even if
87+
// go-ethereum/crypto is updated in the future.
88+
const digestLength = 32
89+
if len(hash) != digestLength {
90+
return nil, fmt.Errorf("hash is required to be exactly %d bytes (%d)", digestLength, len(hash))
91+
}
92+
7893
// Sign the hash
7994
sig, err := crypto.Sign(hash, fs.privateKey)
8095

0 commit comments

Comments
 (0)