Skip to content

Commit

Permalink
Merge pull request #41 from keep-starknet-strange/lucas/still-outputting
Browse files Browse the repository at this point in the history
feat(os output): add DA
  • Loading branch information
0xLucqs authored Oct 23, 2023
2 parents c607010 + 04f0a0b commit 452b75e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ pub struct StarknetOsOutput {
pub messages_to_l1: Vec<Felt252>,
/// List of messages from L1 handled in this block
pub messages_to_l2: Vec<Felt252>,
/// List of the storage updates.
pub state_updates: Vec<Felt252>,
/// List of the newly declared contract classes.
pub contract_class_diff: Vec<Felt252>,
}

impl StarknetOsOutput {
#[allow(clippy::too_many_arguments)]
pub fn new(
prev_state_root: Felt252,
new_state_root: Felt252,
Expand All @@ -131,8 +137,20 @@ impl StarknetOsOutput {
config_hash: Felt252,
messages_to_l1: Vec<Felt252>,
messages_to_l2: Vec<Felt252>,
state_updates: Vec<Felt252>,
contract_class_diff: Vec<Felt252>,
) -> Self {
Self { prev_state_root, new_state_root, block_number, block_hash, config_hash, messages_to_l1, messages_to_l2 }
Self {
prev_state_root,
new_state_root,
block_number,
block_hash,
config_hash,
messages_to_l1,
messages_to_l2,
state_updates,
contract_class_diff,
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,16 @@ impl SnOsRunner {
let messages_to_l1 = os_output[1..messages_to_l1_size].to_vec();

let os_output = &os_output[messages_to_l1_size + 1..];
let messages_to_l2 =
os_output[1..<usize>::from_be_bytes(os_output[0].to_be_bytes()[..8].try_into().unwrap())].to_vec();
let messages_to_l2_size = <usize>::from_be_bytes(os_output[0].to_be_bytes()[..8].try_into().unwrap());
let messages_to_l2 = os_output[1..messages_to_l2_size].to_vec();
let os_output = &os_output[messages_to_l2_size + 1..];

let state_updates_size = <usize>::from_be_bytes(os_output[0].to_be_bytes()[..8].try_into().unwrap());
let state_updates = os_output[1..state_updates_size].to_vec();
let os_output = &os_output[state_updates_size + 1..];

let contract_class_diff_size = <usize>::from_be_bytes(os_output[0].to_be_bytes()[..8].try_into().unwrap());
let contract_class_diff = os_output[1..contract_class_diff_size].to_vec();
StarknetOsOutput::new(
prev_state_root,
new_state_root,
Expand All @@ -138,6 +146,8 @@ impl SnOsRunner {
config_hash,
messages_to_l1,
messages_to_l2,
state_updates,
contract_class_diff,
);

vm.verify_auto_deductions().map_err(|e| SnOsError::Runner(e.into()))?;
Expand Down

0 comments on commit 452b75e

Please sign in to comment.