Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll dev 0807 #10

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d89f1d1
add bn254 scalar arith chip
kunxian-xia Apr 18, 2024
11bf5ad
refactor
kunxian-xia Apr 19, 2024
c926509
finish bn254-scalar-arith chip and add unit test
kunxian-xia Apr 23, 2024
30186b7
include entrypoint in unit test
kunxian-xia Apr 23, 2024
7bf8d1e
include bn254 scalar arith chip in riscv air
kunxian-xia Apr 24, 2024
52b5103
add selector
kunxian-xia Apr 24, 2024
3a6f21b
pass op through value not pointer and refine testcase
kunxian-xia Apr 24, 2024
a0afb44
add poseidon_bn254 example
kunxian-xia May 9, 2024
e769fb4
handle bn254 scalar add and mul separately
kunxian-xia May 16, 2024
89e1ec8
chore: update poseidon-base dep
kunxian-xia May 16, 2024
eb0fddd
reduce total cycles from 2M to 1.4M
kunxian-xia May 17, 2024
28b0bfb
reduce total cycles from 1.4M to 1M
kunxian-xia May 21, 2024
df2d65b
add log in runtime execution
kunxian-xia May 21, 2024
a293b1b
add mac
lightsing May 21, 2024
fb1c13f
add chip
lightsing May 22, 2024
15114bf
fix
lightsing May 22, 2024
c4e0ac3
fix & fmt
lightsing May 22, 2024
ee578f8
fix p3-baby-bear dep
lightsing May 22, 2024
6aaec72
remove add
lightsing May 22, 2024
6397a79
fix twirp & reqwest
lightsing May 22, 2024
c228ae3
add memcpy chip
lightsing Jun 6, 2024
9ee89cd
add eval_memory_access_slice
lightsing Jun 6, 2024
61b3431
update Cargo.lock
lightsing Jun 13, 2024
6ed60da
update Cargo.toml
lightsing Jun 13, 2024
6f5d81b
cleanup
lightsing Jun 13, 2024
a61929f
Merge remote-tracking branch 'scroll/main' into feat/poseidon_bn254
kunxian-xia Jun 13, 2024
7eb3efb
fix errors after merge upstream
kunxian-xia Jun 13, 2024
46cd5a9
Merge remote-tracking branch 'scroll/main' into feat/poseidon_bn254
kunxian-xia Jun 13, 2024
4da5a36
fix merge errors
kunxian-xia Jun 13, 2024
42be5d2
Merge remote-tracking branch 'scroll/feat/poseidon_bn254' into feat/m…
kunxian-xia Jun 13, 2024
e84c37c
Merge branch 'refs/heads/feat/poseidon_bn254' into feat/memcpy
lightsing Jun 14, 2024
003227d
Merge remote-tracking branch 'refs/remotes/scroll/feat/memcpy' into f…
lightsing Jun 14, 2024
8821135
fix upgrade
lightsing Jun 14, 2024
15cf7f1
use self-hosted runner for pr ci
kunxian-xia Jun 14, 2024
340d982
Merge remote-tracking branch 'scroll/dev' into feat/poseidon_bn254
kunxian-xia Jun 14, 2024
d455d69
self-hosted runner
kunxian-xia Jun 14, 2024
30d29bc
fix
kunxian-xia Jun 14, 2024
795eefc
Merge remote-tracking branch 'scroll/feat/poseidon_bn254' into feat/m…
kunxian-xia Jun 14, 2024
ec58b04
fix
kunxian-xia Jun 14, 2024
ad46cdf
update elf
kunxian-xia Jun 14, 2024
c7d0a5e
Merge pull request #2 from scroll-tech/feat/memcpy
kunxian-xia Jun 14, 2024
e755c43
Merge remote-tracking branch 'origin/main' into feat/poseidon_bn254
lispc Jun 27, 2024
1b558fe
use 0 as bn254 scalar nonce. FIX later
lispc Jun 27, 2024
1b8e677
Merge remote-tracking branch 'origin/main' into scroll-dev-0720
lispc Jul 20, 2024
d70246f
pass cargo check
lispc Jul 20, 2024
97cddcb
update SP1_CIRCUIT_VERSION and use native for gnark
lispc Jul 20, 2024
85dfdb4
fix NumWords::USIZE
lispc Jul 20, 2024
52febcc
Merge remote-tracking branch 'origin/main' into scroll-dev-0720
lispc Jul 23, 2024
187e723
fix syscall nonce
lispc Jul 24, 2024
3c6a63e
minor..
lispc Jul 24, 2024
2dddad4
separate mul mac
lispc Jul 24, 2024
cfc395d
more log
lispc Jul 25, 2024
d614a30
cache srs
lispc Jul 25, 2024
5b5cb73
try fix syscall nonce
lispc Jul 25, 2024
2e84640
expect none
lispc Jul 25, 2024
8c3a2dd
use syscall nonce 0 for scroll syscall
lispc Jul 25, 2024
8ff49ac
disable some logs
lispc Jul 26, 2024
0d28654
Merge remote-tracking branch 'origin/main' into scroll-dev-0803
lispc Aug 3, 2024
2664885
pass build
lispc Aug 3, 2024
5e39747
add compress instrument
lispc Aug 3, 2024
226bc0b
Merge remote-tracking branch 'origin/main' into scroll-dev-0807
lispc Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions core/src/cpu/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,29 @@ impl CpuChip {
}

