Skip to content

Commit

Permalink
Synthesizer is restored based on Ale-75, Playground is deleted from t…
Browse files Browse the repository at this point in the history
…his repository. Find Playground from the repo 'tokamak-zk-evm-playground'
  • Loading branch information
JehyukJang committed Feb 28, 2025
1 parent a19616c commit 05a9fd6
Show file tree
Hide file tree
Showing 138 changed files with 4,014 additions and 13,433 deletions.
629 changes: 333 additions & 296 deletions packages/backend/libs/src/group_structures/mod.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/backend/libs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod math;
pub mod polynomials;
pub mod vectors;
pub mod tools;
pub mod group_structures;
pub const s_max: usize = 256;
Expand Down
File renamed without changes.
44 changes: 43 additions & 1 deletion packages/backend/libs/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::cmp;
#[cfg(test)]
mod tests {
use super::*;
use crate::math::{DensePolynomialExt, BivariatePolynomial};
use crate::polynomials::{DensePolynomialExt, BivariatePolynomial};

// Helper function: Create a simple 2D polynomial
fn create_simple_polynomial() -> DensePolynomialExt {
Expand Down Expand Up @@ -460,4 +460,46 @@ mod tests {
}

// More tests can be added as needed
}

#[cfg(test)]
mod tests_vectors {
use icicle_bls12_381::curve::{ScalarField, ScalarCfg};
use icicle_core::traits::{Arithmetic, FieldConfig, FieldImpl, GenerateRandom};
use icicle_runtime::memory::{HostOrDeviceSlice, HostSlice};
use std::cmp;

use crate::vectors::{outer_product_two_vecs, point_mul_two_vecs};

macro_rules! scalar_vec {
( $( $x:expr ),* ) => {
vec![
$( ScalarField::from_u32($x) ),*
].into_boxed_slice()
};
}

#[test]
fn test_point_mul_two_vecs() {
let vec1 = scalar_vec![1, 2, 3];
let vec2 = scalar_vec![4, 5];
let vec3 = scalar_vec![2, 0, 2, 4];

let mut res = vec![ScalarField::zero(); 6].into_boxed_slice();
outer_product_two_vecs(&vec1, &vec2, &mut res);
println!("res : {:?}", res);

let mut res = vec![ScalarField::zero(); 6].into_boxed_slice();
outer_product_two_vecs(&vec2, &vec1, &mut res);
println!("res : {:?}", res);

let mut res = vec![ScalarField::zero(); 12].into_boxed_slice();
outer_product_two_vecs(&vec1, &vec3, &mut res);
println!("res : {:?}", res);

let mut res = vec![ScalarField::zero(); 8].into_boxed_slice();
outer_product_two_vecs(&vec3, &vec2, &mut res);
println!("res : {:?}", res);

}
}
2 changes: 1 addition & 1 deletion packages/backend/libs/src/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::math::{DensePolynomialExt, BivariatePolynomial};
use super::polynomials::{DensePolynomialExt, BivariatePolynomial};

use icicle_bls12_381::curve::{ScalarField, ScalarCfg};
use icicle_bls12_381::polynomials::DensePolynomial;
Expand Down
59 changes: 59 additions & 0 deletions packages/backend/libs/src/vectors/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use icicle_core::vec_ops::{VecOps, VecOpsConfig};
use icicle_bls12_381::curve::{ScalarCfg, ScalarField};
use icicle_core::traits::{Arithmetic, FieldConfig, FieldImpl, GenerateRandom};
use icicle_runtime::memory::{HostOrDeviceSlice, HostSlice, DeviceSlice, DeviceVec};

pub fn point_mul_two_vecs(lhs: &Box<[ScalarField]>, rhs: &Box<[ScalarField]>, res: &mut Box<[ScalarField]>){
if lhs.len() != rhs.len() || lhs.len() != res.len() {
panic!("Mismatch of sizes of vectors to be pointwise-multiplied");
}
let vec_ops_cfg = VecOpsConfig::default();
let lhs_buff = HostSlice::from_slice(lhs);
let rhs_buff = HostSlice::from_slice(rhs);
let res_buff = HostSlice::from_mut_slice(res);
ScalarCfg::mul(lhs_buff, rhs_buff, res_buff, &vec_ops_cfg).unwrap();
}

pub fn outer_product_two_vecs(col_vec: &Box<[ScalarField]>, row_vec: &Box<[ScalarField]>, res: &mut Box<[ScalarField]>){
if col_vec.len() * row_vec.len() != res.len() {
panic!("Mismatch of sizes of vectors to be outer-producted");
}

let col_len = col_vec.len();
let row_len = row_vec.len();

let vec_ops_cfg = VecOpsConfig::default();
let min_len = std::cmp::min(row_len, col_len);
let max_len = std::cmp::max(row_len, col_len);
let max_dir = if max_len == row_len {true } else {false};

let base_vec = if max_dir { row_vec } else { col_vec };

let mut res_untransposed = vec![ScalarField::zero(); res.len()].into_boxed_slice();
for ind in 0 .. min_len {
let scaler = if max_dir {col_vec[ind]} else {row_vec[ind]};
let scaler_vec = vec![scaler; max_len].into_boxed_slice();
let mut res_vec = vec![ScalarField::zero(); max_len].into_boxed_slice();
ScalarCfg::mul(
HostSlice::from_slice(&scaler_vec),
HostSlice::from_slice(&base_vec),
HostSlice::from_mut_slice(&mut res_vec),
&vec_ops_cfg
).unwrap();
res_untransposed[ind * max_len .. (ind + 1) * max_len].copy_from_slice(&res_vec);
}

if !max_dir {
let res_untranposed_buf = HostSlice::from_slice(&res_untransposed);
let res_buf = HostSlice::from_mut_slice(res);
ScalarCfg::transpose(
res_untranposed_buf,
min_len as u32,
max_len as u32,
res_buf,
&vec_ops_cfg).unwrap();
} else {
res.clone_from(&res_untransposed);
}

}
2 changes: 1 addition & 1 deletion packages/frontend/qap-compiler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/frontend/qap-compiler/scripts/compile.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#names=("bufferPrvInPubOut" "bufferPubInPrvOut" "bufferPrvInPrvOut" "ADD" "MUL" "SUB" "DIV" "SDIV" "MOD" "SMOD" "ADDMOD" "MULMOD" "EQ" "ISZERO" "SHL" "SHR" "LT" "GT" "NOT" "BYTE" "SAR" "SIGNEXTEND" "SLT" "SGT" "AND" "OR" "XOR" "DecToBit" "SubEXP")
names=("ADD" "MUL" "SUB")
names=("bufferPrvInPubOut" "bufferPubInPrvOut" "bufferPrvInPrvOut" "ADD" "MUL" "SUB" "DIV" "SDIV" "MOD" "SMOD" "ADDMOD" "MULMOD" "EQ" "ISZERO" "SHL" "SHR" "LT" "GT" "NOT" "BYTE" "SAR" "SIGNEXTEND" "SLT" "SGT" "AND" "OR" "XOR" "DecToBit" "SubEXP")
#names=("ADD" "MUL" "SUB")
CURVE_NAME="bls12381"

# get the directory of the script
Expand Down

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// s_D: The number of subcircuits in the library
export const setupParams =
{
"l": 0,
"l_D": 32,
"m_D": 1112,
"n": 1024,
"s_D": 3
"l": 512,
"l_D": 2560,
"m_D": 30774,
"n": 8192,
"s_D": 29
}

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/frontend/synthesizer/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"request": "launch",
"name": "Launch with tsx",
"runtimeExecutable": "tsx",
"program": "${workspaceFolder}/examples/erc20/ton-transfer.ts",
"program": "${workspaceFolder}/examples/erc20/usdc-transfer.ts",
"args": [],
"cwd": "${workspaceFolder}",
"skipFiles": ["<node_internals>/**"],
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/synthesizer/examples/erc20/usdt-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import { keccak256 } from 'ethereum-cryptography/keccak'
import { createEVM } from '../../src/constructors.js'
import { finalize } from '../../src/tokamak/core/finalize.js'
import { setupEVMFromCalldata } from "src/tokamak/utils/erc20EvmSetup.js"
import USDT_STORAGE_LAYOUT from "../../constants/storage-layouts/USDT.json" assert { type: "json" };
import USDT_CONTRACT from "../../constants/bytecodes/USDT.json" assert { type: "json" };
// import USDT_STORAGE_LAYOUT from "../../constants/storage-layouts/USDT.json" assert { type: "json" };
// import USDT_CONTRACT from "../../constants/bytecodes/USDT.json" assert { type: "json" };
import USDT_STORAGE_LAYOUT from "../../src/constants/storage-layouts/USDT.json" assert { type: "json" };
import USDT_CONTRACT from "../../src/constants/bytecodes/USDT.json" assert { type: "json" };


// USDT contract bytecode
const contractCode = USDT_CONTRACT.bytecode
Expand Down
Loading

0 comments on commit 05a9fd6

Please sign in to comment.