diff --git a/lee/state_machine/core/src/program/mod.rs b/lee/state_machine/core/src/program/mod.rs index a77d36f7b..9860030f7 100644 --- a/lee/state_machine/core/src/program/mod.rs +++ b/lee/state_machine/core/src/program/mod.rs @@ -53,6 +53,10 @@ impl From for ProgramId { } pub type InstructionData = Vec; + +/// Struct encoding the input to an LEE program. Crosses the guest boundary as +/// `ProgramInput` with the instruction still borsh-encoded. +#[derive(BorshSerialize, BorshDeserialize)] pub struct ProgramInput { pub self_program_id: ProgramId, pub caller_program_id: Option, @@ -60,15 +64,6 @@ pub struct ProgramInput { pub instruction: T, } -/// Struct encoding the input to an LEE program. -#[derive(BorshSerialize, BorshDeserialize)] -pub struct LeeInputHeader { - pub self_program_id: ProgramId, - pub caller_program_id: Option, - pub pre_states: Vec, - pub instruction_data: InstructionData, -} - /// A 32-byte seed used to compute a *Program-Derived `AccountId`* (PDA). /// /// Each program can derive up to `2^256` unique account IDs by choosing different @@ -710,12 +705,13 @@ pub fn read_input_frame() -> Vec { /// Reads the LEE inputs from the guest environment. #[must_use] pub fn read_lee_inputs() -> (ProgramInput, InstructionData) { - let LeeInputHeader { + let ProgramInput { self_program_id, caller_program_id, pre_states, - instruction_data, - } = borsh::from_slice(&read_input_frame()).expect("guest input must be a valid borsh header"); + instruction: instruction_data, + } = borsh::from_slice::>(&read_input_frame()) + .expect("guest input must be valid borsh"); let instruction = borsh::from_slice(&instruction_data).expect("instruction must decode from borsh"); ( diff --git a/lee/state_machine/src/program/mod.rs b/lee/state_machine/src/program/mod.rs index 4e13c96ee..b1fd451e4 100644 --- a/lee/state_machine/src/program/mod.rs +++ b/lee/state_machine/src/program/mod.rs @@ -4,7 +4,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use lee_core::{ account::AccountWithMetadata, from_frame, - program::{InstructionData, LeeInputHeader, ProgramId, ProgramOutput}, + program::{InstructionData, ProgramId, ProgramInput, ProgramOutput}, to_frame, }; use risc0_zkvm::{ExecutorEnv, ExecutorEnvBuilder, default_executor}; @@ -95,14 +95,14 @@ impl Program { instruction_data: &[u8], env_builder: &mut ExecutorEnvBuilder, ) -> Result<(), LeeError> { - let header = LeeInputHeader { + let input = ProgramInput { self_program_id: self.id, caller_program_id, pre_states: pre_states.to_vec(), - instruction_data: instruction_data.to_vec(), + instruction: instruction_data.to_vec(), }; let payload = - borsh::to_vec(&header).map_err(|e| LeeError::ProgramWriteInputFailed(e.to_string()))?; + borsh::to_vec(&input).map_err(|e| LeeError::ProgramWriteInputFailed(e.to_string()))?; env_builder.write_slice(&to_frame(&payload)); Ok(()) }