From a62feb7ee54a7dbde986d66a26cf56b8b29bc862 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Wed, 13 Nov 2024 11:24:12 +0100 Subject: [PATCH] WIP: support ADAL in the SDK --- .../kernel_evm/evm_evaluation/src/evalhost.rs | 18 +++++++ etherlink/kernel_evm/runtime/src/runtime.rs | 18 +++++++ .../kernel_evm/runtime/src/safe_storage.rs | 18 +++++++ src/kernel_sdk/CHANGES.md | 1 + src/kernel_sdk/host/src/runtime.rs | 48 +++++++++++++++++++ src/kernel_sdk/host/src/runtime/unwindable.rs | 18 +++++++ .../entrypoint/internal/static_input_host.rs | 18 +++++++ 7 files changed, 139 insertions(+) diff --git a/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs b/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs index a2973b4fa14f..1f9a1ce045e9 100644 --- a/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs +++ b/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs @@ -171,6 +171,24 @@ impl SdkRuntime for EvalHost { .reveal_dal_page(published_level, slot_index, page_index, destination) } + #[inline(always)] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result { + self.host.reveal_adal_page( + published_level, + slot_index, + page_index, + attestation_threshold_per_mil, + destination, + ) + } + #[inline(always)] fn reveal_dal_parameters(&self) -> RollupDalParameters { self.host.reveal_dal_parameters() diff --git a/etherlink/kernel_evm/runtime/src/runtime.rs b/etherlink/kernel_evm/runtime/src/runtime.rs index 64a24c9fe51a..6dc7d9ba76dc 100644 --- a/etherlink/kernel_evm/runtime/src/runtime.rs +++ b/etherlink/kernel_evm/runtime/src/runtime.rs @@ -211,6 +211,24 @@ impl + Borrow, Internal: InternalRuntime> S ) } + #[inline(always)] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result { + self.host.borrow().reveal_adal_page( + published_level, + slot_index, + page_index, + attestation_threshold_per_mil, + destination, + ) + } + #[inline(always)] fn reveal_dal_parameters(&self) -> RollupDalParameters { self.host.borrow().reveal_dal_parameters() diff --git a/etherlink/kernel_evm/runtime/src/safe_storage.rs b/etherlink/kernel_evm/runtime/src/safe_storage.rs index d55feb706e33..0a1190554c35 100644 --- a/etherlink/kernel_evm/runtime/src/safe_storage.rs +++ b/etherlink/kernel_evm/runtime/src/safe_storage.rs @@ -197,6 +197,24 @@ impl SdkRuntime for SafeStorage<&mut Host> { .reveal_dal_page(published_level, slot_index, page_index, destination) } + #[inline(always)] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result { + self.host.reveal_adal_page( + published_level, + slot_index, + page_index, + attestation_threshold_per_mil, + destination, + ) + } + #[inline(always)] fn reveal_dal_parameters(&self) -> RollupDalParameters { self.host.reveal_dal_parameters() diff --git a/src/kernel_sdk/CHANGES.md b/src/kernel_sdk/CHANGES.md index cefd8de2f97f..617aa6ed24ff 100644 --- a/src/kernel_sdk/CHANGES.md +++ b/src/kernel_sdk/CHANGES.md @@ -3,6 +3,7 @@ ## Version next ### SDK +- Add Experimental support for Adjustable DAL reveal page - Add experimental support for compiling kernels to a Hermit RISC-V image behind the `proto-alpha` flag. - Add an experimental rollup host for RISC-V with an in-memory store behind the `experimental-host-in-memory-store` flag. - Add an `OutboxQueue` that can be used when more than 100 outbox messages are produced at a given level. diff --git a/src/kernel_sdk/host/src/runtime.rs b/src/kernel_sdk/host/src/runtime.rs index 269e5b21d31b..e3db4eb5d19a 100644 --- a/src/kernel_sdk/host/src/runtime.rs +++ b/src/kernel_sdk/host/src/runtime.rs @@ -200,6 +200,17 @@ pub trait Runtime { destination: &mut [u8], ) -> Result; + /// Reveal a Adjustable DAL page. + #[cfg(feature = "alloc")] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result; + /// Reveal the DAL parameters. fn reveal_dal_parameters(&self) -> RollupDalParameters; @@ -630,6 +641,43 @@ where } } + /// Reveal Adjustable DAL page + #[cfg(feature = "alloc")] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result { + // This will match the encoding declared for a DAL page in the Tezos protocol. + // ADAL/FIXME: Handle this case for debug mode as well + let payload: &[u8] = &[ + &[4u8], // tag + published_level.to_be_bytes().as_ref(), + &[slot_index], + page_index.to_be_bytes().as_ref(), + attestation_threshold_per_mil.to_be_bytes().as_ref(), + ] + .concat(); + + let res = unsafe { + SmartRollupCore::reveal( + self, + payload.as_ptr(), + payload.len(), + destination.as_mut_ptr(), + destination.len(), + ) + }; + + match Error::wrap(res) { + Ok(size) => Ok(size), + Err(e) => Err(RuntimeError::HostErr(e)), + } + } + fn reveal_dal_parameters(&self) -> RollupDalParameters { let mut destination = [0u8; DAL_PARAMETERS_SIZE]; // This will match the encoding declared for revealing DAL parameters in the Tezos protocol. diff --git a/src/kernel_sdk/host/src/runtime/unwindable.rs b/src/kernel_sdk/host/src/runtime/unwindable.rs index 63e89b58c0c4..a55b87ec1d38 100644 --- a/src/kernel_sdk/host/src/runtime/unwindable.rs +++ b/src/kernel_sdk/host/src/runtime/unwindable.rs @@ -191,6 +191,24 @@ impl Runtime for UnwindableRuntime { ) } + #[cfg(feature = "alloc")] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result { + self.runtime.read().unwrap().reveal_adal_page( + published_level, + slot_index, + page_index, + attestation_threshold_per_mil, + destination, + ) + } + fn reveal_dal_parameters(&self) -> RollupDalParameters { self.runtime.read().unwrap().reveal_dal_parameters() } diff --git a/src/kernel_sdk/sdk/src/entrypoint/internal/static_input_host.rs b/src/kernel_sdk/sdk/src/entrypoint/internal/static_input_host.rs index c71c17013183..f949c39b3e2c 100644 --- a/src/kernel_sdk/sdk/src/entrypoint/internal/static_input_host.rs +++ b/src/kernel_sdk/sdk/src/entrypoint/internal/static_input_host.rs @@ -216,6 +216,24 @@ impl<'runtime, R: Runtime> Runtime for StaticInputHost<'runtime, R> { .reveal_dal_page(published_level, slot_index, page_index, destination) } + #[inline(always)] + fn reveal_adal_page( + &self, + published_level: i32, + slot_index: u8, + page_index: i16, + attestation_threshold_per_mil: i16, + destination: &mut [u8], + ) -> Result { + self.host.reveal_adal_page( + published_level, + slot_index, + page_index, + attestation_threshold_per_mil, + destination, + ) + } + #[inline(always)] fn reveal_dal_parameters(&self) -> RollupDalParameters { self.host.reveal_dal_parameters() -- GitLab