-
Notifications
You must be signed in to change notification settings - Fork 116
Update openvm to 1.4.0 #3291
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
base: main
Are you sure you want to change the base?
Update openvm to 1.4.0 #3291
Conversation
…f, but can't get column names
[Ovm 1.4] get original airs
[OVM 1.4] `VmConfig` related trait implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Still doing the review, these are some initial comments
run: | | ||
rustup toolchain install 1.88 | ||
cargo +1.88 install --git 'http://github.com/powdr-labs/openvm.git' --rev fbd69da cargo-openvm | ||
cargo +1.88 install --git 'http://github.com/openvm-org/openvm.git' cargo-openvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the fork here anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think it was really needed before either. cargo-openvm
is used to compile the guest, and our fork does not touch that part of openvm.
with: | ||
repository: powdr-labs/openvm-reth-benchmark | ||
ref: main | ||
ref: 15a1cb1533036f1b5284ddf79b3cadd644778398 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess this needs to get in first, then reth updated, then this can go back to main?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's gonna be a few commits to merge all of this..
openvm-stark-backend = { git = "https://github.com/powdr-labs/stark-backend.git", rev = "e27de8b", default-features = false, features = [ | ||
"parallel", | ||
"jemalloc", | ||
"bench-metrics", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bench-metrics
not needed anymore for metrics.json
?
"jemalloc", | ||
"nightly-features", | ||
"bench-metrics", | ||
"evm-prove", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this feature for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It enables verifying in evm, so the prover and verifier for the last recursion step which outputs a bn128 snark iirc.
openvm/src/extraction_utils.rs
Outdated
.iter() | ||
.fold(HashMap::new(), |mut acc, instruction| { | ||
let (air_name, _) = air_by_opcode_id.get_instruction_air_and_id(instruction); | ||
// TODO: main_columns might not be correct, as the RA::with_capacity() uses the following `main_width()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now or later PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all working properly now, so I'll say for a later PR where we EITHER investigate this and find it to be proper and just remove this comment OR find a "proper" solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still keeping this comment here to flag a potential issue though.
openvm/src/extraction_utils.rs
Outdated
.or_insert(RecordArenaDimension { | ||
height: 0, | ||
width: air_by_opcode_id | ||
.get_instruction_air_stats(instruction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: i think it doesn't matter much, but the calls of get_instruction_air_and_id
and get_instruction_air_stats
are both searching for the same entry in the OriginalAirs
maps... not sure how feasible it is to avoid this due to the trait though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. We don't need to go through the trait as we have access to the concrete type. I refactored to accessing the maps inside OriginalAirs
directly.
openvm/src/extraction_utils.rs
Outdated
.filter(|op| { | ||
// Filter out the opcode that we are not interested in | ||
instruction_allowlist.contains(op) | ||
let res = instruction_allowlist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the let res
i think since we're immediately returning it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
openvm/src/lib.rs
Outdated
|
||
// Generate an AppProvingKey | ||
let app_pk = Arc::new(sdk.app_keygen(app_config)?); | ||
sdk.app_keygen(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it right to ignore the returned values here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was called for caching, but it's not required, removed!
openvm/src/lib.rs
Outdated
// Create the SDK | ||
let sdk: GenericSdk<_, SpecializedConfigCpuBuilder, _> = GenericSdk::new(app_config).unwrap(); | ||
|
||
let mut app_prover = sdk.app_prover(exe.clone())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be moved inside the else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
openvm/src/lib.rs
Outdated
|
||
// All gate constraints should be satisfied, but bus interactions are not implemented yet. | ||
#[test] | ||
#[ignore = "Pending bug fix"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a future PR? does this need a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. This is PLONK and the bug is described in #3333. We decided to make it run first before fixing PLONK, which is not our default path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refined the bug in this PR. mock works, but verification fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually mock does not work with debug_assert on. Refined and still ignored in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...--release
flag can be kind of confusing...
openvm/src/powdr_extension/chip.rs
Outdated
original_airs: OriginalAirs<BabyBear>, | ||
base_config: OriginalVmConfig, | ||
periphery: PowdrPeripheryInstances, | ||
record_arena_by_air_name: Rc<RefCell<OriginalArenas>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this parameter is already inside the precompile
being passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good catch...
impl OriginalArenas { | ||
/// Given an estimate of how many times the APC is called in this segment, and the original airs and apc, | ||
/// initializes the arenas iff not already initialized. | ||
fn ensure_initialized( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this gonna be called multiple times? could it just be initialize
and fail if already init?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is called each time the apc instruction is executed, but actually does the initialization only at the beginning of each segment.
The state machine is
Uninitialized
execute_preflight_seg_0
execute_apc_call (this is where init happens)
Initialized
execute_apc_call (here it just adds to the arena)
... (more calls to execute_apc_call)
trace_gen_seg_0 (read from the arenas and create the final table, then reset to Uninitialized)
Uninitialized
execute_preflight_seg_1 (now we need to initialize again for seg_1)
...
We do need to check if it's initialized at each execute_apc_call
because we have no way to know we just started a new segment based on PreflightExecutor::execute
. So this check happens in ensure_initialized
.
apc, | ||
pub fn arenas(&self) -> &HashMap<String, MatrixRecordArena<BabyBear>> { | ||
match self { | ||
OriginalArenas::Uninitialized => unreachable!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd use panic
since this is not unreachable by construction, its more like an "unwrap"
/// - read from during trace generation | ||
/// - reset to uninitialized after trace generation | ||
#[derive(Default)] | ||
pub enum OriginalArenas { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: could be a struct wrapping an Option
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree it is basically an option, but I thought it was clearer to name the possible states explicitly rather than relying on Some/None
apc: Arc<Apc<F, Instr<F>>>, | ||
} | ||
/// Returns a mutable reference to the arenas. | ||
/// Should only be called after `initialize` is called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no method named initialize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
if let Some(ref ecc) = this.sdk_vm_config.ecc { | ||
complex = complex.extend(ecc)?; | ||
|
||
fn get_opcode_name(&self, opcode: usize) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's required for the trait and is used when the metrics
flag is on iirc
original_airs: OriginalAirs<BabyBear>, | ||
base_config: OriginalVmConfig, | ||
periphery: PowdrPeripheryInstances, | ||
record_arena_by_air_name: Rc<RefCell<OriginalArenas>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already part of precompile
i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!
assert!(inventory | ||
.find_air::<VariableRangeCheckerAir>() | ||
.nth(1) | ||
.is_none()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't ensure the air is present, only that there is at most one instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
assert!(inventory | ||
.find_chip::<SharedVariableRangeCheckerChip>() | ||
.nth(1) | ||
.is_none()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
This PR updated the openvm dependency to 1.4.0. A lot of changes were introduced, hence the size of this PR.
Not covered in this PR:
Changes to openvm here
Changes to stark-backend here
Tasks:
Send + Sync
bound on Executor in ovm (instead, removed the need for that bound in ovm)