-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathP256Verifier.sol
39 lines (33 loc) · 1.24 KB
/
P256Verifier.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./BytesUtils.sol";
/**
* @title P256Verifier Wrapper
*/
abstract contract P256Verifier {
using BytesUtils for bytes;
/// @dev this address can either be:
/// - 0x100 (as defined in RIP-7212)
/// - 0xc2b78104907F722DABAc4C69f826a522B2754De4 (daimo-eth P256 implementation, ref: https://github.com/daimo-eth/p256-verifier/)
/// @dev may contain other P256 Verifier address depending on the target network
address public immutable P256_VERIFIER;
constructor(address _verifier) {
P256_VERIFIER = _verifier;
}
function ecdsaVerify(bytes32 messageHash, bytes memory signature, bytes memory key)
internal
view
returns (bool verified)
{
bytes memory args = abi.encode(
messageHash,
uint256(bytes32(signature.substring(0, 32))),
uint256(bytes32(signature.substring(32, 32))),
uint256(bytes32(key.substring(0, 32))),
uint256(bytes32(key.substring(32, 32)))
);
(bool success, bytes memory ret) = P256_VERIFIER.staticcall(args);
assert(success); // never reverts, always returns 0 or 1
verified = abi.decode(ret, (uint256)) == 1;
}
}