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-0914 -> v3.0.0-rc3 #18

Draft
wants to merge 214 commits into
base: upstream/v3.0.0-rc3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
214 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
0e573c1
collect the local memory events
kevjue Aug 9, 2024
97ae8c7
better naming
kevjue Aug 9, 2024
37d8815
implemented machineair for memory local chip
kevjue Aug 9, 2024
235ffda
empy eval
kevjue Aug 9, 2024
9c6ef80
moved MemoryChipType enum to mod.rs
kevjue Aug 9, 2024
031f2b8
added tests
kevjue Aug 9, 2024
cb2c0a8
Merge branch 'dev' into kevjue/phase_1_improvements
kevjue Aug 9, 2024
1a2a6e9
some fixes
kevjue Aug 9, 2024
c1451e1
added local memory chips to the risc-v machine
kevjue Aug 9, 2024
4c46cbc
added interaction scope
kevjue Aug 9, 2024
9d538a3
renamed MessageScope to InteractionScope
kevjue Aug 9, 2024
e47d52a
changes to the prover
kevjue Aug 9, 2024
060282d
handled two different cumulative sums
kevjue Aug 9, 2024
5c4a435
debug folder changres
kevjue Aug 10, 2024
b7bedfd
core prover and verifier changes compile
kevjue Aug 12, 2024
f535214
recursion compiles
kevjue Aug 12, 2024
7846ade
core verification works
kevjue Aug 13, 2024
9555ae7
things compile
kevjue Aug 13, 2024
b7671aa
fixed some bugs
kevjue Aug 13, 2024
e2cdc49
local memory checks
kevjue Aug 14, 2024
b9ebca4
local mem event
kevjue Aug 14, 2024
b2a2636
ssz_withdrawal works!
kevjue Aug 15, 2024
cdfb891
tendermint compiles
kevjue Aug 15, 2024
b904c03
ssz_withdrawal working with byte lookup migration
kevjue Aug 16, 2024
2acb408
tendermint works!
kevjue Aug 16, 2024
3ce0c20
added program memory to phase 1
kevjue Aug 16, 2024
592118b
remote plonky3 dependencies
kevjue Aug 17, 2024
a268004
some cleanup
kevjue Aug 19, 2024
7b04460
big cleanuip
kevjue Aug 20, 2024
940ef24
fixed typo
kevjue Aug 21, 2024
c950e99
fixed permutation width bug
kevjue Aug 23, 2024
a7575cf
fixes
kevjue Aug 23, 2024
09c7563
removed unnecessary constraints
kevjue Aug 23, 2024
84dcba3
add some more logs
kevjue Aug 25, 2024
8bad4a2
more logging
kevjue Aug 25, 2024
6dfc22b
changes dependencies
kevjue Aug 25, 2024
19e8ca0
remove generate_dependencies for phase 1
kevjue Aug 26, 2024
3fdafea
more logging
kevjue Aug 26, 2024
83f0580
removed shard column from byte table
kevjue Aug 27, 2024
90c663c
added precompile blus for weierstrass precompiles
kevjue Aug 27, 2024
b6f5f0e
merged dev and things compile
kevjue Aug 28, 2024
835e1f9
some fixes
kevjue Aug 28, 2024
dfa91a3
initial changes to get the verifier to work
kevjue Aug 29, 2024
956c3ab
Merge tag 'v1.2.0-rc2' into scroll-v1.2.0-rc2
lispc Aug 30, 2024
5506551
added syscall table
kevjue Aug 30, 2024
2180d3e
merged dev
kevjue Aug 30, 2024
955657a
build
lispc Aug 30, 2024
b68b0cd
fix syscall id
lispc Aug 30, 2024
b5c7c48
fix syscall id
lispc Aug 30, 2024
0329f4e
fix syscall id
lispc Aug 30, 2024
fae481d
changes in core prover for phase 2 chip split
kevjue Aug 31, 2024
7ada5f0
Merge branch 'dev' into kevjue/phase_1_improvements
kevjue Aug 31, 2024
e701bd8
core verification works
kevjue Sep 1, 2024
fc87eab
changes for moongate
kevjue Sep 1, 2024
1d8d49a
better cumulative sum error
kevjue Sep 2, 2024
825ca91
fixed bug
kevjue Sep 2, 2024
36da046
some fixes
kevjue Sep 2, 2024
d216ec2
changes for recursion
kevjue Sep 3, 2024
741285d
changes to recursion verify_shard
kevjue Sep 3, 2024
36da109
compress prover compiles
kevjue Sep 3, 2024
3cad40e
recursive runtime for first shard runs fine
kevjue Sep 3, 2024
0411471
Merge branch 'dev' into kevjue/phase_1_improvements
kevjue Sep 3, 2024
92bb37c
some fixes for the recursion compress proof gen
kevjue Sep 4, 2024
9332c76
Merge tag 'v1.2.0' into scroll-dev-0830
lispc Sep 4, 2024
2dc19b9
rebase from v1.3.0-rc2
kevjue Sep 4, 2024
bcacff6
removed file
kevjue Sep 4, 2024
359b6ce
compressed proof generated but fails verification
kevjue Sep 4, 2024
1fb8b72
compressed proofs work
kevjue Sep 4, 2024
8c52a11
merged latest v1.3.0-rc2
kevjue Sep 4, 2024
c1705f3
got wrap working
kevjue Sep 4, 2024
1dfd8f7
added some comments
kevjue Sep 5, 2024
80bd31d
some cleanup
kevjue Sep 5, 2024
5296cac
more cleanup
kevjue Sep 5, 2024
ed78d05
revert some changes in the recursion crate
kevjue Sep 5, 2024
f1383fc
exclude recursion/circuit and recursion/program
kevjue Sep 5, 2024
172bf5c
reverted recursion/circuit and recursion/program directories
kevjue Sep 5, 2024
9c86c02
fixed unit test
kevjue Sep 5, 2024
e39a4dc
fixed a warning
kevjue Sep 5, 2024
f159b55
merged latest v1.3.0-rc2
kevjue Sep 5, 2024
eb74090
Merge branch 'tamir/v1.3.0-rc2' into kevjue/phase_1_improvements
kevjue Sep 5, 2024
98e19d2
generate_dependencies after record.split
kevjue Sep 5, 2024
17f73db
remove unneeded clippy allow
kevjue Sep 5, 2024
87f290a
changes for moongate
kevjue Sep 6, 2024
55f0b92
add debug feature to prover crate
lispc Sep 6, 2024
3c86e33
Merge branch 'tamir/v1.3.0-rc2' into kevjue/phase_1_improvements
kevjue Sep 6, 2024
ffba4c3
big cleanup of the local memory for syscalls
kevjue Sep 6, 2024
34b3b81
minimize diff
kevjue Sep 6, 2024
262cae5
more cleanup
kevjue Sep 6, 2024
02e505a
cleaned up generate trace/dependencies for local memory table
kevjue Sep 6, 2024
a7c4564
generate dependencies for all chips
kevjue Sep 7, 2024
bd600e4
merged v1.3.0-rc2
kevjue Sep 7, 2024
ed06156
fix merge issue
kevjue Sep 7, 2024
a251d6b
fixed unit tests and formatting
kevjue Sep 7, 2024
fd11b44
restore the examples
kevjue Sep 7, 2024
b90a7f8
fix crates/core/machine/src/riscv/mod.rs
lispc Sep 8, 2024
8db9e57
fix CostEstimator
lispc Sep 8, 2024
6c80f61
check for byte multiplicies in the rust verifier
kevjue Sep 8, 2024
39670dd
added byte multiplicies overflow check in recursion circuit
kevjue Sep 8, 2024
6d3e066
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Sep 9, 2024
41be899
1.3.0-rc3
lispc Sep 9, 2024
cb77447
cleanup
kevjue Sep 9, 2024
4d77bc1
Merge branch 'tamir/v1.3.0-rc2' into kevjue/phase_1_improvements
kevjue Sep 9, 2024
3b8c445
some cleanup
kevjue Sep 10, 2024
b2f871b
Merge branch 'tamir/v1.3.0-rc2' into kevjue/phase_1_improvements
kevjue Sep 10, 2024
f72c35f
feat: generate dependencies cleanup (#1498)
kevjue Sep 14, 2024
7ed65a2
some clean up
kevjue Sep 14, 2024
175afa0
more cleanup
kevjue Sep 14, 2024
13403cf
Merge remote-tracking branch 'origin/kevjue/phase_1_improvements' int…
lispc Sep 14, 2024
4ece415
last clippy issue
kevjue Sep 14, 2024
bf69f54
some cleanup
kevjue Sep 14, 2024
7fa84e7
build
lispc Sep 14, 2024
9b9b512
clean tests
lispc Sep 14, 2024
d8e89a4
Merge remote-tracking branch 'scroll/kevjue/phase_1_improvements' int…
lispc Sep 14, 2024
80dd262
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Sep 18, 2024
44d17cf
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Sep 21, 2024
613a7d7
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Sep 22, 2024
6e1ca7d
add gpu prover check
lispc Sep 22, 2024
2774faa
fix(cuda-prover): dont discard stderr
lispc Sep 18, 2024
38dba2d
cpu wrap bn254
lispc Sep 22, 2024
e9684f0
change syscall code
lispc Sep 23, 2024
768a3e4
syscall lint and fix
lispc Sep 23, 2024
db3743a
update memcpy.s
lightsing Sep 23, 2024
e59735a
Merge remote-tracking branch 'scroll/scroll-dev-0914' into scroll-dev…
lightsing Sep 23, 2024
09fb4c3
Merge branch 'scroll-v1.3.0-rc2' into scroll-dev-0914
lispc Sep 23, 2024
0b1cb35
update memcpy.s
lightsing Sep 23, 2024
094f4c5
Merge remote-tracking branch 'scroll/scroll-dev-0914' into scroll-dev…
lightsing Sep 23, 2024
64e306b
try fix nonce
lispc Sep 23, 2024
a6c18e4
Merge branch 'scroll-dev-0914' of github.com:scroll-tech/sp1 into scr…
lispc Sep 23, 2024
87be977
improve err msg
lispc Sep 23, 2024
2593328
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Sep 25, 2024
c9547f5
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Sep 27, 2024
c451b59
add flag
tamirhemo Oct 4, 2024
667b658
tests and no filter
tamirhemo Oct 4, 2024
f606408
finalize shapes
tamirhemo Oct 4, 2024
49d792d
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 5, 2024
cf84973
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 5, 2024
4c14c55
revert memcpy.s
lispc Oct 5, 2024
442104c
tmp: many verbose log
lispc Oct 5, 2024
31f9d47
Revert "finalize shapes"
lispc Oct 6, 2024
368a60c
Revert "tests and no filter"
lispc Oct 6, 2024
7741254
Revert "add flag"
lispc Oct 6, 2024
939c9d4
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 6, 2024
7325250
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 8, 2024
e6e4336
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 9, 2024
a35889a
build
lispc Oct 9, 2024
f4b856b
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 9, 2024
6911fdd
enable debug
lispc Oct 9, 2024
28a41a2
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 9, 2024
a5ae1c8
fix memcpy clk
lispc Oct 9, 2024
cf2efb8
syscall local
lispc Oct 9, 2024
023ec2d
fix bn254 mul clk bug.. wtf
lispc Oct 9, 2024
3991008
Revert "tmp: many verbose log"
lispc Oct 10, 2024
4ba5515
Merge remote-tracking branch 'origin/tamir/v1.3.0-rc2' into scroll-de…
lispc Oct 10, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/core/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bincode = "1.3.3"
hashbrown = { version = "0.14.5", features = ["serde", "inline-more"] }
itertools = "0.13.0"
rand = "0.8.5"
generic-array = { version = "1.1.0", features = ["alloc", "serde"] }
num = { version = "0.4.3" }
typenum = "1.17.0"
nohash-hasher = "0.2.0"
Expand Down
15 changes: 15 additions & 0 deletions crates/core/executor/src/events/memcpy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::{LookupId, MemoryLocalEvent, MemoryReadRecord, MemoryWriteRecord};
use serde::{Deserialize, Serialize};

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct MemCopyEvent {
pub lookup_id: LookupId,
pub shard: u32,
pub clk: u32,
pub src_ptr: u32,
pub dst_ptr: u32,
pub read_records: Vec<MemoryReadRecord>,
pub write_records: Vec<MemoryWriteRecord>,
/// The local memory access records.
pub local_mem_access: Vec<MemoryLocalEvent>,
}
2 changes: 2 additions & 0 deletions crates/core/executor/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod alu;
mod byte;
mod cpu;
mod memcpy;
mod memory;
mod precompiles;
mod syscall;
Expand All @@ -11,6 +12,7 @@ mod utils;
pub use alu::*;
pub use byte::*;
pub use cpu::*;
pub use memcpy::*;
pub use memory::*;
pub use precompiles::*;
pub use syscall::*;
Expand Down
166 changes: 166 additions & 0 deletions crates/core/executor/src/events/precompiles/bn254_scalar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
use num::BigUint;
use sp1_curves::{
params::{FieldParameters, NumWords},
weierstrass::bn254::Bn254ScalarField,
};
use typenum::Unsigned;

use serde::{Deserialize, Serialize};

use crate::{
events::{LookupId, MemoryLocalEvent, MemoryReadRecord, MemoryWriteRecord},
syscalls::SyscallContext,
};

use super::FieldOperation;

pub const NUM_WORDS_PER_FE: usize = 8;

#[derive(Default, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)]
pub enum Bn254FieldOperation {
#[default]
Invalid = 0,
Mul = 2,
Mac = 4,
}

impl Bn254FieldOperation {
pub const fn to_field_operation(&self) -> FieldOperation {
match self {
Bn254FieldOperation::Mul => FieldOperation::Mul,
Bn254FieldOperation::Mac => panic!("not supported"),
Bn254FieldOperation::Invalid => panic!("what??"),
}
}
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Bn254FieldArithEvent {
pub lookup_id: LookupId,
pub shard: u32,
pub clk: u32,
pub op: Bn254FieldOperation,
pub arg1: FieldArithMemoryAccess<MemoryWriteRecord>,
pub arg2: FieldArithMemoryAccess<MemoryReadRecord>,
pub a: Option<FieldArithMemoryAccess<MemoryReadRecord>>,
pub b: Option<FieldArithMemoryAccess<MemoryReadRecord>>,
/// The local memory access records.
pub local_mem_access: Vec<MemoryLocalEvent>,
}

pub fn create_bn254_scalar_arith_event(
rt: &mut SyscallContext,
arg1: u32,
arg2: u32,
op: Bn254FieldOperation,
) -> Bn254FieldArithEvent {
let start_clk = rt.clk;
let p_ptr = arg1;
let q_ptr = arg2;

assert_eq!(p_ptr % 4, 0, "p_ptr({p_ptr:x}) is not aligned");
assert_eq!(q_ptr % 4, 0, "q_ptr({q_ptr:x}) is not aligned");

let nw_per_fe = <Bn254ScalarField as NumWords>::WordsFieldElement::USIZE;
debug_assert_eq!(nw_per_fe, NUM_WORDS_PER_FE);

let arg1: Vec<u32> = rt.slice_unsafe(p_ptr, nw_per_fe);
let arg2 = match op {
// 2 ptrs of real U256 values
Bn254FieldOperation::Mac => FieldArithMemoryAccess::read(rt, arg2, 2),
_ => FieldArithMemoryAccess::read(rt, arg2, nw_per_fe),
};

let bn_arg1 = BigUint::from_bytes_le(
&arg1.iter().copied().flat_map(u32::to_le_bytes).collect::<Vec<u8>>(),
);
let modulus = Bn254ScalarField::modulus();

let (a, b, bn_arg1_out) = if matches!(op, Bn254FieldOperation::Mac) {
let a = FieldArithMemoryAccess::read(rt, arg2.memory_records[0].value, nw_per_fe);
let b = FieldArithMemoryAccess::read(rt, arg2.memory_records[1].value, nw_per_fe);

let bn_a = a.value_as_biguint();
let bn_b = b.value_as_biguint();
let bn_arg1_out = (&bn_a * &bn_b + &bn_arg1) % modulus;

(Some(a), Some(b), bn_arg1_out)
} else {
let bn_arg2 = arg2.value_as_biguint();

let bn_arg1_out = match op {
Bn254FieldOperation::Mul => (&bn_arg1 * &bn_arg2) % modulus,
_ => unimplemented!("not supported"),
};
(None, None, bn_arg1_out)
};

log::trace!(
"shard: {}, clk: {}, op: {:?}, arg1: {:?}, arg2: {:?}, a: {:?}, b: {:?}",
rt.current_shard(),
rt.clk,
op,
arg1,
arg2,
a,
b
);
rt.clk += 1;

let mut result_words = bn_arg1_out.to_u32_digits();
result_words.resize(nw_per_fe, 0);

let arg1 = FieldArithMemoryAccess::write(rt, p_ptr, &result_words);

let shard = rt.current_shard();
Bn254FieldArithEvent {
lookup_id: rt.syscall_lookup_id,
shard,
clk: start_clk,
op,
arg1,
arg2,
a,
b,
local_mem_access: rt.postprocess(),
}
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct FieldArithMemoryAccess<T> {
pub ptr: u32,
pub memory_records: Vec<T>,
}

impl FieldArithMemoryAccess<MemoryReadRecord> {
pub fn read(rt: &mut SyscallContext, ptr: u32, len: usize) -> Self {
let (memory_records, _) = rt.mr_slice(ptr, len);
Self { ptr, memory_records }
}

pub fn value_as_biguint(&self) -> BigUint {
BigUint::from_bytes_le(
&self
.memory_records
.iter()
.flat_map(|word| word.value.to_le_bytes())
.collect::<Vec<u8>>(),
)
}
}

impl FieldArithMemoryAccess<MemoryWriteRecord> {
pub fn write(rt: &mut SyscallContext, ptr: u32, values: &[u32]) -> Self {
Self { ptr, memory_records: rt.mw_slice(ptr, values) }
}

pub fn prev_value_as_biguint(&self) -> BigUint {
BigUint::from_bytes_le(
&self
.memory_records
.iter()
.flat_map(|word| word.prev_value.to_le_bytes())
.collect::<Vec<u8>>(),
)
}
}
17 changes: 17 additions & 0 deletions crates/core/executor/src/events/precompiles/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod bn254_scalar;
mod ec;
mod edwards;
mod fptower;
Expand All @@ -6,6 +7,9 @@ mod sha256_compress;
mod sha256_extend;
mod uint256;

pub use bn254_scalar::{
create_bn254_scalar_arith_event, Bn254FieldArithEvent, Bn254FieldOperation, NUM_WORDS_PER_FE,
};
pub use ec::*;
pub use edwards::*;
pub use fptower::*;
Expand All @@ -19,6 +23,7 @@ pub use uint256::*;

use crate::syscalls::SyscallCode;

use super::{MemCopyEvent};
use super::{MemoryLocalEvent, SyscallEvent};

#[derive(Clone, Debug, Serialize, Deserialize, EnumIter)]
Expand Down Expand Up @@ -52,6 +57,12 @@ pub enum PrecompileEvent {
Bn254Fp2AddSub(Fp2AddSubEvent),
/// Bn254 quadratic field mul precompile event.
Bn254Fp2Mul(Fp2MulEvent),

Bn254ScalarMac(Bn254FieldArithEvent),
Bn254ScalarMul(Bn254FieldArithEvent),
MemCopy32(MemCopyEvent),
MemCopy64(MemCopyEvent),

/// Bls12-381 curve add precompile event.
Bls12381Add(EllipticCurveAddEvent),
/// Bls12-381 curve double precompile event.
Expand Down Expand Up @@ -120,6 +131,12 @@ impl PrecompileLocalMemory for Vec<(SyscallEvent, PrecompileEvent)> {
PrecompileEvent::Bls12381Fp2Mul(e) | PrecompileEvent::Bn254Fp2Mul(e) => {
iterators.push(e.local_mem_access.iter());
}
PrecompileEvent::Bn254ScalarMac(e) | PrecompileEvent::Bn254ScalarMul(e) => {
iterators.push(e.local_mem_access.iter());
}
PrecompileEvent::MemCopy32(e) | PrecompileEvent::MemCopy64(e) => {
iterators.push(e.local_mem_access.iter());
}
}
}

Expand Down
37 changes: 37 additions & 0 deletions crates/core/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,10 @@ impl<'a> Executor<'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 @@ -885,6 +889,10 @@ impl<'a> Executor<'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 @@ -894,6 +902,10 @@ impl<'a> Executor<'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 @@ -929,6 +941,10 @@ impl<'a> Executor<'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 @@ -942,6 +958,10 @@ impl<'a> Executor<'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 @@ -951,6 +971,10 @@ impl<'a> Executor<'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 @@ -1042,6 +1066,7 @@ impl<'a> Executor<'a> {
return Err(ExecutionError::InvalidSyscallUsage(syscall_id as u64));
}

let global_clk = self.state.global_clk;
// Update the syscall counts.
let syscall_for_count = syscall.count_map();
let syscall_count = self.state.syscall_counts.entry(syscall_for_count).or_insert(0);
Expand All @@ -1061,6 +1086,14 @@ impl<'a> Executor<'a> {
}
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
Expand Down Expand Up @@ -1097,6 +1130,10 @@ impl<'a> Executor<'a> {
next_pc = precompile_next_pc;
self.state.clk += precompile_cycles;
exit_code = returned_exit_code;

//log::info!(
// "execute_instruction {syscall:?} {syscall_count} {nonce} {syscall_lookup_id}"
//);
}
Opcode::EBREAK => {
return Err(ExecutionError::Breakpoint());
Expand Down
13 changes: 13 additions & 0 deletions crates/core/executor/src/syscalls/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ pub enum SyscallCode {

/// Executes the `BN254_FP2_MUL` precompile.
BN254_FP2_MUL = 0x00_01_01_2B,

/// Execute the `MEMCPY_32` precompile.
MEMCPY_32 = 0x00_01_01_90,
/// Execute the `MEMCPY_64` precompile.
MEMCPY_64 = 0x00_01_01_91,
/// Execute the `BN254_SCALAR_MUL` precompile.
BN254_SCALAR_MUL = 0x00_01_01_80,
/// Execute the `BN254_SCALAR_MAC` precompile.
BN254_SCALAR_MAC = 0x00_01_01_81,
}

impl SyscallCode {
Expand Down Expand Up @@ -170,6 +179,10 @@ impl SyscallCode {
0x00_01_01_2A => SyscallCode::BN254_FP2_SUB,
0x00_01_01_2B => SyscallCode::BN254_FP2_MUL,
0x00_00_01_1C => SyscallCode::BLS12381_DECOMPRESS,
0x00_01_01_90 => SyscallCode::MEMCPY_32,
0x00_01_01_91 => SyscallCode::MEMCPY_64,
0x00_01_01_80 => SyscallCode::BN254_SCALAR_MUL,
0x00_01_01_81 => SyscallCode::BN254_SCALAR_MAC,
_ => panic!("invalid syscall number: {value}"),
}
}
Expand Down
Loading
Loading