From 5f460c9f9cb66b12c613c5d407a6123b1df34b24 Mon Sep 17 00:00:00 2001 From: Augustin Villetard Date: Sun, 15 Dec 2024 14:36:04 +0900 Subject: [PATCH] rust/ts bindings --- tools/garaga_rs/src/wasm_bindings.rs | 13 +++++++++++++ .../groth16ContractGenerator/parsingUtils.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/garaga_rs/src/wasm_bindings.rs b/tools/garaga_rs/src/wasm_bindings.rs index dbae9eaf..d2455f36 100644 --- a/tools/garaga_rs/src/wasm_bindings.rs +++ b/tools/garaga_rs/src/wasm_bindings.rs @@ -276,6 +276,19 @@ pub fn get_groth16_calldata( Ok(groth16_calldata_js) } +#[wasm_bindgen] +pub fn get_risc0_constants() -> Result, JsValue> { + let (control_root, control_id) = crate::wasm_bindings::groth16::risc0_utils::get_risc0_constants(); + + // Convert BigUint values to JsValue + let result = vec![ + biguint_to_jsvalue(control_root), + biguint_to_jsvalue(control_id), + ]; + + Ok(result) +} + #[allow(dead_code)] #[cfg(test)] mod tests { diff --git a/tools/npm/garaga_ts/src/node/starknet/groth16ContractGenerator/parsingUtils.ts b/tools/npm/garaga_ts/src/node/starknet/groth16ContractGenerator/parsingUtils.ts index 5f884ebe..94295ae6 100644 --- a/tools/npm/garaga_ts/src/node/starknet/groth16ContractGenerator/parsingUtils.ts +++ b/tools/npm/garaga_ts/src/node/starknet/groth16ContractGenerator/parsingUtils.ts @@ -2,11 +2,11 @@ import { CURVES, CurveId, G1Point, G2Point, findValueInStringToCurveId } from ". import * as fs from 'fs'; import { bitLength, hexStringToBytes, modInverse, split128, toBigInt, toHexStr } from "../../hints/io"; import { createHash } from 'crypto'; +import { get_risc0_constants } from "../../../wasm/pkg/garaga_rs"; //https://github.com/risc0/risc0-ethereum/blob/main/contracts/src/groth16/ControlID.sol -const RISC0_CONTROL_ROOT = BigInt("0x8CDAD9242664BE3112ABA377C5425A4DF735EB1C6966472B561D2855932C0469"); -const RISC0_BN254_CONTROL_ID = BigInt("0x04446E66D300EB7FB45C9726BB53C793DDA407A62E9601618BB43C5C14657AC0"); +const [RISC0_CONTROL_ROOT, RISC0_BN254_CONTROL_ID] = get_risc0_constants(); const SYSTEM_STATE_ZERO_DIGEST = Uint8Array.from(Buffer.from( "A3ACC27117418996340B84E5A90F3EF4C49D22C79E44AAD822EC9C313E1EB8E2", "hex"