Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "forgeTest/lib/forge-std"]
path = forgeTest/lib/forge-std
url = https://github.com/foundry-rs/forge-std
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ clean:
find . -name "*.r1cs" -type f -delete
find . -name "*.sym" -type f -delete
-find . -name "*_js" -type d | xargs rm -r
-find . -name "*_cpp" -type d | xargs rm -r
-find . -name "*_cpp" -type d | xargs rm -r

test-forge:
python3 generator.py
cd forgeTest
forge test
34 changes: 34 additions & 0 deletions forgeTest/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
14 changes: 14 additions & 0 deletions forgeTest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
66 changes: 66 additions & 0 deletions forgeTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
6 changes: 6 additions & 0 deletions forgeTest/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions forgeTest/lib/forge-std
Submodule forge-std added at 36c303
12 changes: 12 additions & 0 deletions forgeTest/script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";

contract CounterScript is Script {
function setUp() public {}

function run() public {
vm.broadcast();
}
}
8,430 changes: 8,430 additions & 0 deletions forgeTest/src/batchverifier.sol

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions forgeTest/test/batchverifier.t.sol

Large diffs are not rendered by default.

8,430 changes: 8,430 additions & 0 deletions generated/batchverifier.sol

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions generated/proof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"pi_a":["13579029548046625646271183087954096809401264806668502927093033099161476076576","18124254697466476117581331859657944560965941299048814163773675461398734016388","1"],"pi_b":[["2702717479163133362619043733328815064523151421377604535697565200051551072711","6193387373039604661725499143222844992844122819932893284344962074535423656015"],["15246317953416621135258870809451112074556013201394379287753732314990418208726","16859444411929385376416646850276330608687282582593303251595028671376130875900"],["1","0"]],"pi_c":["19611464305650669726419885265583149776523477201741566390124116431365967012209","18498956057552833450531300846537971062809610642421953949353581711325595757390","1"],
"protocol":"groth16"}
1 change: 1 addition & 0 deletions generated/public.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["0","1","0","0","0","1","0","0","0","1","1","1","0","0","1","0","0","0","1","0","0","1","0","0","0","1","1","1","0","0","1","0","0","1","1","0","0","1","0","0","0","1","1","1","0","0","1","0","0","0","0","1","0","1","0","0","0","1","1","1","0","0","1","0","0","1","1","0","1","1","0","1","0","1","0","0","1","0","0","0","1","1","1","1","1","1","1","1","0","1","0","1","1","0","0","1","1","0","1","1","0","0","1","1","0","0","1","1","1","0","0","0","1","1","0","0","1","0","1","0","0","1","1","0","0","1","0","0","0","1","0","1","0","1","0","0","0","0","0","1","0","0","0","1","0","0","0","1","1","0","1","0","0","0","0","0","1","1","1","1","1","0","0","1","0","1","1","1","1","1","0","0","1","1","1","0","1","1","1","1","1","1","0","1","0","1","0","1","0","0","0","1","0","1","0","1","1","0","1","1","0","1","1","1","1","0","0","1","0","0","0","0","1","0","1","1","1","1","0","1","0","1","1","0","0","0","0","1","0","1","0","1","0","1","0","0","0","0","1","1","0","0","0","0","1","1","0","1","0","0","0","0","0","0","1","1","0","0","0","0","0","1","1","1","1","1","0","1","0","0","1","0","1","0","1","1","0","1","1","1","0","0","1","1","0","1","1","0","0","0","0","1","0","0","1","1","1","1","1","0","1","0","1","1","0","1","1","0","0","0","1","1","0","0","0","0","0","0","0","0","0","1","0","0","0","1","0","0","0","0","1","0","0","1","0","0","1","0","1","1","1","0","0","0","1","1","0","0","0","0","0","0","0","0","1","0","1","0","1","1","0","1","1","1","0","0","0","1","1","0","0","0","1","0","1","1","1","1","1","1","1","1","1","1","1","0","0","0","0","1","1","0","0","0","0","0","1","1","1","0","1","1","0","1","0","0","0","1","0","1","1","1","0","1","0","0","0","1","0","1","1","1","1","0","0","0","1","0","0","1","0","0","0","1","0","0","1","0","0","0","0","1","0","1","1","0","0","1","1","0","0","1","1","1","0","1","1","0","1","0","1","0","0","0","0","0","1","1","1","0","1","0","0","1","0","1","1","1","0","0","0","1","0","0","0","1","0","0","0","1","0","0","1","0","0","1","1","0","1","1","0","1","0","1","1","1","1","1","0","0","1","1","0","0","1","1","1","0","1","0","0","1","0","1","1","1","1","0","0","0","0","1","1","0","1","1","0","0","1","1","0","1","0","1","1","0","0","0","1","1","0","0","1","1","0","1","0","1","1","0","0","1","0","1","0","1","0","0","1","1","0","1","0","0","0","0","0","0","1","1","0","1","1","0","1","0","1","0","1","0","1","0","0","0","1","0","1","1","1","1","1","1","1","0","1","1","1","1","0","0","0","1","0","1","0","1","0","1","0","1","0","1","1","1","1","1","0","0","1","0","1","0","1","1","0","0","1","0","0","1","0","1","0","0","0","1","1","0","0","0","0","0","0","0","1","0","1","1","1","1","1","0","0","0","0","1","0","1","1","0","0","1","0","0","0","1","0","0","1","0","0","0","0","0","1","0","1","0","1","0","1","0","0","0","0","1","0","1","1","0","1","0","1","0","1","1","1","0","0","1","0","1","1","0","1","0","1","1","0","1","1","1","1","0","0","0","1","0","0","1","1","1","0","1","1","0","0","1","0","1","0","0","0","1","0","1","1","1","0","1","1","0","1","0","0","0","1","1","1","0","0","0","0","1","0","1","1","1","0","0","1","0","1","1","1","1","1","0","0","0","0","1","0","1","1","1","0","1","1","0","1","0","0","0","0","1","1","0","0","1","1","0","1","1","0","1","1","1","1","1","1","1","0","1","0","0","1","0","0","0","0","0","0","1","0","0","1","0","0","0","1","0","1","1","0","0","0","0","1","1","0","0","1","1","1","0","1","0","1","1","1","1","0","1","1","1","1","1","0","1","1","0","0","0","1","1","1","1","0","1","1","0","0","1","1","0","0","0","0","1","1","1","0","1","0","1","0","1","0","1","1","1","1","0","1","1","0","1","0","1","0","0","0","1","1","1","1","1","0","1","1","1","1","1","1","0","1","1","1","1","1","1","0","1","0","0","1","1","1","1","0","0","0","0","0","1","0","0","0","0","0","1","1","1","0","0","0","0","1","0","1","0","0","1","0","0","1","0","1","0","0","1","0","0","0","1","1","1","0","0","1","1","0","1","1","0","0","1","0","0","1","0","0","1","1","1","1","0","1","1","0","0","1","0","1","0","1","0","0","1","0","0","0","0","1","1","1","0","0","0","1","1","0","0","1","1","0","0","1","0","0","1","0","0","0","1","1","1","0","1","0","0","1","0","0","0","0","1","0","0","1","1","1","1","0","1","0","0","0","1","1","1","0","0","0","1","1","1","1","0","1","1","0","0","1","1","0","0","0","1","0","1","0","1","0","1","0","0","0","1","0","0","0","0","0","353653291233496652974789","14184261804575928850438572","27980783900713761382960617","32798176988663623823299642","24628614730058518272809638","4698506783354809395092245","1","0","0","0","0","0","15245324883534822587230286","3613118522451456004432090","37045229678622908842622071","31141999397197068585721346","28593821578297621399252915","12982898439271292972717503","1","0","0","0","0","0","13861076619600403879782141","17457852633216534303005740","34346766925597499882745713","18402669294876713082582031","6469769464448506262355232","11721539248868291515973627","1","0","0","0","0","0","14292217207691996698268075","20019580450850385959104355","3387711416469135802610404","14984450927499831941126836","14432992455779652258975645","25752795238277255535926136","1","0","0","0","0","0","1323625930391934344325761","9456487816650436299198899","9550508386974556085414579","1917581696082629016785971","13293424310327992393915821","7525545143534518558005342","1","0","0","0","0","0","27787498886171177402749624","22140181715346129691246305","29406990148094542984276577","4584358160300934089254285","31731355952683156230801254","12892078131806800751171612","1","0","0","0","0","0","7782918947902117463331217","8133922812974422627926328","26459414664458888810892529","3932963101016921973919507","2259792442318509913064371","1002631952298913164019853","1","0","0","0","0","0","31741815235492205675035296","20031073936631467742253941","35069343166467859054191335","16972856028600828441930129","13452155336099616685933914","36303957799501330667546614","1","0","0","0","0","0"]
42 changes: 42 additions & 0 deletions generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json, os
print(os.getcwd())
fproof = open('generated/proof.json')
proof = json.load(fproof)
fpublic = open('generated/public.json')
public = json.load(fpublic)
fproof.close()
fpublic.close()

output = f"""// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {{Test, console2}} from "forge-std/Test.sol";
import {{Groth16Verifier}} from "../src/batchverifier.sol";

contract CounterTest is Test {{
Groth16Verifier public verifier;

function VerifierTest() public {{
uint256[2] memory pa;
uint256[2][2] memory pb;
uint256[2] memory pc;
uint256[{len(public)}] memory input;
"""

for i in range(2):
output += f" pa[{i}] = {proof['pi_a'][i]};\n"
for j in range(2):
output += f" pb[{i}][{j}] = {proof['pi_b'][i][j]};\n"
output += f" pc[{i}] = {proof['pi_c'][i]};\n"

for i in range(len(public)):
output += f" input[{i}] = {public[i]};\n"
output += """
require(verifier.verifyProof(pa,pb,pc,input),"Invalid proof");
}
}"""



out = open('forgeTest/test/batchverifier.t.sol', 'w')
out.write(output)