Skip to content

Commit b125b27

Browse files
committed
feat: updated stark_utils to test metered_cost and aot_metered_cost
1 parent 99abf54 commit b125b27

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

crates/vm/src/arch/vm.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,15 @@ where
309309
InterpretedInstance::new_metered(&self.inventory, exe, executor_idx_to_air_idx)
310310
}
311311

312-
// Creates an instance of the AotInstance specialized for metered execution of the given
313-
/// `exe`.
314-
pub fn aot_metered_instance(
312+
// Creates an AOT instance for metered execution of the given `exe`.
313+
pub fn metered_cost_aot_instance(
315314
&self,
316315
exe: &VmExe<F>,
317316
executor_idx_to_air_idx: &[usize],
318-
) -> Result<AotInstance<F, MeteredCtx>, StaticProgramError> {
317+
) -> Result<AotInstance<F, MeteredCostCtx>, StaticProgramError> {
319318
#[cfg(all(target_arch = "x86_64", not(feature = "tco")))]
320319
{
321-
AotInstance::new_metered(&self.inventory, exe, executor_idx_to_air_idx)
320+
AotInstance::new_metered_cost(&self.inventory, exe, executor_idx_to_air_idx)
322321
}
323322
#[cfg(any(not(target_arch = "x86_64"), feature = "tco"))]
324323
{
@@ -543,6 +542,20 @@ where
543542
.metered_cost_instance(exe, &executor_idx_to_air_idx)
544543
}
545544

545+
// Metered Cost AOT execution
546+
pub fn get_metered_cost_aot_instance(
547+
&self,
548+
exe: &VmExe<Val<E::SC>>,
549+
) -> Result<AotInstance<Val<E::SC>, MeteredCostCtx>, StaticProgramError>
550+
where
551+
Val<E::SC>: PrimeField32,
552+
<VB::VmConfig as VmExecutionConfig<Val<E::SC>>>::Executor: MeteredExecutor<Val<E::SC>>,
553+
{
554+
let executor_idx_to_air_idx = self.executor_idx_to_air_idx();
555+
self.executor()
556+
.metered_cost_aot_instance(exe, &executor_idx_to_air_idx)
557+
}
558+
546559
pub fn preflight_interpreter(
547560
&self,
548561
exe: &VmExe<Val<E::SC>>,

crates/vm/src/utils/stark_utils.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
let exe = exe.into();
116116
let input = input.into();
117117
let metered_ctx = vm.build_metered_ctx(&exe);
118-
118+
let metered_cost_ctx = vm.build_metered_cost_ctx();
119119
/*
120120
Assertions for Pure Execution AOT
121121
*/
@@ -174,7 +174,21 @@ where
174174
assert_eq!(segments[i].trace_heights, aot_segments[i].trace_heights);
175175
}
176176
}
177+
/*
178+
Assertions for Metered AOT Cost
179+
*/
180+
{
181+
let (cost, vm_state) = vm
182+
.metered_cost_interpreter(&exe)?
183+
.execute_metered_cost(input.clone(), metered_cost_ctx.clone())?;
184+
185+
let (aot_cost, aot_vm_state) = vm
186+
.get_metered_cost_aot_instance(&exe)?
187+
.execute_metered_cost(input.clone(), metered_cost_ctx.clone())?;
177188

189+
assert_eq!(vm_state.instret(), aot_vm_state.instret());
190+
assert_eq!(cost, aot_cost);
191+
}
178192
/* TODO: this is a temporary change to use `get_metered_aot_instance` instead of `metered_interpreter`
179193
to test AOT segments in addition to the equal assertions
180194
We would want to revert `stark_utils.rs` back to how it looked like in main

0 commit comments

Comments
 (0)