Skip to content

Commit

Permalink
fix: test_permitBadV (#28)
Browse files Browse the repository at this point in the history
* fix: test_permitBadV

* style: remove extra line

* chore: add comment explaining the test

Co-authored-by: Lucas Manuel <[email protected]>
  • Loading branch information
edag94 and Lucas Manuel authored Mar 14, 2022
1 parent 8e7405e commit 8d55417
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions contracts/test/ERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,28 @@ contract ERC20PermitTest is TestUtils {

function test_permitBadV() external {
uint256 amount = 10 * WAD;

// Get valid signature. The `v` value is the expected v value that will cause `permit` to succeed, and must be 27 or 28.
// Any other value should fail.
// If v is 27, then 28 should make it past the MALLEABLE require, but should result in an invalid signature, and vice versa when v is 28.
( uint8 v, bytes32 r, bytes32 s ) = _getValidPermitSignature(amount, owner, skOwner, deadline);

for (uint8 i; i <= type(uint8).max; i++) {
if (i == type(uint8).max) {
break;
} else if (i == 28) {
continue;
} else if (i == 27) {
// Should get past the Malleable require check as 27 or 28 are valid values for s.
vm.expectRevert(bytes("ERC20:P:INVALID_SIGNATURE"));
} else {
} else if (i != 27 && i != 28) {
vm.expectRevert(bytes("ERC20:P:MALLEABLE"));
} else {
if (i == v) {
continue;
} else {
// Should get past the Malleable require check as 27 or 28 are valid values for s.
vm.expectRevert(bytes("ERC20:P:INVALID_SIGNATURE"));
}
}
user.erc20_permit(address(token), owner, spender, amount, deadline, i, r, s);
}

assertEq(v, 28);
user.erc20_permit(address(token), owner, spender, amount, deadline, v, r, s);
}

Expand Down

0 comments on commit 8d55417

Please sign in to comment.