-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSecp256k1Properties.t.sol
50 lines (38 loc) · 1.39 KB
/
Secp256k1Properties.t.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
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.16;
import {Test} from "forge-std/Test.sol";
import {console2 as console} from "forge-std/console2.sol";
import {Secp256k1Offchain} from "offchain/Secp256k1Offchain.sol";
import {Secp256k1, SecretKey, PublicKey} from "src/Secp256k1.sol";
import {Points, Point, ProjectivePoint} from "src/arithmetic/Points.sol";
/**
* @notice Secp256k1 Property Tests
*/
contract Secp256k1PropertiesTest is Test {
using Secp256k1Offchain for SecretKey;
using Secp256k1 for SecretKey;
using Secp256k1 for PublicKey;
using Secp256k1 for Point;
//--------------------------------------------------------------------------
// Test: (De)Serialization
//----------------------------------
// Secret Key
function testProperty_SecretKey_Bytes_SerializationLoop(SecretKey start)
public
pure
{
vm.assume(start.isValid());
SecretKey end = Secp256k1.secretKeyFromBytes(start.toBytes());
assertEq(start.asUint(), end.asUint());
}
//----------------------------------
// Public Key
function testProperty_PublicKey_Bytes_SerializationLoop(SecretKey sk)
public
{
vm.assume(sk.isValid());
PublicKey memory start = sk.toPublicKey();
PublicKey memory end = Secp256k1.publicKeyFromBytes(start.toBytes());
assertTrue(start.eq(end));
}
}