Skip to content

Commit 5a193a0

Browse files
committed
fixes
1 parent f01ccd2 commit 5a193a0

File tree

16 files changed

+141
-41
lines changed

16 files changed

+141
-41
lines changed

crates/sdk/Cargo.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ rrs-lib.workspace = true
6161
num-bigint.workspace = true
6262

6363
[features]
64-
default = ["parallel", "jemalloc"]
64+
default = ["parallel", "jemalloc", "tco"]
6565
evm-prove = [
6666
"openvm-continuations/static-verifier",
6767
"openvm-native-recursion/evm-prove",
@@ -79,6 +79,17 @@ metrics = [
7979
"openvm-native-recursion/metrics",
8080
"openvm-native-compiler/metrics",
8181
]
82+
tco = [
83+
"openvm-circuit/tco",
84+
"openvm-rv32im-circuit/tco",
85+
"openvm-native-circuit/tco",
86+
"openvm-sha256-circuit/tco",
87+
"openvm-keccak256-circuit/tco",
88+
"openvm-bigint-circuit/tco",
89+
"openvm-algebra-circuit/tco",
90+
"openvm-ecc-circuit/tco",
91+
"openvm-pairing-circuit/tco"
92+
]
8293
# for guest profiling:
8394
perf-metrics = ["openvm-circuit/perf-metrics", "openvm-transpiler/function-span"]
8495
# turns on stark-backend debugger in all proofs

crates/vm/src/arch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use execution::*;
3030
pub use execution_mode::{ExecutionCtxTrait, MeteredExecutionCtxTrait};
3131
pub use extensions::*;
3232
pub use integration_api::*;
33-
#[cfg(feature = "tco")]
33+
pub use interpreter::InterpretedInstance;
3434
pub use openvm_circuit_derive::create_tco_handler;
3535
pub use openvm_instructions as instructions;
3636
pub use record_arena::*;

extensions/algebra/circuit/src/execution.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::{
55

66
use num_bigint::BigUint;
77
use openvm_algebra_transpiler::{Fp2Opcode, Rv32ModularArithmeticOpcode};
8-
use openvm_circuit::arch::*;
8+
use openvm_circuit::{
9+
arch::*,
10+
system::memory::{online::GuestMemory, POINTER_MAX_BITS},
11+
};
912
use openvm_circuit_primitives::AlignedBytesBorrow;
1013
use openvm_instructions::{
1114
instruction::Instruction,
@@ -174,13 +177,17 @@ impl<'a, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2: bool>
174177
impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2: bool> Executor<F>
175178
for FieldExprVecHeapExecutor<BLOCKS, BLOCK_SIZE, IS_FP2>
176179
{
177-
#[cfg(feature = "tco")]
178-
fn handler<Ctx>(
180+
#[inline(always)]
181+
fn pre_compute_size(&self) -> usize {
182+
std::mem::size_of::<FieldExpressionPreCompute>()
183+
}
184+
185+
fn pre_compute<Ctx>(
179186
&self,
180187
pc: u32,
181188
inst: &Instruction<F>,
182189
data: &mut [u8],
183-
) -> Result<Handler<F, Ctx>, StaticProgramError>
190+
) -> Result<ExecuteFunc<F, Ctx>, StaticProgramError>
184191
where
185192
Ctx: ExecutionCtxTrait,
186193
{
@@ -197,7 +204,7 @@ impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2
197204
op,
198205
BLOCKS,
199206
BLOCK_SIZE,
200-
execute_e1_tco_handler,
207+
execute_e1_impl,
201208
[
202209
(BN254Coordinate, Add),
203210
(BN254Coordinate, Sub),
@@ -210,15 +217,15 @@ impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2
210217
]
211218
)
212219
} else {
213-
Ok(execute_e1_generic_tco_handler::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
220+
Ok(execute_e1_generic_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
214221
}
215222
} else if let Some(field_type) = get_field_type(modulus) {
216223
generate_field_dispatch!(
217224
field_type,
218225
op,
219226
BLOCKS,
220227
BLOCK_SIZE,
221-
execute_e1_tco_handler,
228+
execute_e1_impl,
222229
[
223230
(K256Coordinate, Add),
224231
(K256Coordinate, Sub),
@@ -255,24 +262,20 @@ impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2
255262
]
256263
)
257264
} else {
258-
Ok(execute_e1_generic_tco_handler::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
265+
Ok(execute_e1_generic_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
259266
}
260267
} else {
261-
Ok(execute_e1_setup_tco_handler::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
268+
Ok(execute_e1_setup_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
262269
}
263270
}
264271

265-
#[inline(always)]
266-
fn pre_compute_size(&self) -> usize {
267-
std::mem::size_of::<FieldExpressionPreCompute>()
268-
}
269-
270-
fn pre_compute<Ctx>(
272+
#[cfg(feature = "tco")]
273+
fn handler<Ctx>(
271274
&self,
272275
pc: u32,
273276
inst: &Instruction<F>,
274277
data: &mut [u8],
275-
) -> Result<ExecuteFunc<F, Ctx>, StaticProgramError>
278+
) -> Result<Handler<F, Ctx>, StaticProgramError>
276279
where
277280
Ctx: ExecutionCtxTrait,
278281
{
@@ -289,7 +292,7 @@ impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2
289292
op,
290293
BLOCKS,
291294
BLOCK_SIZE,
292-
execute_e1_impl,
295+
execute_e1_tco_handler,
293296
[
294297
(BN254Coordinate, Add),
295298
(BN254Coordinate, Sub),
@@ -302,15 +305,15 @@ impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2
302305
]
303306
)
304307
} else {
305-
Ok(execute_e1_generic_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
308+
Ok(execute_e1_generic_tco_handler::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
306309
}
307310
} else if let Some(field_type) = get_field_type(modulus) {
308311
generate_field_dispatch!(
309312
field_type,
310313
op,
311314
BLOCKS,
312315
BLOCK_SIZE,
313-
execute_e1_impl,
316+
execute_e1_tco_handler,
314317
[
315318
(K256Coordinate, Add),
316319
(K256Coordinate, Sub),
@@ -347,10 +350,10 @@ impl<F: PrimeField32, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2
347350
]
348351
)
349352
} else {
350-
Ok(execute_e1_generic_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
353+
Ok(execute_e1_generic_tco_handler::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
351354
}
352355
} else {
353-
Ok(execute_e1_setup_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
356+
Ok(execute_e1_setup_tco_handler::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2>)
354357
}
355358
}
356359
}
@@ -581,6 +584,7 @@ unsafe fn execute_e12_setup_impl<
581584
vm_state.instret += 1;
582585
}
583586

587+
#[create_tco_handler]
584588
unsafe fn execute_e1_setup_impl<
585589
F: PrimeField32,
586590
CTX: ExecutionCtxTrait,
@@ -629,6 +633,7 @@ unsafe fn execute_e1_impl<
629633
execute_e12_impl::<_, _, BLOCKS, BLOCK_SIZE, IS_FP2, FIELD_TYPE, OP>(pre_compute, vm_state);
630634
}
631635

636+
#[create_tco_handler]
632637
unsafe fn execute_e2_impl<
633638
F: PrimeField32,
634639
CTX: MeteredExecutionCtxTrait,
@@ -651,6 +656,7 @@ unsafe fn execute_e2_impl<
651656
);
652657
}
653658

659+
#[create_tco_handler]
654660
unsafe fn execute_e1_generic_impl<
655661
F: PrimeField32,
656662
CTX: ExecutionCtxTrait,

extensions/algebra/circuit/src/modular_chip/is_eq.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use num_bigint::BigUint;
77
use openvm_algebra_transpiler::Rv32ModularArithmeticOpcode;
88
use openvm_circuit::{
99
arch::*,
10-
system::memory::{online::TracingMemory, MemoryAuxColsFactory},
10+
system::memory::{
11+
online::{GuestMemory, TracingMemory},
12+
MemoryAuxColsFactory, POINTER_MAX_BITS,
13+
},
1114
};
1215
use openvm_circuit_primitives::{
1316
bigint::utils::big_uint_to_limbs,
@@ -551,16 +554,10 @@ where
551554
#[cfg(feature = "tco")]
552555
fn handler<Ctx>(
553556
&self,
554-
_opcode: u32,
555-
_instruction: &Instruction<F>,
556-
_data: &mut [u8],
557-
) -> Result<
558-
for<'a, 'b, 'c> unsafe fn(
559-
&'a InterpretedInstance<'b, F, Ctx>,
560-
&'c mut VmExecState<F, GuestMemory, Ctx>,
561-
) -> Result<(), ExecutionError>,
562-
StaticProgramError,
563-
>
557+
pc: u32,
558+
inst: &Instruction<F>,
559+
data: &mut [u8],
560+
) -> Result<Handler<F, Ctx>, StaticProgramError>
564561
where
565562
Ctx: ExecutionCtxTrait,
566563
{

extensions/ecc/circuit/src/weierstrass_chip/add_ne/execution.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::{
55

66
use num_bigint::BigUint;
77
use openvm_algebra_circuit::fields::{get_field_type, FieldType};
8-
use openvm_circuit::arch::*;
8+
use openvm_circuit::{
9+
arch::*,
10+
system::memory::{online::GuestMemory, POINTER_MAX_BITS},
11+
};
912
use openvm_circuit_primitives::AlignedBytesBorrow;
1013
use openvm_ecc_transpiler::Rv32WeierstrassOpcode;
1114
use openvm_instructions::{

extensions/ecc/circuit/src/weierstrass_chip/double/execution.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::{
44
};
55

66
use num_bigint::BigUint;
7-
use openvm_circuit::arch::*;
7+
use openvm_circuit::{
8+
arch::*,
9+
system::memory::{online::GuestMemory, POINTER_MAX_BITS},
10+
};
811
use openvm_circuit_primitives::AlignedBytesBorrow;
912
use openvm_ecc_transpiler::Rv32WeierstrassOpcode;
1013
use openvm_instructions::{

extensions/native/circuit/src/branch_eq/execution.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::{Borrow, BorrowMut};
22

33
use openvm_circuit::{
44
arch::*,
5+
system::memory::online::GuestMemory,
56
utils::{transmute_field_to_u32, transmute_u32_to_field},
67
};
78
use openvm_circuit_primitives::AlignedBytesBorrow;

extensions/native/circuit/src/castf/execution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::borrow::{Borrow, BorrowMut};
22

3-
use openvm_circuit::arch::*;
3+
use openvm_circuit::{arch::*, system::memory::online::GuestMemory};
44
use openvm_circuit_primitives::AlignedBytesBorrow;
55
use openvm_instructions::{
66
instruction::Instruction, program::DEFAULT_PC_STEP, riscv::RV32_MEMORY_AS, LocalOpcode,

extensions/native/circuit/src/field_arithmetic/execution.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::{Borrow, BorrowMut};
22

33
use openvm_circuit::{
44
arch::*,
5+
system::memory::online::GuestMemory,
56
utils::{transmute_field_to_u32, transmute_u32_to_field},
67
};
78
use openvm_circuit_primitives::AlignedBytesBorrow;

extensions/native/circuit/src/field_extension/execution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::borrow::{Borrow, BorrowMut};
22

3-
use openvm_circuit::arch::*;
3+
use openvm_circuit::{arch::*, system::memory::online::GuestMemory};
44
use openvm_circuit_primitives::AlignedBytesBorrow;
55
use openvm_instructions::{instruction::Instruction, program::DEFAULT_PC_STEP, LocalOpcode};
66
use openvm_native_compiler::{conversion::AS, FieldExtensionOpcode};

0 commit comments

Comments
 (0)