-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
updated
20 files
+1 −1 | README.md | |
+1 −1 | package.json | |
+4 −0 | src/StdChains.sol | |
+1 −1 | src/StdCheats.sol | |
+104 −0 | src/StdJson.sol | |
+104 −0 | src/StdToml.sol | |
+95 −8 | src/Vm.sol | |
+471 −463 | src/console.sol | |
+2 −2 | src/interfaces/IERC4626.sol | |
+1 −1 | test/StdAssertions.t.sol | |
+14 −12 | test/StdChains.t.sol | |
+10 −10 | test/StdCheats.t.sol | |
+12 −12 | test/StdError.t.sol | |
+1 −1 | test/StdJson.t.sol | |
+4 −14 | test/StdMath.t.sol | |
+5 −5 | test/StdStorage.t.sol | |
+1 −1 | test/StdStyle.t.sol | |
+1 −1 | test/StdToml.t.sol | |
+12 −12 | test/StdUtils.t.sol | |
+9 −6 | test/Vm.t.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import {BLS} from "../src/sign/BLS.sol"; | ||
|
||
/// @notice A simple test demonstrating BLS signature verification. | ||
contract BLSTest is Test { | ||
/// @notice The generator point in G1 (P1). | ||
BLS.G1Point G1_GENERATOR = BLS.G1Point( | ||
BLS.Fp( | ||
31827880280837800241567138048534752271, | ||
88385725958748408079899006800036250932223001591707578097800747617502997169851 | ||
), | ||
BLS.Fp( | ||
11568204302792691131076548377920244452, | ||
114417265404584670498511149331300188430316142484413708742216858159411894806497 | ||
) | ||
); | ||
|
||
/// @notice The negated generator point in G1 (-P1). | ||
BLS.G1Point NEGATED_G1_GENERATOR = BLS.G1Point( | ||
BLS.Fp( | ||
31827880280837800241567138048534752271, | ||
88385725958748408079899006800036250932223001591707578097800747617502997169851 | ||
), | ||
BLS.Fp( | ||
22997279242622214937712647648895181298, | ||
46816884707101390882112958134453447585552332943769894357249934112654335001290 | ||
) | ||
); | ||
|
||
function test() public { | ||
// Obtain the private key as a random scalar. | ||
uint256 privateKey = vm.randomUint(); | ||
|
||
// Public key is the generator point multiplied by the private key. | ||
BLS.G1Point memory publicKey = BLS.G1Mul(G1_GENERATOR, privateKey); | ||
|
||
// Compute the message point by mapping message's keccak256 hash to a point in G2. | ||
bytes memory message = "hello world"; | ||
BLS.G2Point memory messagePoint = BLS.MapFp2ToG2(BLS.Fp2(BLS.Fp(0, 0), BLS.Fp(0, uint256(keccak256(message))))); | ||
|
||
// Obtain the signature by multiplying the message point by the private key. | ||
BLS.G2Point memory signature = BLS.G2Mul(messagePoint, privateKey); | ||
|
||
// Invoke the pairing check to verify the signature. | ||
BLS.G1Point[] memory g1Points = new BLS.G1Point[](2); | ||
g1Points[0] = NEGATED_G1_GENERATOR; | ||
g1Points[1] = publicKey; | ||
|
||
BLS.G2Point[] memory g2Points = new BLS.G2Point[](2); | ||
g2Points[0] = signature; | ||
g2Points[1] = messagePoint; | ||
|
||
assertTrue(BLS.Pairing(g1Points, g2Points)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import {Secp256r1} from "../src/sign/Secp256r1.sol"; | ||
|
||
/// @notice A simple test demonstrating P256 signature verification. | ||
contract BLSTest is Test { | ||
function test() public { | ||
// Obtain the private key and derive the public key. | ||
uint256 privateKey = vm.randomUint(); | ||
(uint256 publicKeyX, uint256 publicKeyY) = vm.publicKeyP256(privateKey); | ||
|
||
bytes memory message = "hello world"; | ||
bytes32 digest = keccak256(message); | ||
|
||
// Sign the hashed message. | ||
(bytes32 r, bytes32 s) = vm.signP256(privateKey, digest); | ||
|
||
// Verify the signature. | ||
assertTrue(Secp256r1.verify(digest, r, s, publicKeyX, publicKeyY)); | ||
} | ||
} |