-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(cheatcodes): Add vm.signWithNonce(privateKey, digest, nonce) cheatcode (Crypto) #11267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
cheatcodes
): Add vm.signWithNonce(privateKey, digest, nonce) cheatcode (Crypto)
cheatcodes
): Add vm.signWithNonce(privateKey, digest, nonce) cheatcode (Crypto)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits (not a final review)
review modification Co-authored-by: onbjerg <[email protected]>
review modification (better format) Co-authored-by: onbjerg <[email protected]>
given the security concerns, and the fact that this is only useful for security researchers, imo we should rename the cheatcode to include the i'd either do |
That's a good idea. |
Motivation
Security researchers and advanced test writers sometimes need to create deterministic ECDSA signatures with a chosen ephemeral nonce
k
.This is useful to:
Currently, Foundry's
vm.sign
only derivesk
internally (RFC6979) and does not allow injecting a fixed nonce.For security testing and deeper protocol analysis, we need a way to supply
k
manually.Closes #11266.
Solution
This PR introduces a new cheatcode:
digest
on secp256k1 usingprivateKey
and a user-supplied noncek
.privateKey
andnonce
to be in(0, n)
wheren
is the secp256k1 curve order.Changes include:
crypto.rs
implementation of the fixed-nonce signing path.Vm.sol
interface.testdata/default/cheats/Sign.t.sol
covering valid and invalid nonce cases.PR Checklist
Question
EDIT: Just wondering, was it intentional to not have
cargo cheats
included in themake pr
target in theMakefile
? (And is it expected that the firstcargo cheats
crashes but the second runs fine?)