Replies: 3 comments
|
The solution is to use different private keys — each key produces a unique valid signature for the same digest: uint256 privateKeyA = 0x1;
uint256 privateKeyB = 0x2;
uint256 privateKeyC = 0x3;
bytes32 digest = keccak256("some message");
(uint8 v1, bytes32 r1, bytes32 s1) = vm.sign(privateKeyA, digest);
(uint8 v2, bytes32 r2, bytes32 s2) = vm.sign(privateKeyB, digest);
(uint8 v3, bytes32 r3, bytes32 s3) = vm.sign(privateKeyC, digest);Each signature is valid and different. You can derive the corresponding addresses with: address signerA = vm.addr(privateKeyA);
address signerB = vm.addr(privateKeyB);
address signerC = vm.addr(privateKeyC);This is the standard approach for testing multi-sig contracts or anything requiring multiple unique signatures over the same message. |
|
The existing answer is right that Foundry's Your options depend on what the test is trying to prove:
If the contract treats two encodings of the same signer/digest as two independent approvals, that is usually the bug to fix: deduplicate by recovered signer and use a per-action nonce/domain separator, not by raw signature bytes. So: |
|
Good additions. To summarize for anyone landing here:
And if the contract treats different raw signatures over the same |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a test, where I want to create different signatures for the same digest. If I use
vm.sign(privateKey, digest)multiple times I get the same signature. Is there a way I can force it to use differentkto create different signatures?All reactions