Skip to content

feat(starknet_os): implement write_split_result #5163

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ use blockifier::state::state_api::StateReader;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{
get_integer_from_var_name,
get_ptr_from_var_name,
get_relocatable_from_var_name,
insert_value_from_var_name,
};
use cairo_vm::types::relocatable::MaybeRelocatable;
use starknet_types_core::felt::Felt;

use crate::hints::error::{OsHintError, OsHintResult};
use crate::hints::hint_implementation::kzg::utils::polynomial_coefficients_to_kzg_commitment;
use crate::hints::hint_implementation::kzg::utils::{
polynomial_coefficients_to_kzg_commitment,
split_bigint3,
};
use crate::hints::types::HintArgs;
use crate::hints::vars::{Const, Ids};

Expand Down Expand Up @@ -75,6 +79,16 @@ pub(crate) fn store_da_segment<S: StateReader>(
Ok(())
}

pub(crate) fn write_split_result<S: StateReader>(HintArgs { .. }: HintArgs<'_, S>) -> OsHintResult {
todo!()
pub(crate) fn write_split_result<S: StateReader>(
HintArgs { vm, ids_data, ap_tracking, .. }: HintArgs<'_, S>,
) -> OsHintResult {
let value =
get_integer_from_var_name(Ids::Value.into(), vm, ids_data, ap_tracking)?.to_bigint();
let res_ptr = get_relocatable_from_var_name(Ids::Res.into(), vm, ids_data, ap_tracking)?;

let splits: Vec<MaybeRelocatable> =
split_bigint3(value)?.into_iter().map(MaybeRelocatable::Int).collect();
vm.write_arg(res_ptr, &splits)?;

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ pub(crate) fn polynomial_coefficients_to_kzg_commitment(
/// d0 + d1 * BASE + d2 * BASE**2.
/// d2 can be in the range (-2**127, 2**127).
// TODO(Dori): Consider using bls_split from the VM crate if and when public.
#[allow(dead_code)]
pub(crate) fn split_bigint3(num: BigInt) -> Result<[Felt; 3], OsHintError> {
let (q1, d0) = (&num / &*BASE, Felt::from(num % &*BASE));
let (d2, d1) = (&q1 / &*BASE, Felt::from(q1 % &*BASE));
Expand Down
2 changes: 2 additions & 0 deletions crates/starknet_os/src/hints/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub enum Ids {
RemainingGas,
ResourceBounds,
Request,
Res,
Sha256Ptr,
StateEntry,
StateUpdatesStart,
Expand Down Expand Up @@ -185,6 +186,7 @@ impl From<Ids> for &'static str {
Ids::RemainingGas => "remaining_gas",
Ids::ResourceBounds => "resource_bounds,",
Ids::Request => "request",
Ids::Res => "res",
Ids::Sha256Ptr => "sha256_ptr",
Ids::StateEntry => "state_entry",
Ids::StateUpdatesStart => "state_updates_start",
Expand Down
Loading