Skip to content
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

fix: test_permitBadV #28

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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