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

add block hint #42

Closed
wants to merge 6 commits into from
Closed

add block hint #42

wants to merge 6 commits into from

Conversation

tcoratger
Copy link
Collaborator

No description provided.

@tcoratger tcoratger marked this pull request as ready for review September 30, 2024 19:01
Co-authored-by: Clément Walter <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we'd like instead to implement From<SealedBlock> for a KethBlock, and such a KethBlock would fit well with the already existing https://github.com/lambdaclass/cairo-vm/blob/main/vm/src/vm/vm_memory/memory_segments.rs#L132-L146 so that it's easier is we update the models

Copy link
Collaborator Author

@tcoratger tcoratger Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KethBlock would be a Vec<MaybeRelocatable>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd have been better to import the test_block function from test_os.cairo but since #43 is supposed to remove this, I won't block the PR for this

-> HintExecutionResult {
// This call will first add a new memory segment to the VM (the base)
// Then we load the block into the VM starting from the base
vm.gen_arg(&Into::<KethPayload>::into(block.clone()).0)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do you actually assign the base to the block cairo variable here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust question: why do we need to clone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +208 to +212
impl From<Option<u64>> for KethPayload {
fn from(value: Option<u64>) -> Self {
MaybeRelocatable::from(Felt252::from(value.unwrap_or_default())).into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where we have Option<u64> in blocks, but this would be converted into a model.Option in cairo, meaning a struct with 2 values {is_some: 0, value: 0}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blob_gas_used for example is an option, at the moment the model.Block is constructed like that so maybe let us keep as is and fine tuned this after modification on Cairo side no?

fn from(value: Bloom) -> Self {
vec![
MaybeRelocatable::from(Felt252::from(value.len())),
MaybeRelocatable::from(Felt252::from_bytes_be_slice(&value.0 .0)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bloom is a 256 long bytes array, so a vec of felt

Comment on lines +236 to +243
impl From<U256> for KethPayload {
fn from(value: U256) -> Self {
MaybeRelocatable::from(Felt252::from_bytes_be_slice(
&value.to_be_bytes::<{ U256::BYTES }>(),
))
.into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the u256 is not trivial as it can be either Uint256* (so a pointer to a new segment with two values) or directly inlined into the struct, and consequently split in _low and _high parts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I put the case where this is always inlined into the struct

Comment on lines +245 to +253
impl From<Bytes> for KethPayload {
fn from(value: Bytes) -> Self {
vec![
MaybeRelocatable::from(Felt252::from(value.len())),
MaybeRelocatable::from(Felt252::from_bytes_be_slice(&value.0)),
]
.into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes are an array of felt, not a single felt

fn from(value: Vec<u8>) -> Self {
vec![
MaybeRelocatable::from(Felt252::from(value.len())),
MaybeRelocatable::from(Felt252::from_bytes_be_slice(&value)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, needs to be an array

Comment on lines +265 to +273
impl From<B256> for KethPayload {
fn from(value: B256) -> Self {
vec![
MaybeRelocatable::from(Felt252::from_bytes_be_slice(&value.0[16..])),
MaybeRelocatable::from(Felt252::from_bytes_be_slice(&value.0[0..16])),
]
.into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment, it depends on the target model

Comment on lines +275 to +279
impl From<Option<B256>> for KethPayload {
fn from(value: Option<B256>) -> Self {
value.unwrap_or_default().into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above for Option

// The length of the signature payload
MaybeRelocatable::from(Felt252::from(value.payload_len())),
// The signature payload
MaybeRelocatable::from(Felt252::from_bytes_be_slice(&value.to_bytes())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above, is this a vec?

// Run the cairo program with the hint processor and the block
//
// We unwrap the result to ensure that the program ran successfully
let _ = cairo_run(&program, &config, &mut hint_processor).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the program does nothing, there is no chance to have this run failing. (you could remove the hint it'd be the same)

@tcoratger tcoratger closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants