refactor(lee): replace LeeInputHeader with ProgramInput<InstructionData>

This commit is contained in:
Artem Gureev
2026-08-23 09:35:41 +00:00
parent 631a1d7167
commit 1e913284d8
2 changed files with 12 additions and 16 deletions
+8 -12
View File
@@ -53,6 +53,10 @@ impl From<AccountId> for ProgramId {
}
pub type InstructionData = Vec<u8>;
/// Struct encoding the input to an LEE program. Crosses the guest boundary as
/// `ProgramInput<InstructionData>` with the instruction still borsh-encoded.
#[derive(BorshSerialize, BorshDeserialize)]
pub struct ProgramInput<T> {
pub self_program_id: ProgramId,
pub caller_program_id: Option<ProgramId>,
@@ -60,15 +64,6 @@ pub struct ProgramInput<T> {
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<ProgramId>,
pub pre_states: Vec<AccountWithMetadata>,
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<u8> {
/// Reads the LEE inputs from the guest environment.
#[must_use]
pub fn read_lee_inputs<T: BorshDeserialize>() -> (ProgramInput<T>, 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::<ProgramInput<InstructionData>>(&read_input_frame())
.expect("guest input must be valid borsh");
let instruction =
borsh::from_slice(&instruction_data).expect("instruction must decode from borsh");
(
+4 -4
View File
@@ -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(())
}