Skip to content

Commit

Permalink
fri fold runtime fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevjue committed Feb 19, 2024
1 parent 542e492 commit 307ddf0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
5 changes: 1 addition & 4 deletions core/src/runtime/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ pub fn default_syscall_map() -> HashMap<SyscallCode, Rc<dyn Syscall>> {
SyscallCode::BLAKE3_COMPRESS_INNER,
Rc::new(Blake3CompressInnerChip::new()),
);
syscall_map.insert(
SyscallCode::BLAKE3_COMPRESS_INNER,
Rc::new(FriFoldChip::new()),
);
syscall_map.insert(SyscallCode::FRI_FOLD, Rc::new(FriFoldChip::new()));
syscall_map.insert(
SyscallCode::ENTER_UNCONSTRAINED,
Rc::new(SyscallEnterUnconstrained::new()),
Expand Down
10 changes: 6 additions & 4 deletions core/src/syscall/precompiles/fri_fold/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use p3_baby_bear::BabyBear;
use p3_baby_bear::{from_monty, to_monty};
use p3_field::{
extension::BinomialExtensionField, AbstractExtensionField, AbstractField, PrimeField32,
};
Expand Down Expand Up @@ -59,10 +60,11 @@ impl Syscall for FriFoldChip {
let alpha_pow_address = output_addresses[1];

let (ro_read_records, ro_values) = rt.mr_slice(ro_address, 4);

let mut ro = BinomialExtensionField::<BabyBear, 4>::from_base_slice(
ro_values
.iter()
.map(|&x| BabyBear::from_canonical_u32(x))
.map(|&x| BabyBear::from_canonical_u32(from_monty(x)))
.collect::<Vec<_>>()
.as_slice(),
);
Expand All @@ -71,7 +73,7 @@ impl Syscall for FriFoldChip {
let mut alpha_pow = BinomialExtensionField::<BabyBear, 4>::from_base_slice(
alpha_values
.iter()
.map(|&x| BabyBear::from_canonical_u32(x))
.map(|&x| BabyBear::from_canonical_u32(from_monty(x)))
.collect::<Vec<_>>()
.as_slice(),
);
Expand All @@ -86,7 +88,7 @@ impl Syscall for FriFoldChip {
ro_address,
ro.as_base_slice()
.iter()
.map(|x: &BabyBear| x.as_canonical_u32())
.map(|x: &BabyBear| to_monty(x.as_canonical_u32()))
.collect::<Vec<_>>()
.as_slice(),
);
Expand All @@ -95,7 +97,7 @@ impl Syscall for FriFoldChip {
alpha_pow
.as_base_slice()
.iter()
.map(|x: &BabyBear| x.as_canonical_u32())
.map(|x: &BabyBear| to_monty(x.as_canonical_u32()))
.collect::<Vec<_>>()
.as_slice(),
);
Expand Down
2 changes: 1 addition & 1 deletion zkvm/src/syscalls/fri_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::arch::asm;
/// The result is written to the addresses in the output mem entries.
#[allow(unused_variables)]
#[no_mangle]
pub extern "C" fn syscall_fri_fold(input_mem_ptr: *mut u32, output_mem_ptr: *mut u32) {
pub extern "C" fn syscall_fri_fold(input_mem_ptr: *const u32, output_mem_ptr: *const *mut u32) {
#[cfg(target_os = "zkvm")]
unsafe {
asm!(
Expand Down
3 changes: 3 additions & 0 deletions zkvm/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ mod blake3_compress;
#[cfg(not(feature = "interface"))]
mod ed25519;
#[cfg(not(feature = "interface"))]
mod fri_fold;
#[cfg(not(feature = "interface"))]
mod halt;
#[cfg(not(feature = "interface"))]
mod io;
Expand All @@ -24,6 +26,7 @@ mod unconstrained;
#[cfg(not(feature = "interface"))]
mod syscall_def {
pub use super::ed25519::*;
pub use super::fri_fold::*;
pub use super::halt::*;
pub use super::io::*;
pub use super::keccak_permute::*;
Expand Down

0 comments on commit 307ddf0

Please sign in to comment.