// Write the syscall nonce.
ecall_cols.syscall_nonce = F::from_canonical_u32(
nonce_lookup
.get(&event.syscall_lookup_id)
.copied()
.unwrap_or_default(),
let syscall_nonce = nonce_lookup
.get(&event.syscall_lookup_id)
.copied()
.unwrap_or_default();
ecall_cols.syscall_nonce = F::from_canonical_u32(syscall_nonce);

// FIXME

if syscall_id == F::from_canonical_u32(SyscallCode::MEMCPY_32.syscall_id())
|| syscall_id == F::from_canonical_u32(SyscallCode::MEMCPY_64.syscall_id())
|| syscall_id == F::from_canonical_u32(SyscallCode::BN254_SCALAR_MAC.syscall_id())
|| syscall_id == F::from_canonical_u32(SyscallCode::BN254_SCALAR_MUL.syscall_id())
{
ecall_cols.syscall_nonce = F::from_canonical_u32(0);
}

/*
log::info!(
"populate_ecall syscall_lookup_id {} syscall_nonce {} syscall_id {syscall_id:?}",
event.syscall_lookup_id,
syscall_nonce
);
*/

is_halt = syscall_id == F::from_canonical_u32(SyscallCode::HALT.syscall_id());

Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ use stark::StarkGenericConfig;
/// This string should be updated whenever any step in verifying an SP1 proof changes, including
/// core, recursion, and plonk-bn254. This string is used to download SP1 artifacts and the gnark
/// docker image.
pub const SP1_CIRCUIT_VERSION: &str = "v1.1.0";
pub const SP1_CIRCUIT_VERSION: &str = "v1.1.0-scroll";
48 changes: 47 additions & 1 deletion core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,10 @@ impl<'a> Runtime<'a> {
let value = (memory_read_value).to_le_bytes()[(addr % 4) as usize];
a = ((value as i8) as i32) as u32;
memory_store_value = Some(memory_read_value);
//println!(
// "[clk: {}, pc: 0x{:x}] LB: {:?} <- {:x}",
// self.state.global_clk, self.state.pc, rd, a
//);
self.rw(rd, a);
}
Opcode::LH => {
Expand All @@ -693,6 +697,10 @@ impl<'a> Runtime<'a> {
};
a = ((value as i16) as i32) as u32;
memory_store_value = Some(memory_read_value);
//println!(
// "[clk: {}, pc: 0x{:x}] LH: {:?} <- {:x}",
// self.state.global_clk, self.state.pc, rd, a
//);
self.rw(rd, a);
}
Opcode::LW => {
Expand All @@ -702,6 +710,10 @@ impl<'a> Runtime<'a> {
}
a = memory_read_value;
memory_store_value = Some(memory_read_value);
//println!(
// "[clk: {}, pc: 0x{:x}] LW: {:?} <- {}",
// self.state.global_clk, self.state.pc, rd, a
//);
self.rw(rd, a);
}
Opcode::LBU => {
Expand Down Expand Up @@ -737,6 +749,10 @@ impl<'a> Runtime<'a> {
_ => unreachable!(),
};
memory_store_value = Some(value);
//println!(
// "[clk: {}, pc: 0x{:x}] SB 0x{:x} <- 0x{:x}",
// self.state.global_clk, pc, addr, value
//);
self.mw_cpu(align(addr), value, MemoryAccessPosition::Memory);
}
Opcode::SH => {
Expand All @@ -750,6 +766,10 @@ impl<'a> Runtime<'a> {
_ => unreachable!(),
};
memory_store_value = Some(value);
//println!(
// "[clk: {}, pc: 0x{:x}] SH 0x{:x} <- 0x{:x}",
// self.state.global_clk, pc, addr, value
//);
self.mw_cpu(align(addr), value, MemoryAccessPosition::Memory);
}
Opcode::SW => {
Expand All @@ -759,6 +779,10 @@ impl<'a> Runtime<'a> {
}
let value = a;
memory_store_value = Some(value);
//println!(
// "[clk: {}, pc: 0x{:x}] SW 0x{:x} <- 0x{:x}",
// self.state.global_clk, pc, addr, value
//);
self.mw_cpu(align(addr), value, MemoryAccessPosition::Memory);
}

Expand Down Expand Up @@ -842,9 +866,18 @@ impl<'a> Runtime<'a> {
.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);
precompile_rt.syscall_lookup_id = syscall_lookup_id;
log::trace!(
"[clk: {}, pc: 0x{:x}] ecall syscall_id=0x{:x}, b: 0x{:x}, c: 0x{:x}",
global_clk,
pc,
syscall_id,
b,
c,
);
let (precompile_next_pc, precompile_cycles, returned_exit_code) =
if let Some(syscall_impl) = syscall_impl {
// Executing a syscall optionally returns a value to write to the t0 register.
Expand Down Expand Up @@ -896,7 +929,20 @@ impl<'a> Runtime<'a> {
_ => (self.opts.split_opts.deferred_shift_threshold, 1),
};
let nonce = (((*syscall_count as usize) % threshold) * multiplier) as u32;
self.record.nonce_lookup.insert(syscall_lookup_id, nonce);
// FIXME
match syscall {
SyscallCode::BN254_SCALAR_MAC
| SyscallCode::BN254_SCALAR_MUL
| SyscallCode::MEMCPY_32
| SyscallCode::MEMCPY_64 => {}
_ => {
self.record.nonce_lookup.insert(syscall_lookup_id, nonce);
}
}

//log::info!(
// "execute_instruction {syscall:?} {syscall_count} {nonce} {syscall_lookup_id}"
//);
*syscall_count += 1;
}
Opcode::EBREAK => {
Expand Down
87 changes: 87 additions & 0 deletions core/src/runtime/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ use crate::cpu::CpuEvent;
use crate::runtime::MemoryInitializeFinalizeEvent;
use crate::runtime::MemoryRecordEnum;
use crate::stark::MachineRecord;
use crate::syscall::precompiles::bn254_scalar::Bn254FieldArithEvent;
use crate::syscall::precompiles::edwards::EdDecompressEvent;
use crate::syscall::precompiles::keccak256::KeccakPermuteEvent;
use crate::syscall::precompiles::sha256::{ShaCompressEvent, ShaExtendEvent};
use crate::syscall::precompiles::uint256::Uint256MulEvent;
use crate::syscall::precompiles::ECDecompressEvent;
use crate::syscall::precompiles::{ECAddEvent, ECDoubleEvent};
use crate::syscall::MemCopyEvent;
use crate::utils::SP1CoreOpts;

/// A record of the execution of a program.
Expand Down Expand Up @@ -84,6 +86,9 @@ pub struct ExecutionRecord {

pub bn254_double_events: Vec<ECDoubleEvent>,

pub bn254_scalar_mul_events: Vec<Bn254FieldArithEvent>,
pub bn254_scalar_mac_events: Vec<Bn254FieldArithEvent>,

pub k256_decompress_events: Vec<ECDecompressEvent>,

pub bls12381_add_events: Vec<ECAddEvent>,
Expand All @@ -98,6 +103,9 @@ pub struct ExecutionRecord {

pub bls12381_decompress_events: Vec<ECDecompressEvent>,

pub memcpy32_events: Vec<MemCopyEvent>,
pub memcpy64_events: Vec<MemCopyEvent>,

/// The public values.
pub public_values: PublicValues<u32, u32>,

Expand Down Expand Up @@ -195,6 +203,19 @@ impl MachineRecord for ExecutionRecord {
"bls12381_decompress_events".to_string(),
self.bls12381_decompress_events.len(),
);

stats.insert(
"bn254_scalar_mul_events".to_string(),
self.bn254_scalar_mul_events.len(),
);
stats.insert(
"bn254_scalar_mac_events".to_string(),
self.bn254_scalar_mac_events.len(),
);

stats.insert("memcpy32_events".to_string(), self.memcpy32_events.len());
stats.insert("memcpy64_events".to_string(), self.memcpy64_events.len());

stats.insert(
"memory_initialize_events".to_string(),
self.memory_initialize_events.len(),
Expand Down Expand Up @@ -251,6 +272,12 @@ impl MachineRecord for ExecutionRecord {
.append(&mut other.uint256_mul_events);
self.bls12381_decompress_events
.append(&mut other.bls12381_decompress_events);
self.bn254_scalar_mul_events
.append(&mut other.bn254_scalar_mul_events);
self.bn254_scalar_mac_events
.append(&mut other.bn254_scalar_mac_events);
self.memcpy32_events.append(&mut other.memcpy32_events);
self.memcpy64_events.append(&mut other.memcpy64_events);

if self.byte_lookups.is_empty() {
self.byte_lookups = std::mem::take(&mut other.byte_lookups);
Expand Down Expand Up @@ -278,6 +305,34 @@ impl MachineRecord for ExecutionRecord {
self.nonce_lookup.insert(event.lookup_id, i as u32);
});

/*
self.memcpy32_events
.iter()
.enumerate()
.for_each(|(i, event)| {
self.nonce_lookup.insert(event.lookup_id, i as u32);
});

self.memcpy64_events
.iter()
.enumerate()
.for_each(|(i, event)| {
self.nonce_lookup.insert(event.lookup_id, i as u32);
});

self.bn254_scalar_mul_events
.iter()
.enumerate()
.for_each(|(i, event)| {
self.nonce_lookup.insert(event.lookup_id, i as u32);
});
self.bn254_scalar_mac_events
.iter()
.enumerate()
.for_each(|(i, event)| {
self.nonce_lookup.insert(event.lookup_id, i as u32);
});
*/
self.bitwise_events
.iter()
.enumerate()
Expand Down Expand Up @@ -375,6 +430,10 @@ impl ExecutionRecord {
secp256k1_double_events: std::mem::take(&mut self.secp256k1_double_events),
bn254_add_events: std::mem::take(&mut self.bn254_add_events),
bn254_double_events: std::mem::take(&mut self.bn254_double_events),
bn254_scalar_mul_events: std::mem::take(&mut self.bn254_scalar_mul_events),
bn254_scalar_mac_events: std::mem::take(&mut self.bn254_scalar_mac_events),
memcpy32_events: std::mem::take(&mut self.memcpy32_events),
memcpy64_events: std::mem::take(&mut self.memcpy64_events),
bls12381_add_events: std::mem::take(&mut self.bls12381_add_events),
bls12381_double_events: std::mem::take(&mut self.bls12381_double_events),
sha_extend_events: std::mem::take(&mut self.sha_extend_events),
Expand Down Expand Up @@ -513,6 +572,34 @@ impl ExecutionRecord {
opts.deferred_shift_threshold,
last
);
split_events!(
self,
memcpy32_events,
shards,
opts.deferred_shift_threshold,
last
);
split_events!(
self,
memcpy64_events,
shards,
opts.deferred_shift_threshold,
last
);
split_events!(
self,
bn254_scalar_mul_events,
shards,
opts.deferred_shift_threshold,
last
);
split_events!(
self,
bn254_scalar_mac_events,
shards,
opts.deferred_shift_threshold,
last
);
split_events!(
self,
bls12381_decompress_events,
Expand Down
48 changes: 46 additions & 2 deletions core/src/runtime/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use std::sync::Arc;

use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use typenum::{U16, U32, U64, U8};

use crate::runtime::{Register, Runtime};
use crate::syscall::precompiles::bn254_scalar::{Bn254ScalarMacChip, Bn254ScalarMulChip};
use crate::syscall::precompiles::edwards::EdAddAssignChip;
use crate::syscall::precompiles::edwards::EdDecompressChip;
use crate::syscall::precompiles::keccak256::KeccakPermuteChip;
Expand All @@ -15,8 +17,9 @@ use crate::syscall::precompiles::weierstrass::WeierstrassAddAssignChip;
use crate::syscall::precompiles::weierstrass::WeierstrassDecompressChip;
use crate::syscall::precompiles::weierstrass::WeierstrassDoubleAssignChip;
use crate::syscall::{
SyscallCommit, SyscallCommitDeferred, SyscallEnterUnconstrained, SyscallExitUnconstrained,
SyscallHalt, SyscallHintLen, SyscallHintRead, SyscallVerifySP1Proof, SyscallWrite,
MemCopyChip, SyscallCommit, SyscallCommitDeferred, SyscallEnterUnconstrained,
SyscallExitUnconstrained, SyscallHalt, SyscallHintLen, SyscallHintRead, SyscallVerifySP1Proof,
SyscallWrite,
};
use crate::utils::ec::edwards::ed25519::{Ed25519, Ed25519Parameters};
use crate::utils::ec::weierstrass::bls12_381::Bls12381;
Expand Down Expand Up @@ -102,6 +105,18 @@ pub enum SyscallCode {

/// Executes the `BLS12381_DOUBLE` precompile.
BLS12381_DOUBLE = 0x00_00_01_1F,

/// Execute the `BN254_SCALAR_MUL` precompile.
BN254_SCALAR_MUL = 0x00_01_01_20,

/// Execute the `BN254_SCALAR_MAC` precompile.
BN254_SCALAR_MAC = 0x00_01_01_21,

/// Execute the `MEMCPY_32` precompile.
MEMCPY_32 = 0x00_00_01_30,

/// Execute the `MEMCPY_64` precompile.
MEMCPY_64 = 0x00_00_01_31,
}

impl SyscallCode {
Expand Down Expand Up @@ -131,6 +146,10 @@ impl SyscallCode {
0x00_00_00_F1 => SyscallCode::HINT_READ,
0x00_01_01_1D => SyscallCode::UINT256_MUL,
0x00_00_01_1C => SyscallCode::BLS12381_DECOMPRESS,
0x00_01_01_20 => SyscallCode::BN254_SCALAR_MUL,
0x00_01_01_21 => SyscallCode::BN254_SCALAR_MAC,
0x00_00_01_30 => SyscallCode::MEMCPY_32,
0x00_00_01_31 => SyscallCode::MEMCPY_64,
_ => panic!("invalid syscall number: {}", value),
}
}
Expand Down Expand Up @@ -338,6 +357,23 @@ pub fn default_syscall_map() -> HashMap<SyscallCode, Arc<dyn Syscall>> {
Arc::new(WeierstrassDecompressChip::<Bls12381>::with_lexicographic_rule()),
);
syscall_map.insert(SyscallCode::UINT256_MUL, Arc::new(Uint256MulChip::new()));
syscall_map.insert(
SyscallCode::BN254_SCALAR_MUL,
Arc::new(Bn254ScalarMulChip::new()),
);
syscall_map.insert(
SyscallCode::BN254_SCALAR_MAC,
Arc::new(Bn254ScalarMacChip::new()),
);

syscall_map.insert(
SyscallCode::MEMCPY_32,
Arc::new(MemCopyChip::<U8, U32>::new()),
);
syscall_map.insert(
SyscallCode::MEMCPY_64,
Arc::new(MemCopyChip::<U16, U64>::new()),
);

syscall_map
}
Expand Down Expand Up @@ -428,6 +464,14 @@ mod tests {
SyscallCode::BLS12381_DECOMPRESS => {
assert_eq!(code as u32, sp1_zkvm::syscalls::BLS12381_DECOMPRESS)
}
SyscallCode::BN254_SCALAR_MUL => {
assert_eq!(code as u32, sp1_zkvm::syscalls::BN254_SCALAR_MUL)
}
SyscallCode::BN254_SCALAR_MAC => {
assert_eq!(code as u32, sp1_zkvm::syscalls::BN254_SCALAR_MAC)
}
SyscallCode::MEMCPY_32 => todo!(),
SyscallCode::MEMCPY_64 => todo!(),
}
}
}
Expand Down
Loading
Loading