Skip to content

Commit

Permalink
fix blob padding
Browse files Browse the repository at this point in the history
  • Loading branch information
dongliangCai committed Mar 14, 2024
1 parent a08d7cc commit 2832275
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
46 changes: 23 additions & 23 deletions zkevm-circuits/src/blob_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<F: Field> BlobCircuit<F>{
}

let partial_blob_len = blob.len();
log::trace!("partial blob len{}", partial_blob_len);
log::trace!("partial blob len {}", partial_blob_len);
// === STEP 2: compute the barycentric formula ===
// spec reference:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/polynomial-commitments.md
Expand Down Expand Up @@ -292,12 +292,12 @@ impl<F: Field> BlobCircuit<F>{


for i in 0..partial_blob_len as usize {
let numinator_i = fp_chip.mul(ctx, &roots_of_unity_brp[i + self.index].clone(), &blob[i].clone());
let numinator_i = fp_chip.mul(ctx, &roots_of_unity_brp[i].clone(), &blob[i].clone());

let denominator_i_no_carry = fp_chip.sub_no_carry(
ctx,
&challenge_point_fp.clone(),
&roots_of_unity_brp[i + self.index].clone(),
&roots_of_unity_brp[i].clone(),
);
let denominator_i = fp_chip.carry_mod(ctx, &denominator_i_no_carry);
// avoid division by zero
Expand Down Expand Up @@ -340,26 +340,26 @@ impl<F: Field> BlobCircuit<F>{
// if challenge_point is a root of unity((0..self.index)or((self.index + partial_blob_len)..BLOB_WIDTH), then result = 0
// else result = barycentric_evaluation
// (0..self.index).chain((self.index + partial_blob_len)..BLOB_WIDTH)
for i in (0..self.index).chain((self.index + partial_blob_len)..BLOB_WIDTH) {
let denominator_i_no_carry = fp_chip.sub_no_carry(
ctx,
&challenge_point_fp.clone(),
&roots_of_unity_brp[i].clone(),
);
let denominator_i = fp_chip.carry_mod(ctx, &denominator_i_no_carry);
// avoid division by zero
// safe_denominator_i = denominator_i (denominator_i != 0)
// safe_denominator_i = 1 (denominator_i == 0)
let is_zero_denominator_i = fp_is_zero(ctx, &gate, &denominator_i);
let is_zero_denominator_i =
cross_field_load_private(ctx, &fp_chip, &fp_chip.range, &is_zero_denominator_i, &zero);
// update `cp_is_not_root_of_unity`
// cp_is_not_root_of_unity = 1 (initialize)
// cp_is_not_root_of_unity = 0 (denominator_i == 0)
let non_zero_denominator_i =
fp_chip.sub_no_carry(ctx, &one_fp.clone(), &is_zero_denominator_i.clone());
cp_is_not_root_of_unity = fp_chip.mul(ctx, &cp_is_not_root_of_unity, &non_zero_denominator_i);
}
// for i in (0..self.index).chain((self.index + partial_blob_len)..BLOB_WIDTH) {
// let denominator_i_no_carry = fp_chip.sub_no_carry(
// ctx,
// &challenge_point_fp.clone(),
// &roots_of_unity_brp[i].clone(),
// );
// let denominator_i = fp_chip.carry_mod(ctx, &denominator_i_no_carry);
// // avoid division by zero
// // safe_denominator_i = denominator_i (denominator_i != 0)
// // safe_denominator_i = 1 (denominator_i == 0)
// let is_zero_denominator_i = fp_is_zero(ctx, &gate, &denominator_i);
// let is_zero_denominator_i =
// cross_field_load_private(ctx, &fp_chip, &fp_chip.range, &is_zero_denominator_i, &zero);
// // update `cp_is_not_root_of_unity`
// // cp_is_not_root_of_unity = 1 (initialize)
// // cp_is_not_root_of_unity = 0 (denominator_i == 0)
// let non_zero_denominator_i =
// fp_chip.sub_no_carry(ctx, &one_fp.clone(), &is_zero_denominator_i.clone());
// cp_is_not_root_of_unity = fp_chip.mul(ctx, &cp_is_not_root_of_unity, &non_zero_denominator_i);
// }

let select_evaluation = fp_chip.mul(ctx, &barycentric_evaluation, &cp_is_not_root_of_unity);
let tmp_result = fp_chip.add_no_carry(ctx, &result, &select_evaluation);
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/blob_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ fn test_partial_blob_consistency(){

log::trace!("blob:{:?}", blob);

let index = 0;
let index = 50;
let omega = Fp::from(123).pow(&[(FP_S - 12) as u64, 0, 0, 0]);
let roots_of_unity: Vec<_> = (0..4096)
.map(|i| omega.pow(&[i as u64, 0, 0, 0]))
.collect();
let roots_of_unity_brp = bit_reversal_permutation(roots_of_unity);

//let challenge_point = roots_of_unity_brp[0];
let challenge_point = roots_of_unity_brp[0];
//let challenge_point = Fp::random(OsRng);
let challenge_point = Fp::from(128);
// let challenge_point = Fp::from(128);

let result = poly_eval_partial(blob.clone(), challenge_point, omega, index);

Expand Down

0 comments on commit 2832275

Please sign in to comment.