Skip to content

Commit

Permalink
fix fp2 chip adapter blocks (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
luffykai authored Nov 6, 2024
1 parent 58d2f5a commit eb46470
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 6 additions & 6 deletions vm/src/arch/chip_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use parking_lot::Mutex;
use program::DEFAULT_PC_STEP;
use strum::EnumCount;

use super::{vm_poseidon2_config, EcCurve, Streams};
use super::{vm_poseidon2_config, EcCurve, PairingCurve, Streams};
use crate::{
arch::{AxVmChip, AxVmExecutor, ExecutionBus, ExecutorName, VmConfig},
intrinsics::{
Expand Down Expand Up @@ -1019,7 +1019,7 @@ impl VmConfig {
}
ExecutorName::Fp2AddSubRv32_32 => {
let chip = Rc::new(RefCell::new(Fp2AddSubChip::new(
Rv32VecHeapAdapterChip::<F, 2, 1, 1, 32, 32>::new(
Rv32VecHeapAdapterChip::<F, 2, 2, 2, 32, 32>::new(
execution_bus,
program_bus,
memory_controller.clone(),
Expand All @@ -1034,7 +1034,7 @@ impl VmConfig {
}
ExecutorName::Fp2MulDivRv32_32 => {
let chip = Rc::new(RefCell::new(Fp2MulDivChip::new(
Rv32VecHeapAdapterChip::<F, 2, 1, 1, 32, 32>::new(
Rv32VecHeapAdapterChip::<F, 2, 2, 2, 32, 32>::new(
execution_bus,
program_bus,
memory_controller.clone(),
Expand All @@ -1049,7 +1049,7 @@ impl VmConfig {
}
ExecutorName::Fp2AddSubRv32_48 => {
let chip = Rc::new(RefCell::new(Fp2AddSubChip::new(
Rv32VecHeapAdapterChip::<F, 2, 3, 3, 16, 16>::new(
Rv32VecHeapAdapterChip::<F, 2, 6, 6, 16, 16>::new(
execution_bus,
program_bus,
memory_controller.clone(),
Expand All @@ -1064,7 +1064,7 @@ impl VmConfig {
}
ExecutorName::Fp2MulDivRv32_48 => {
let chip = Rc::new(RefCell::new(Fp2MulDivChip::new(
Rv32VecHeapAdapterChip::<F, 2, 3, 3, 16, 16>::new(
Rv32VecHeapAdapterChip::<F, 2, 6, 6, 16, 16>::new(
execution_bus,
program_bus,
memory_controller.clone(),
Expand Down Expand Up @@ -1325,7 +1325,7 @@ fn gen_ec_executor_tuple(

// Returns (local_opcode_idx, global offset, executor name, modulus)
fn gen_pairing_executor_tuple(
supported_ec_curves: &[EcCurve],
supported_ec_curves: &[PairingCurve],
) -> Vec<(usize, usize, ExecutorName, BigUint)> {
supported_ec_curves
.iter()
Expand Down
8 changes: 4 additions & 4 deletions vm/src/arch/chips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ pub enum AxVmExecutor<F: PrimeField32> {
EcDoubleRv32_6x16(Rc<RefCell<EcDoubleChip<F, 6, 16>>>),
// Pairing:
// Fp2 for 32-bytes or 48-bytes prime.
Fp2AddSubRv32_32(Rc<RefCell<Fp2AddSubChip<F, 1, 32>>>),
Fp2AddSubRv32_48(Rc<RefCell<Fp2AddSubChip<F, 3, 16>>>),
Fp2MulDivRv32_32(Rc<RefCell<Fp2MulDivChip<F, 1, 32>>>),
Fp2MulDivRv32_48(Rc<RefCell<Fp2MulDivChip<F, 3, 16>>>),
Fp2AddSubRv32_32(Rc<RefCell<Fp2AddSubChip<F, 2, 32>>>),
Fp2AddSubRv32_48(Rc<RefCell<Fp2AddSubChip<F, 6, 16>>>),
Fp2MulDivRv32_32(Rc<RefCell<Fp2MulDivChip<F, 2, 32>>>),
Fp2MulDivRv32_48(Rc<RefCell<Fp2MulDivChip<F, 6, 16>>>),
/// Only for BN254 for now
EcLineMul013By013(Rc<RefCell<EcLineMul013By013Chip<F, 4, 10, 32>>>),
/// Only for BN254 for now
Expand Down
19 changes: 17 additions & 2 deletions vm/src/arch/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct VmConfig {
/// List of all supported EC curves
pub supported_ec_curves: Vec<EcCurve>,
/// List of all supported pairing curves
pub supported_pairing_curves: Vec<EcCurve>,
pub supported_pairing_curves: Vec<PairingCurve>,

pub poseidon2_max_constraint_degree: usize,
/// True if the VM is in continuation mode. In this mode, an execution could be segmented and
Expand Down Expand Up @@ -86,7 +86,7 @@ impl VmConfig {
// Come from CompilerOptions. We can also pass in the whole compiler option if we need more fields from it.
supported_modulus: Vec<BigUint>,
supported_ec_curves: Vec<EcCurve>,
supported_pairing_curves: Vec<EcCurve>,
supported_pairing_curves: Vec<PairingCurve>,
) -> Self {
VmConfig {
executors: Vec::new(),
Expand Down Expand Up @@ -263,3 +263,18 @@ impl EcCurve {
}
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum PairingCurve {
Bn254,
Bls12_381,
}

impl PairingCurve {
pub fn prime(&self) -> BigUint {
match self {
PairingCurve::Bn254 => BN254.MODULUS.clone(),
PairingCurve::Bls12_381 => BLS12381.MODULUS.clone(),
}
}
}

0 comments on commit eb46470

Please sign in to comment.