From 78ed9d01677f2877f2fbbcacc360b57919fc1a00 Mon Sep 17 00:00:00 2001 From: Miraculous Owonubi Date: Thu, 10 Oct 2024 16:16:37 +0100 Subject: [PATCH] fix(sdk+runtime): identity exposure (#779) --- crates/runtime/src/logic.rs | 13 ++++++++----- crates/runtime/src/logic/imports.rs | 2 ++ crates/sdk/src/env.rs | 18 ++++++++++-------- crates/sdk/src/sys.rs | 3 ++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/crates/runtime/src/logic.rs b/crates/runtime/src/logic.rs index dc5672e5e..9968a3e17 100644 --- a/crates/runtime/src/logic.rs +++ b/crates/runtime/src/logic.rs @@ -134,11 +134,6 @@ impl<'a> VMLogic<'a> { } .build() } - - pub fn get_executor_identity(&mut self, register_id: u64) -> VMLogicResult<()> { - self.registers - .set(self.limits, register_id, self.context.executor_public_key) - } } #[derive(Debug, Serialize)] @@ -251,6 +246,14 @@ impl VMHostFunctions<'_> { Ok(1) } + pub fn executor_id(&mut self, register_id: u64) -> VMLogicResult<()> { + self.with_logic_mut(|logic| { + logic + .registers + .set(logic.limits, register_id, logic.context.executor_public_key) + }) + } + pub fn input(&mut self, register_id: u64) -> VMLogicResult<()> { self.with_logic_mut(|logic| { logic diff --git a/crates/runtime/src/logic/imports.rs b/crates/runtime/src/logic/imports.rs index 42987cb38..b6186189f 100644 --- a/crates/runtime/src/logic/imports.rs +++ b/crates/runtime/src/logic/imports.rs @@ -34,6 +34,8 @@ impl VMLogic<'_> { fn register_len(register_id: u64) -> u64; fn read_register(register_id: u64, ptr: u64, len: u64) -> u32; + fn executor_id(register_id: u64); + fn input(register_id: u64); fn value_return(tag: u64, value_ptr: u64, value_len: u64); fn log_utf8(ptr: u64, len: u64); diff --git a/crates/sdk/src/env.rs b/crates/sdk/src/env.rs index ba29796db..b497a7d03 100644 --- a/crates/sdk/src/env.rs +++ b/crates/sdk/src/env.rs @@ -40,12 +40,6 @@ fn expected_boolean(e: u32) -> T { panic_str(&format!("Expected 0|1. Got {e}")); } -#[must_use] -pub fn get_executor_identity() -> [u8; 32] { - unsafe { sys::get_executor_identity(DATA_REGISTER) } - read_register_sized(DATA_REGISTER).expect("Must have executor identity.") -} - pub fn setup_panic_hook() { set_hook(Box::new(|info| { #[expect(clippy::option_if_let_else, reason = "Clearer this way")] @@ -106,9 +100,11 @@ pub fn read_register(register_id: RegisterId) -> Option> { #[inline] fn read_register_sized(register_id: RegisterId) -> Option<[u8; N]> { let len = register_len(register_id)?; - let buffer = [0; N]; + + let mut buffer = [0; N]; + let succeed: bool = unsafe { - sys::read_register(register_id, BufferMut::new(buffer)) + sys::read_register(register_id, BufferMut::new(&mut buffer)) .try_into() .unwrap_or_else(expected_boolean) }; @@ -122,6 +118,12 @@ fn read_register_sized(register_id: RegisterId) -> Option<[u8; N Some(buffer) } +#[must_use] +pub fn executor_id() -> [u8; 32] { + unsafe { sys::executor_id(DATA_REGISTER) } + read_register_sized(DATA_REGISTER).expect("Must have executor identity.") +} + #[inline] #[must_use] pub fn input() -> Option> { diff --git a/crates/sdk/src/sys.rs b/crates/sdk/src/sys.rs index 7ed324639..e03299463 100644 --- a/crates/sdk/src/sys.rs +++ b/crates/sdk/src/sys.rs @@ -12,7 +12,8 @@ wasm_imports! { fn register_len(register_id: RegisterId) -> PtrSizedInt; fn read_register(register_id: RegisterId, buf: BufferMut<'_>) -> Bool; // -- - fn get_executor_identity(register_id: RegisterId); + fn executor_id(register_id: RegisterId); + // -- fn input(register_id: RegisterId); fn value_return(value: ValueReturn<'_>); fn log_utf8(msg: Buffer<'_>);