-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat (wip): wasm proving for plume sig
1 parent
2e8c8c9
commit c237b0e
Showing
6 changed files
with
138 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[target.wasm32-unknown-unknown] | ||
rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", "-C", "link-arg=--max-memory=4294967296"] | ||
|
||
[unstable] | ||
build-std = ["panic_abort", "std"] | ||
|
||
[build] | ||
target = "aarch64-apple-darwin" |
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
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 |
---|---|---|
@@ -1 +1,44 @@ | ||
pub mod plume; | ||
|
||
use std::{cell::RefCell, rc::Rc}; | ||
|
||
use halo2_base::{ | ||
gates::{circuit::builder::BaseCircuitBuilder, GateChip, GateInstructions}, | ||
halo2_proofs::halo2curves::bn256::Fr, | ||
}; | ||
use halo2_wasm::Halo2Wasm; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub struct MyCircuit { | ||
// Add whatever other chips you need here | ||
gate: GateChip<Fr>, | ||
builder: Rc<RefCell<BaseCircuitBuilder<Fr>>>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl MyCircuit { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(circuit: &Halo2Wasm) -> Self { | ||
let gate = GateChip::new(); | ||
MyCircuit { | ||
gate, | ||
builder: Rc::clone(&circuit.circuit), | ||
} | ||
} | ||
|
||
pub fn run(&mut self) { | ||
// Replace with your circuit, making sure to use `self.builder` | ||
let a = self | ||
.builder | ||
.borrow_mut() | ||
.main(0) | ||
.load_witness(Fr::from(1u64)); | ||
let b = self | ||
.builder | ||
.borrow_mut() | ||
.main(0) | ||
.load_witness(Fr::from(2u64)); | ||
self.gate.add(self.builder.borrow_mut().main(0), a, b); | ||
} | ||
} |
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,49 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>hello-wasm example</title> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import init, { | ||
initThreadPool, | ||
initPanicHook, | ||
Halo2Wasm, | ||
MyCircuit, | ||
} from "../pkg/plume_halo2.js"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
init().then(async () => { | ||
initPanicHook(); | ||
// await initThreadPool(2); | ||
console.log("WASM initialized"); | ||
const halo2wasm = new Halo2Wasm(); | ||
console.log("Halo2Wasm initialized"); | ||
const myCircuit = new MyCircuit(halo2wasm); | ||
console.log("MyCircuit initialized"); | ||
await myCircuit.run(); | ||
console.log("MyCircuit run"); | ||
const paramsPath = path.join(__dirname, "data", "params.bin"); | ||
console.log("paramsPath", paramsPath); | ||
let params = fs.readFile(filePath, (err, data) => { | ||
if (err) { | ||
console.error("Error reading file:", err); | ||
return; | ||
} | ||
|
||
const byteArray = Buffer.from(data); | ||
console.log("Read file:", byteArray); | ||
return byteArray; | ||
}); | ||
// await halo2wasm.loadParams(); | ||
// await halo2wasm.genVk(); | ||
// const vk = await halo2wasm.getVk(); | ||
// console.log("MyCircuit getVk", vk); | ||
// await halo2wasm.genPk(); | ||
// const pk = await halo2wasm.getPk(); | ||
// console.log("MyCircuit getPk", pk); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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,20 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
rm -rf pkg | ||
|
||
TARGET=$1 | ||
|
||
if [ "$TARGET" = "nodejs" ]; then | ||
wasm-pack build --release --target nodejs --out-dir pkg --no-default-features | ||
elif [ "$TARGET" = "web" ]; then | ||
wasm-pack build --release --target web --out-dir pkg | ||
else | ||
echo "Target must be either 'web' or 'nodejs'" | ||
exit 1 | ||
fi | ||
|
||
|
||
if [ "$TARGET" == "nodejs" ]; then | ||
sed -i '' "s/require('env')/{memory: new WebAssembly.Memory({initial: 100,maximum: 65536,shared: true,})}/g" pkg/index.js | ||
fi |