Skip to content

Commit 10b14d1

Browse files
authored
Merge pull request #359 from rsksmart/GBI-2875/signature-length-verification
GBI-2875/signature-length-verification
2 parents 3af64db + 8d43fcb commit 10b14d1

File tree

3 files changed

+217
-122
lines changed

3 files changed

+217
-122
lines changed

contracts/libraries/SignatureValidator.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ library SignatureValidator {
1212
@return True if the signature is valid, false otherwise.
1313
*/
1414
function verify(address addr, bytes32 quoteHash, bytes memory signature) public pure returns (bool) {
15+
1516
if (addr == address(0)) {
1617
revert ZeroAddress();
1718
}
1819

20+
if (signature.length != 65) {
21+
revert IncorrectSignature(addr, quoteHash, signature);
22+
}
23+
24+
1925
bytes32 r;
2026
bytes32 s;
2127
uint8 v;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.25;
3+
4+
import {SignatureValidator} from "../libraries/SignatureValidator.sol";
5+
6+
/**
7+
* @dev Wrapper contract for testing the SignatureValidator library
8+
* This contract exposes the library functions for testing without calling the library directly
9+
*/
10+
contract SignatureValidatorWrapper {
11+
12+
// Re-declare the errors from the library so they can be caught in tests
13+
error IncorrectSignature(address expectedAddress, bytes32 usedHash, bytes signature);
14+
error ZeroAddress();
15+
16+
/**
17+
* @dev Wrapper function to test SignatureValidator.verify
18+
* @param addr The signing address
19+
* @param quoteHash The hash of the signed data
20+
* @param signature The signature containing v, r and s
21+
* @return True if the signature is valid, false otherwise.
22+
*/
23+
// solhint-disable-next-line comprehensive-interface
24+
function verify(address addr, bytes32 quoteHash, bytes calldata signature) external pure returns (bool) {
25+
return SignatureValidator.verify(addr, quoteHash, signature);
26+
}
27+
}

0 commit comments

Comments
 (0)