From 94b48e1e7e947c5120b7859a2dc469085a35c55d Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 10 Apr 2025 10:40:23 +0200 Subject: [PATCH 1/3] Tezlink/Kernel: Introduce Operation Error in new module operation_result Introduced error are related to the reveal operation as this is the first operation introduce in Tezlink kernel --- etherlink/kernel_latest/tezos/src/lib.rs | 1 + .../tezos/src/operation_result.rs | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 etherlink/kernel_latest/tezos/src/operation_result.rs diff --git a/etherlink/kernel_latest/tezos/src/lib.rs b/etherlink/kernel_latest/tezos/src/lib.rs index 4539626c9124..c8c241be5437 100644 --- a/etherlink/kernel_latest/tezos/src/lib.rs +++ b/etherlink/kernel_latest/tezos/src/lib.rs @@ -4,3 +4,4 @@ pub mod block; pub mod operation; +pub mod operation_result; diff --git a/etherlink/kernel_latest/tezos/src/operation_result.rs b/etherlink/kernel_latest/tezos/src/operation_result.rs new file mode 100644 index 000000000000..b2b240c814a2 --- /dev/null +++ b/etherlink/kernel_latest/tezos/src/operation_result.rs @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2025 Functori +// +// SPDX-License-Identifier: MIT + +//! Tezos operations + +/// The whole module is inspired of `src/proto_alpha/lib_protocol/apply_result.ml` to represent the result of an operation +use std::fmt::Debug; +use tezos_data_encoding::enc as tezos_enc; +use tezos_data_encoding::nom as tezos_nom; +use tezos_data_encoding::types::Narith; +use tezos_enc::BinWriter; +use tezos_nom::NomReader; +use tezos_smart_rollup::types::{PublicKey, PublicKeyHash}; + +#[derive(Debug, PartialEq, Eq, NomReader, BinWriter)] +pub enum ValidityError { + InvalidCounter(Narith), + CantPayFees(Narith), + EmptyImplicitContract, +} + +#[derive(Debug, PartialEq, Eq, NomReader, BinWriter)] +pub enum ManagerError { + PreviouslyRevealedKey(PublicKey), + InconsistentHash(PublicKeyHash), + InconsistentPublicKey(PublicKeyHash), +} + +#[derive(Debug, PartialEq, Eq, NomReader, BinWriter)] +pub enum OperationError { + Validation(ValidityError), + Manager(ManagerError), +} + +impl From for OperationError { + fn from(value: ValidityError) -> Self { + Self::Validation(value) + } +} + +impl From for OperationError { + fn from(value: ManagerError) -> Self { + Self::Manager(value) + } +} -- GitLab From c063aa855f9fd2b2c5764f03852ce9cde1876b42 Mon Sep 17 00:00:00 2001 From: arnaud Date: Wed, 9 Apr 2025 17:01:40 +0200 Subject: [PATCH 2/3] Tezlink/Kernel: Introduce Operation receipts in tezos crate --- .../tezos/src/operation_result.rs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/etherlink/kernel_latest/tezos/src/operation_result.rs b/etherlink/kernel_latest/tezos/src/operation_result.rs index b2b240c814a2..5675497b7014 100644 --- a/etherlink/kernel_latest/tezos/src/operation_result.rs +++ b/etherlink/kernel_latest/tezos/src/operation_result.rs @@ -9,8 +9,10 @@ use std::fmt::Debug; use tezos_data_encoding::enc as tezos_enc; use tezos_data_encoding::nom as tezos_nom; use tezos_data_encoding::types::Narith; +use tezos_data_encoding::types::Zarith; use tezos_enc::BinWriter; use tezos_nom::NomReader; +use tezos_smart_rollup::types::Contract; use tezos_smart_rollup::types::{PublicKey, PublicKeyHash}; #[derive(Debug, PartialEq, Eq, NomReader, BinWriter)] @@ -44,3 +46,66 @@ impl From for OperationError { Self::Manager(value) } } + +pub trait ManagerKind { + type Success: PartialEq + Debug + BinWriter + for<'a> NomReader<'a>; + + fn kind() -> Self; +} + +/// Empty struct to implement [ManagerKind] trait for Reveal +#[derive(PartialEq, Debug)] +pub struct Reveal; + +#[derive(PartialEq, Debug, NomReader, BinWriter)] +pub struct RevealSuccess { + pub consumed_gas: Narith, +} + +#[derive(PartialEq, Debug, NomReader, BinWriter)] +pub struct RevealContent { + pk: PublicKey, +} + +impl ManagerKind for Reveal { + type Success = RevealSuccess; + + fn kind() -> Self { + Self + } +} + +// Inspired from `src/proto_alpha/lib_protocol/apply_operation_result.ml` +// Still need to implement Backtracked and Skipped +#[derive(PartialEq, Debug, BinWriter, NomReader)] +pub enum OperationStatus { + Applied(M::Success), + Failed(Vec), +} + +/// A [Balance] updates can be triggered on different target +#[derive(PartialEq, Debug, NomReader, BinWriter)] +pub enum Balance { + Account(Contract), + BlockFees, +} + +/// Depending of the sign of [credited], the account is credited or debited +#[derive(PartialEq, Debug, NomReader, BinWriter)] +pub struct BalanceUpdate { + pub balance: Balance, + pub credited: Zarith, +} + +// Inspired from `src/proto_alpha/lib_protocol/apply_results.ml` +// Still need to implement internal_results +#[derive(PartialEq, Debug, NomReader, BinWriter)] +pub struct ManagerReceipt { + pub balance_updates: Vec, + pub result: OperationStatus, +} + +#[derive(PartialEq, Debug, NomReader, BinWriter)] +pub enum OperationReceipt { + RevealReceipt(ManagerReceipt), +} -- GitLab From a08fda0b0aa5c5f102837414c15bf6c105103c34 Mon Sep 17 00:00:00 2001 From: arnaud Date: Wed, 7 May 2025 13:08:40 +0200 Subject: [PATCH 3/3] Tezlink/Kernel: Replace BigUint with Narith in operation --- .../kernel_latest/tezos/src/operation.rs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/etherlink/kernel_latest/tezos/src/operation.rs b/etherlink/kernel_latest/tezos/src/operation.rs index 45bbb5007a42..8da026ad6fbd 100644 --- a/etherlink/kernel_latest/tezos/src/operation.rs +++ b/etherlink/kernel_latest/tezos/src/operation.rs @@ -10,9 +10,10 @@ use nom::error::{ErrorKind, ParseError}; use nom::{bytes::complete::take, Finish}; use primitive_types::H256; use tezos_crypto_rs::hash::{HashType, UnknownSignature}; +use tezos_data_encoding::types::Narith; use tezos_data_encoding::{ - enc::{self as tezos_enc, BinError, BinResult, BinWriter}, - nom::{self as tezos_nom, error::DecodeError, NomError, NomReader, NomResult}, + enc::{BinError, BinResult, BinWriter}, + nom::{error::DecodeError, NomError, NomReader, NomResult}, }; use tezos_smart_rollup::types::PublicKey; use tezos_smart_rollup::types::PublicKeyHash; @@ -37,7 +38,7 @@ impl OperationContent { let (array, pk) = PublicKey::nom_read(bytes)?; NomResult::Ok((array, Self::Reveal { pk })) } - _ => Err(nom::Err::Error(tezos_nom::NomError::invalid_tag( + _ => Err(nom::Err::Error(NomError::invalid_tag( bytes, tag.to_string(), ))), @@ -62,10 +63,10 @@ impl BinWriter for OperationContent { #[derive(PartialEq, Debug)] pub struct ManagerOperation { pub source: PublicKeyHash, - pub fee: num_bigint::BigUint, - pub counter: num_bigint::BigUint, - pub gas_limit: num_bigint::BigUint, - pub storage_limit: num_bigint::BigUint, + pub fee: Narith, + pub counter: Narith, + pub gas_limit: Narith, + pub storage_limit: Narith, pub operation: OperationContent, } @@ -87,13 +88,13 @@ impl BinWriter for ManagerOperation { // Push data related to the operation source.bin_write(data)?; - tezos_enc::n_bignum(fee, data)?; + fee.bin_write(data)?; - tezos_enc::n_bignum(counter, data)?; + counter.bin_write(data)?; - tezos_enc::n_bignum(gas_limit, data)?; + gas_limit.bin_write(data)?; - tezos_enc::n_bignum(storage_limit, data)?; + storage_limit.bin_write(data)?; // Append the operation operation.bin_write(data)?; @@ -110,13 +111,13 @@ impl NomReader<'_> for ManagerOperation { let (bytes, source) = PublicKeyHash::nom_read(bytes)?; - let (bytes, fee) = tezos_nom::n_bignum(bytes)?; + let (bytes, fee) = Narith::nom_read(bytes)?; - let (bytes, counter) = tezos_nom::n_bignum(bytes)?; + let (bytes, counter) = Narith::nom_read(bytes)?; - let (bytes, gas_limit) = tezos_nom::n_bignum(bytes)?; + let (bytes, gas_limit) = Narith::nom_read(bytes)?; - let (bytes, storage_limit) = tezos_nom::n_bignum(bytes)?; + let (bytes, storage_limit) = Narith::nom_read(bytes)?; let (bytes, operation) = OperationContent::from_bytes(tag, bytes)?; @@ -198,10 +199,7 @@ impl Operation { pub fn try_from_bytes(data: &[u8]) -> Result> { let (remaining, operation) = Self::nom_read(data).finish()?; if !remaining.is_empty() { - return Err(tezos_nom::NomError::from_error_kind( - remaining, - ErrorKind::NonEmpty, - )); + return Err(NomError::from_error_kind(remaining, ErrorKind::NonEmpty)); } Ok(operation) } -- GitLab