Skip to content

Commit

Permalink
fix merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Jun 13, 2024
1 parent 46cd5a9 commit 4da5a36
Show file tree
Hide file tree
Showing 6 changed files with 1,059 additions and 588 deletions.
2 changes: 1 addition & 1 deletion core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ impl Runtime {
.or_insert(1);
}

let global_clk = self.state.global_clk;
let syscall_impl = self.get_syscall(syscall).cloned();
let mut precompile_rt = SyscallContext::new(self);

let global_clk = self.state.global_clk;
log::debug!(
"[clk: {}, pc: 0x{:x}] ecall syscall_id=0x{:x}, b: 0x{:x}, c: 0x{:x}",
global_clk,
Expand Down
41 changes: 33 additions & 8 deletions core/src/syscall/precompiles/bn254_scalar/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const OP: Bn254FieldOperation = Bn254FieldOperation::Mac;
pub struct Bn254ScalarMacCols<T> {
is_real: T,
shard: T,
channel: T,
clk: T,
arg1_ptr: T,
arg2_ptr: T,
Expand Down Expand Up @@ -95,41 +96,52 @@ impl<F: PrimeField32> MachineAir<F> for Bn254ScalarMacChip {

cols.is_real = F::one();
cols.shard = F::from_canonical_u32(event.shard);
cols.channel = F::from_canonical_u32(event.channel);
cols.clk = F::from_canonical_u32(event.clk);
cols.arg1_ptr = F::from_canonical_u32(event.arg1.ptr);
cols.arg2_ptr = F::from_canonical_u32(event.arg2.ptr);

let mul = cols.mul_eval.populate(
&mut new_byte_lookup_events,
event.shard,
event.channel,
&a,
&b,
FieldOperation::Mul,
);
cols.add_eval.populate(
&mut new_byte_lookup_events,
event.shard,
event.channel,
&arg1,
&mul,
FieldOperation::Add,
);

for i in 0..cols.arg1_access.len() {
cols.arg1_access[i]
.populate(event.arg1.memory_records[i], &mut new_byte_lookup_events);
cols.arg1_access[i].populate(
event.channel,
event.arg1.memory_records[i],
&mut new_byte_lookup_events,
);
}
for i in 0..cols.arg2_access.len() {
cols.arg2_access[i]
.populate(event.arg2.memory_records[i], &mut new_byte_lookup_events);
cols.arg2_access[i].populate(
event.channel,
event.arg2.memory_records[i],
&mut new_byte_lookup_events,
);
}
for i in 0..cols.a_access.len() {
cols.a_access[i].populate(
event.channel,
event.a.as_ref().unwrap().memory_records[i],
&mut new_byte_lookup_events,
);
}
for i in 0..cols.b_access.len() {
cols.b_access[i].populate(
event.channel,
event.b.as_ref().unwrap().memory_records[i],
&mut new_byte_lookup_events,
);
Expand All @@ -145,9 +157,9 @@ impl<F: PrimeField32> MachineAir<F> for Bn254ScalarMacChip {

let zero = BigUint::zero();
cols.mul_eval
.populate(&mut vec![], 0, &zero, &zero, FieldOperation::Mul);
.populate(&mut vec![], 0, 0, &zero, &zero, FieldOperation::Mul);
cols.add_eval
.populate(&mut vec![], 0, &zero, &zero, FieldOperation::Add);
.populate(&mut vec![], 0, 0, &zero, &zero, FieldOperation::Add);

row
});
Expand Down Expand Up @@ -190,14 +202,22 @@ where
let b: Limbs<<AB as AirBuilder>::Var, <Bn254ScalarField as NumLimbs>::Limbs> =
limbs_from_prev_access(&row.b_access);

row.mul_eval
.eval(builder, &a, &b, FieldOperation::Mul, row.shard, row.is_real);
row.mul_eval.eval(
builder,
&a,
&b,
FieldOperation::Mul,
row.shard,
row.channel,
row.is_real,
);
row.add_eval.eval(
builder,
&arg1,
&row.mul_eval.result,
FieldOperation::Add,
row.shard,
row.channel,
row.is_real,
);

Expand All @@ -210,6 +230,7 @@ where

builder.eval_memory_access_slice(
row.shard,
row.channel,
row.clk.into(),
row.arg1_ptr,
&row.arg1_access,
Expand All @@ -218,6 +239,7 @@ where

builder.eval_memory_access_slice(
row.shard,
row.channel,
row.clk.into(),
row.arg2_ptr,
&row.arg2_access,
Expand All @@ -244,6 +266,7 @@ where

builder.eval_memory_access_slice(
row.shard,
row.channel,
row.clk.into(),
a_ptr,
&row.a_access,
Expand All @@ -252,6 +275,7 @@ where

builder.eval_memory_access_slice(
row.shard,
row.channel,
row.clk.into(),
b_ptr,
&row.b_access,
Expand All @@ -261,6 +285,7 @@ where
let syscall_id = AB::F::from_canonical_u32(SyscallCode::BN254_SCALAR_MAC.syscall_id());
builder.receive_syscall(
row.shard,
row.channel,
row.clk,
syscall_id,
row.arg1_ptr,
Expand Down
2 changes: 2 additions & 0 deletions core/src/syscall/precompiles/bn254_scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Bn254FieldOperation {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Bn254FieldArithEvent {
pub shard: u32,
pub channel: u32,
pub clk: u32,
pub op: Bn254FieldOperation,
pub arg1: FieldArithMemoryAccess<MemoryWriteRecord>,
Expand Down Expand Up @@ -158,6 +159,7 @@ pub fn create_bn254_scalar_arith_event(
let shard = rt.current_shard();
Bn254FieldArithEvent {
shard,
channel: rt.current_channel(),
clk: start_clk,
op,
arg1,
Expand Down
23 changes: 18 additions & 5 deletions core/src/syscall/precompiles/bn254_scalar/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const OP: Bn254FieldOperation = Bn254FieldOperation::Mul;
pub struct Bn254ScalarMulCols<T> {
is_real: T,
shard: T,
channel: T,
clk: T,
p_ptr: T,
q_ptr: T,
Expand Down Expand Up @@ -90,25 +91,33 @@ impl<F: PrimeField32> MachineAir<F> for Bn254ScalarMulChip {

cols.is_real = F::one();
cols.shard = F::from_canonical_u32(event.shard);
cols.channel = F::from_canonical_u32(event.channel);
cols.clk = F::from_canonical_u32(event.clk);
cols.p_ptr = F::from_canonical_u32(event.arg1.ptr);
cols.q_ptr = F::from_canonical_u32(event.arg2.ptr);

cols.eval.populate(
&mut new_byte_lookup_events,
event.shard,
event.channel,
&p,
&q,
OP.to_field_operation(),
);

for i in 0..cols.p_access.len() {
cols.p_access[i]
.populate(event.arg1.memory_records[i], &mut new_byte_lookup_events);
cols.p_access[i].populate(
event.channel,
event.arg1.memory_records[i],
&mut new_byte_lookup_events,
);
}
for i in 0..cols.q_access.len() {
cols.q_access[i]
.populate(event.arg2.memory_records[i], &mut new_byte_lookup_events);
cols.q_access[i].populate(
event.channel,
event.arg2.memory_records[i],
&mut new_byte_lookup_events,
);
}

rows.push(row);
Expand All @@ -121,7 +130,7 @@ impl<F: PrimeField32> MachineAir<F> for Bn254ScalarMulChip {

let zero = BigUint::zero();
cols.eval
.populate(&mut vec![], 0, &zero, &zero, OP.to_field_operation());
.populate(&mut vec![], 0, 0, &zero, &zero, OP.to_field_operation());

row
});
Expand Down Expand Up @@ -168,6 +177,7 @@ where
&q,
OP.to_field_operation(),
row.shard,
row.channel,
row.is_real,
);

Expand All @@ -179,6 +189,7 @@ where

builder.eval_memory_access_slice(
row.shard,
row.channel,
row.clk.into(),
row.q_ptr,
&row.q_access,
Expand All @@ -187,6 +198,7 @@ where

builder.eval_memory_access_slice(
row.shard,
row.channel,
row.clk.into(),
row.p_ptr,
&row.p_access,
Expand All @@ -196,6 +208,7 @@ where
let syscall_id = AB::F::from_canonical_u32(SyscallCode::BN254_SCALAR_MUL.syscall_id());
builder.receive_syscall(
row.shard,
row.channel,
row.clk,
syscall_id,
row.p_ptr,
Expand Down
Binary file modified examples/poseidon_bn254/program/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Loading

0 comments on commit 4da5a36

Please sign in to comment.