Skip to content

Commit

Permalink
latest test vector digest
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Feb 13, 2025
1 parent 7ef6839 commit 3a3169a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
7 changes: 6 additions & 1 deletion src/SignatureChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ contract SignatureChecker is Ownable {
/// @notice Mapping of notary addresses to their validity
mapping(address => bool) public isNotary;

uint256 public constant BN254_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617;

/// @notice Error for invalid signatures
error InvalidSignature();
/// @notice Error for invalid notary addresses
error InvalidNotary();

/// @notice Error for invalid signature length
error InvalidSignatureLength();

/// @notice Constructor configures the notary address
/// @param _notaryAddress The address of the notary to add
constructor(address _notaryAddress) Ownable(msg.sender) {
Expand All @@ -38,7 +43,7 @@ contract SignatureChecker is Ownable {
/// @param r The R value of the signature
/// @param s The S value of the signature
/// @param signer The address that signed the data
function verifySignature(bytes32 _hash, uint8 v, bytes32 r, bytes32 s, address signer)
function verifyNotarySignature(bytes32 _hash, uint8 v, bytes32 r, bytes32 s, address signer)
external
view
returns (bool)
Expand Down
9 changes: 0 additions & 9 deletions test.json

This file was deleted.

26 changes: 7 additions & 19 deletions test/SignatureChecker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@ contract SignatureCheckerTest is Test {
}

function test_isValidSignatureNow() public view {

// TEST vector from NOTARY
// "merkle_root": "0x2943593524b7c19d5448e2489772f3de80d71418c3a62b25ef39559334acbffe",
// "signature" is comprised of 160 characters
// 0x3045022100 : Not sure what the firstones here are
// 9039bd2ded8fd5e09b62a04a3d25d2d13f0f45f40c1b4ca6c3aece4a71f92c14 : This is the R value
// 0220 : Not sure what the secondones here are
// 16d62561a8939ed49c97d9621c47988cf74b5b5074f89f2b2c6b9b18a6eeb1b2 : This is the S value
// "signature_r": "0x9039bd2ded8fd5e09b62a04a3d25d2d13f0f45f40c1b4ca6c3aece4a71f92c14",
// "signature_s": "0x16d62561a8939ed49c97d9621c47988cf74b5b5074f89f2b2c6b9b18a6eeb1b2",
// "signature_v": 28,
// "signer": "0xfdf07a5dcfa7b74f4c28dab23ead8b1c43be801f"
address signer = 0xfdf07A5dCfa7b74f4c28DAb23eaD8B1c43Be801F;
// There are interestingly 129 characters in this signature, the ercrecover opcode expects 65 where 32 are R, 32 are S, and 1 is V
bytes32 _hash = bytes32(0x2943593524b7c19d5448e2489772f3de80d71418c3a62b25ef39559334acbffe);
uint8 v = 28;
bytes32 r = bytes32(0x9039bd2ded8fd5e09b62a04a3d25d2d13f0f45f40c1b4ca6c3aece4a71f92c14);
bytes32 s = bytes32(0x16d62561a8939ed49c97d9621c47988cf74b5b5074f89f2b2c6b9b18a6eeb1b2);
// verify signature
assertEq(signatureChecker.verifySignature(_hash, v, r, s, signer), true);
bytes32 digest = bytes32(0x0ad25b24a05589ed9f2332ac85f5690c8400019f32858c2f6bf24877362d41db);
bytes32 r = bytes32(0x86c6ab86ac26bfdfd245ab65a05e90cd18afe9f810acb42532adf7570cd0ed77);
bytes32 s = bytes32(0x17370b1c7a7d7d96155e6144a9bfc9265f81c354b1cb4af7cebe52e601dabfef);
uint8 v = 27;
assertEq(signatureChecker.verifyNotarySignature(digest, v, r, s, signer), true);

}
}
}
9 changes: 9 additions & 0 deletions test_vectors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"digest": "0x0ad25b24a05589ed9f2332ac85f5690c8400019f32858c2f6bf24877362d41db",
"signature": "0x304502210086c6ab86ac26bfdfd245ab65a05e90cd18afe9f810acb42532adf7570cd0ed77022017370b1c7a7d7d96155e6144a9bfc9265f81c354b1cb4af7cebe52e601dabfef",
"signature_r": "0x86c6ab86ac26bfdfd245ab65a05e90cd18afe9f810acb42532adf7570cd0ed77",
"signature_s": "0x17370b1c7a7d7d96155e6144a9bfc9265f81c354b1cb4af7cebe52e601dabfef",
"signature_v": 27,
"signer": "0xfdf07a5dcfa7b74f4c28dab23ead8b1c43be801f"
}

0 comments on commit 3a3169a

Please sign in to comment.