Skip to content

Commit

Permalink
Progress towards making zkp field-agnostic (risc0#238)
Browse files Browse the repository at this point in the history
* Define "field::Elem" and "field::ExtElem" types
* Add test_roots_of_unity and test_field_ops test utils to run basic tests on fields (It sounds like kalen and @tzerell will be working more on tests and documentation)
* Rename baby bear field (15*2^27) from {Fp, Fp4} to field::baby_bear::{Elem, ExtElem}; Fp and Fp4 are now aliases
* Change a bunch of Fp and Fp4 calls to use trait items.
* Remove Fp::invalid, so we don't have to keep this complication for all our fields. (and we weren't using it in rust anyways)
  • Loading branch information
shkoo authored Aug 17, 2022
1 parent e0e39ed commit 09c3292
Show file tree
Hide file tree
Showing 21 changed files with 798 additions and 639 deletions.
3 changes: 2 additions & 1 deletion risc0/zkp/rust/benches/ntt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rand::thread_rng;
use risc0_zkp::core::{fp::Fp, ntt::interpolate_ntt, Random};
use risc0_zkp::core::{fp::Fp, ntt::interpolate_ntt};
use risc0_zkp::field::Elem;

pub fn ntt(c: &mut Criterion) {
let mut group = c.benchmark_group("interpolate_ntt");
Expand Down
5 changes: 3 additions & 2 deletions risc0/zkp/rust/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use anyhow::{bail, Result};

use crate::{
core::{fp::Fp, fp4::Fp4},
field::Elem,
taps::TapSet,
INV_RATE,
};
Expand Down Expand Up @@ -55,7 +56,7 @@ impl CircuitStepContext {

pub fn _set(&self, base: &mut [Fp], value: Fp, offset: usize, _loc: &str) {
let reg = &mut base[offset * self.size + self.cycle];
assert!(*reg == Fp::invalid() || *reg == Fp::new(0) || *reg == value);
assert!(*reg == Fp::new(0) || *reg == value);
*reg = value;
}

Expand Down Expand Up @@ -322,7 +323,7 @@ impl CircuitStep {
CircuitStep::Set(base, value, offset, _loc) => {
let value = stack[*value];
let reg = &mut args[*base][offset * ctx.size + ctx.cycle];
assert!(*reg == Fp::invalid() || *reg == Fp::new(0) || *reg == value);
assert!(*reg == Fp::ZERO || *reg == value);
*reg = value;
}
CircuitStep::GetGlobal(base, offset, _loc) => {
Expand Down
259 changes: 0 additions & 259 deletions risc0/zkp/rust/src/core/fp.rs

This file was deleted.

Loading

0 comments on commit 09c3292

Please sign in to comment.