Skip to content

Commit a23266e

Browse files
committed
test on-chain verification
1 parent fa1a8c7 commit a23266e

5 files changed

Lines changed: 91 additions & 11 deletions

File tree

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export RPC_URL=https://*****/*************8b549a8a377a52d0f
2+
export CHAIN_ID=11155111
3+
export PRIVATE_KEY=****************
4+
export VERIFIER_ADDRESS=0xYourVerifierAddress
5+
6+
export PARAMS_JSON='{"L":2,"H":[{"x":1,"y":2},{"x":3,"y":4},{"x":5,"y":6}]}'
7+
export PK_JSON='{"w":{"x":[1,2],"y":[3,4]}}'

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ docs/
1414
.env
1515

1616
# vscode
17-
.vscode/
17+
.vscode/
18+
19+
tmp
20+
21+
broadcast/

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
bbs on-chain verifier contracts
44

5+
## How to use
6+
7+
1. Edit `.env`
8+
2. Run command below:
9+
```bash
10+
forge script script/DeployVerifier.s.sol:DeployVerifier \
11+
--rpc-url "$RPC_URL" \
12+
--private-key "$PRIVATE_KEY" \
13+
--broadcast
14+
```
15+
3. To verify, use the command below:
16+
```bash
17+
cast call $VERIFIER_ADDRESS \
18+
"verify(((uint256,uint256),uint256,uint256),uint256[])(bool)" \
19+
"((Ax,Ay),e,s)" \
20+
"[M1,M2,M3]" \
21+
--rpc-url $RPC_URL
22+
```
23+
524
## Thanks
625

7-
The precompile pairing refer to [zkREPL](https://zkrepl.dev/)
26+
+ The precompile pairing references [zkREPL](https://zkrepl.dev/)

script/DeployVerifier.s.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Script.sol";
5+
import "../src/Verifier.sol";
6+
7+
contract DeployVerifier is Script {
8+
function run() external {
9+
// Read data
10+
string memory paramsJson = vm.envString("PARAMS_JSON");
11+
string memory pkJson = vm.envString("PK_JSON");
12+
13+
// Deserialize
14+
uint256 L = vm.parseJsonUint(paramsJson, ".L");
15+
bytes memory hRaw = vm.parseJson(paramsJson, ".H");
16+
BN254.G1Point[] memory H = abi.decode(hRaw, (BN254.G1Point[]));
17+
18+
Verifier.Parameters memory p;
19+
p.L = L;
20+
p.H = H;
21+
22+
// Deserialize public key
23+
BN254.G2Point memory w;
24+
w.x[0] = vm.parseJsonUint(pkJson, ".w.x[0]");
25+
w.x[1] = vm.parseJsonUint(pkJson, ".w.x[1]");
26+
w.y[0] = vm.parseJsonUint(pkJson, ".w.y[0]");
27+
w.y[1] = vm.parseJsonUint(pkJson, ".w.y[1]");
28+
29+
Verifier.PublicKey memory pk;
30+
pk.w = w;
31+
32+
vm.startBroadcast();
33+
Verifier v = new Verifier(p, pk);
34+
vm.stopBroadcast();
35+
36+
console2.log("Verifier deployed at:", address(v));
37+
console2.log("If you are using sepolia, see: https://sepolia.etherscan.io/address/", address(v));
38+
}
39+
}

src/Verifier.sol

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@ import {BN254} from "./lib.sol";
66
contract Verifier {
77
using BN254 for BN254.G1Point;
88

9-
BN254.G1Point internal g1;
10-
BN254.G2Point internal g2;
9+
BN254.G1Point internal g1 = BN254.G1Point({
10+
x: 1,
11+
y: 2
12+
});
13+
14+
BN254.G2Point internal g2 = BN254.G2Point({
15+
x: [
16+
uint256(10857046999023057135944570762232829481370756359578518086990519993285655852781),
17+
uint256(11559732032986387107991004021392285783925812861821192530917403151452391805634)
18+
],
19+
y: [
20+
uint256(8495653923123431417604973247489272438418190587263600148770280649306958101930),
21+
uint256(4082367875863433681332203403145435568316851327593401208105741076214120093531)
22+
]
23+
});
1124

1225
uint256 public constant FR_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
1326

@@ -50,9 +63,6 @@ contract Verifier {
5063

5164
owner = msg.sender;
5265

53-
g1 = BN254.g1Generator();
54-
g2 = BN254.g2Generator();
55-
5666
_setParameters(_params);
5767
_setPublicKey(_pk);
5868
}
@@ -78,11 +88,12 @@ contract Verifier {
7888
}
7989

8090
/// @notice allows updating generators
81-
function updateGenerators(BN254.G1Point memory _g1, BN254.G2Point memory _g2) external onlyOwner {
91+
// uncomment these to activate
92+
/* function updateGenerators(BN254.G1Point memory _g1, BN254.G2Point memory _g2) external onlyOwner {
8293
g1 = _g1;
8394
g2 = _g2;
8495
emit GeneratorsUpdated();
85-
}
96+
} */
8697

8798
function _setPublicKey(PublicKey memory _pk) internal {
8899
pk = _pk;
@@ -108,9 +119,9 @@ contract Verifier {
108119
return pk;
109120
}
110121

111-
function getGenerators() external view returns (BN254.G1Point memory, BN254.G2Point memory) {
122+
/* function getGenerators() external view returns (BN254.G1Point memory, BN254.G2Point memory) {
112123
return (g1, g2);
113-
}
124+
} */
114125

115126
function getParametersMeta() external view returns (uint256 L, uint256 hLen) {
116127
return (params.L, params.H.length);

0 commit comments

Comments
 (0)