Skip to content

Commit

Permalink
♻️ Improve brutalizer (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized authored Aug 18, 2024
1 parent e8768f2 commit 00bfa87
Show file tree
Hide file tree
Showing 7 changed files with 1,094 additions and 819 deletions.
1,504 changes: 752 additions & 752 deletions .gas-snapshot

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions test/ECDSA.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ contract ECDSATest is SoladyTest {
uint256 privateKey;
(signer, privateKey) = _randomSigner();
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);
v = _brutalizedV(v);
v = _brutalizedUint8(v);
signature = abi.encodePacked(r, s, v);
cHash = ECDSA.canonicalHash(signature);
assertEq(keccak256(signature), cHash);
Expand All @@ -531,7 +531,7 @@ contract ECDSATest is SoladyTest {
}

if (_randomChance(4)) {
uint8 corruptedV = _brutalizedV(uint8(_random()));
uint8 corruptedV = _brutalizedUint8(uint8(_random()));
assertEq(
ECDSA.canonicalHash(abi.encodePacked(r, s, corruptedV)),
ECDSA.canonicalHash(corruptedV, r, s)
Expand Down Expand Up @@ -599,13 +599,6 @@ contract ECDSATest is SoladyTest {
}
}

function _brutalizedV(uint8 v) internal pure returns (uint8 result) {
/// @solidity memory-safe-assembly
assembly {
result := xor(shl(8, keccak256(0x00, 0xa0)), v)
}
}

function _corruptedSignature(bytes memory signature) internal returns (bytes memory result) {
if (_randomChance(2)) {
result = abi.encodePacked(signature, uint8(_random()), _random());
Expand Down
Loading

0 comments on commit 00bfa87

Please sign in to comment.