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

mitigation: off chain signature validator #331

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract OffChainSignatureValidator is IERC1271 {
error NotMemberOfParty();
error InsufficientVotingPower();
error MessageHashMismatch();
error InvalidSignature();

/// @notice Event emitted when signing threshold updated
event SigningThresholdBpsSet(
Expand Down Expand Up @@ -56,6 +57,11 @@ contract OffChainSignatureValidator is IERC1271 {

Party party = Party(payable(msg.sender));
address signer = ecrecover(hash, v, r, s);

if (signer == address(0)) {
revert InvalidSignature();
}

uint96 signerVotingPowerBps = party.getVotingPowerAt(
signer,
uint40(block.timestamp),
Expand All @@ -73,7 +79,7 @@ contract OffChainSignatureValidator is IERC1271 {
// Either threshold is 0 or signer votes above threshold
if (
thresholdBps == 0 ||
(signerVotingPowerBps > totalVotingPower &&
(signerVotingPowerBps >= totalVotingPower &&
signerVotingPowerBps / totalVotingPower >= thresholdBps)
) {
return IERC1271.isValidSignature.selector;
Expand Down
22 changes: 22 additions & 0 deletions test/signature-validators/OffChainSignatureValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ contract OffChainSignatureValidatorTest is SetupPartyHelper {
assertEq(abi.decode(res, (bytes4)), IERC1271.isValidSignature.selector);
}

function testOffChainSignatureValidator_invalidSignature() public {
string memory message = "Hello, this is my message";
bytes memory encondedMessage = abi.encodePacked(message);
bytes memory encodedPacket = abi.encodePacked(
"\x19Ethereum Signed Message:\n",
Strings.toString(encondedMessage.length),
encondedMessage
);
bytes32 messageHash = keccak256(encodedPacket);
(, bytes32 r, bytes32 s) = vm.sign(johnPk, messageHash);
bytes memory signature = abi.encodePacked(r, s, uint8(0), message);

bytes memory staticCallData = abi.encodeWithSelector(
IERC1271.isValidSignature.selector,
messageHash,
signature
);
vm.startPrank(address(0), address(0));
vm.expectRevert(OffChainSignatureValidator.InvalidSignature.selector);
address(party).staticcall(staticCallData);
}

function _signMessage(
uint256 privateKey,
string memory message
Expand Down