From bac23552f2280dc42b0122e7a72d2a27a4cf25e8 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 17 Nov 2024 21:34:50 +0100 Subject: [PATCH] WIP on master --- src/api/alu.rs | 4 +-- src/api/api.rs | 6 ++--- src/api/embedded.rs | 4 +-- src/api/issuer.rs | 55 ++++++++++++++++++++++++++++++++++++++++ src/api/mod.rs | 4 ++- src/persistence/mod.rs | 1 + src/persistence/stock.rs | 45 ++++++++++++++++++++++++++++++++ 7 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 src/api/issuer.rs diff --git a/src/api/alu.rs b/src/api/alu.rs index 6127c97..d3f4b27 100644 --- a/src/api/alu.rs +++ b/src/api/alu.rs @@ -23,11 +23,11 @@ use aluvm::LibSite; -use super::{ApiVm, ApiVmType, StateArithm}; +use super::{ApiVm, StateArithm, VmType}; use crate::state::StructData; impl ApiVm for aluvm::Vm { - const TYPE: ApiVmType = ApiVmType::AluVM; + const TYPE: VmType = VmType::AluVM; type Arithm = AluVMArithm; type ReaderSite = LibSite; type AdaptorSite = LibSite; diff --git a/src/api/api.rs b/src/api/api.rs index d948306..6c137eb 100644 --- a/src/api/api.rs +++ b/src/api/api.rs @@ -39,7 +39,7 @@ use strict_encoding::VariantName; use strict_types::SemId; use ultrasonic::{CallId, ContractId, Ffv}; -use super::ApiVmType; +use super::VmType; use crate::state::StructData; pub type StateName = VariantName; @@ -63,7 +63,7 @@ pub struct Api { /// Virtual machine used by `state` and `readers`. /// /// NB: `verifiers` always use VM type defined by the contract itself (currently zk-AluVM). - pub vm: ApiVmType, + pub vm: VmType, /// State API defines how specific state types (both append-only and destructible) are /// constructed out of (and converted into) UltraSONIC memory cells. @@ -105,7 +105,7 @@ pub trait CallSite {} impl CallSite for T {} pub trait ApiVm { - const TYPE: ApiVmType; + const TYPE: VmType; type Arithm: StateArithm; type ReaderSite: CallSite; type AdaptorSite: CallSite; diff --git a/src/api/embedded.rs b/src/api/embedded.rs index 4e63185..966747f 100644 --- a/src/api/embedded.rs +++ b/src/api/embedded.rs @@ -21,13 +21,13 @@ // or implied. See the License for the specific language governing permissions and limitations under // the License. -use super::{ApiVm, ApiVmType, StateArithm, StateName}; +use super::{ApiVm, StateArithm, StateName, VmType}; use crate::state::StructData; pub struct EmbeddedProc; impl ApiVm for EmbeddedProc { - const TYPE: ApiVmType = ApiVmType::Embedded; + const TYPE: VmType = VmType::Embedded; type Arithm = EmbeddedArithm; type ReaderSite = EmbeddedReaders; type AdaptorSite = EmbeddedAdaptors; diff --git a/src/api/issuer.rs b/src/api/issuer.rs new file mode 100644 index 0000000..05e688e --- /dev/null +++ b/src/api/issuer.rs @@ -0,0 +1,55 @@ +// SONARE: Runtime environment for formally-verifiable distributed software +// +// SPDX-License-Identifier: Apache-2.0 +// +// Designed in 2019-2024 by Dr Maxim Orlovsky +// Written in 2024-2025 by Dr Maxim Orlovsky +// +// Copyright (C) 2019-2025 LNP/BP Standards Association, Switzerland. +// Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO), +// Institute for Distributed and Cognitive Systems (InDCS), Switzerland. +// Copyright (C) 2019-2025 Dr Maxim Orlovsky. +// All rights under the above copyrights are reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under +// the License. + +use aluvm::Vm; +use amplify::confinement::{TinyOrdMap, TinyString}; +use ultrasonic::{CallId, Ffv}; + +use super::{MethodName, StateApi, StateName, VmType}; + +/// Issuer is a form of API which issues a contract. It is a non-interface specific though. +pub struct Issuer { + pub version: Ffv, + + pub codex: CodexId, + + // TODO: Add developer etc. + /// Virtual machine used by `state` and `readers`. + /// + /// NB: `verifiers` always use VM type defined by the contract itself (currently zk-AluVM). + pub vm: VmType, + + /// State API defines how specific state types (both append-only and destructible) are + /// constructed out of (and converted into) UltraSONIC memory cells. + pub issued_state: TinyOrdMap>, + + /// Links between named transaction methods defined in the interface - and corresponding + /// verifier call ids defined by the contract. + /// + /// NB: Multiple methods from the interface may call to the came verifier. + pub issue_verifiers: TinyOrdMap, + + /// Maps error type reported by a contract verifier via `EA` value to an error description taken + /// from the interfaces. + pub issue_errors: TinyOrdMap, +} diff --git a/src/api/mod.rs b/src/api/mod.rs index 76d548d..c719523 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -24,10 +24,12 @@ mod api; pub mod embedded; pub mod alu; +mod issuer; pub use api::{Api, ApiId, ApiVm, MethodName, StateApi, StateArithm, StateName}; +pub use issuer::Issuer; -pub enum ApiVmType { +pub enum VmType { Embedded, AluVM, } diff --git a/src/persistence/mod.rs b/src/persistence/mod.rs index 7a851b5..e3e81ae 100644 --- a/src/persistence/mod.rs +++ b/src/persistence/mod.rs @@ -24,6 +24,7 @@ mod stash; mod state; mod trace; +mod stock; pub use stash::{Stash, StashProvider}; pub use state::{State, StateProvider}; diff --git a/src/persistence/stock.rs b/src/persistence/stock.rs index fa18404..ae2ab6b 100644 --- a/src/persistence/stock.rs +++ b/src/persistence/stock.rs @@ -21,9 +21,54 @@ // or implied. See the License for the specific language governing permissions and limitations under // the License. +use amplify::confinement::TinyOrdMap; +use ultrasonic::{CellAddr, Operation, Opid}; + +use super::{Stash, State, Trace}; +use crate::api::{ApiId, MethodName, StateName}; +use crate::state::{DataCell, StructData}; + pub struct Stock { pub stash: Stash, pub state: State, pub trace: Trace, pub repo: Repo, } + +impl Stock { + pub fn issue( + &mut self, + issuer: IssuerId, + call: MethodName, + append_only: TinyOrdMap, + destructible: TinyOrdMap, + ) -> Result { + // 1. Create operation + // 2. Validation operation + // 3. Add it to stash + // 4. Add to trace + // 5. Add to state + todo!() + } + + pub fn exec( + &mut self, + api: ApiId, + call: MethodName, + append_only_input: TinyOrdMap, + destructivle_input: TinyOrdMap, + append_only_output: TinyOrdMap, + destructible_output: TinyOrdMap, + ) -> Result { + todo!() + } + + pub fn validate(&mut self, other: &Stash) -> Result<(), ()> { todo!() } + + pub fn accept(&mut self, other: &ValidStash) { todo!() } + + // this should return stash-type object + pub fn subset(&self, terminals: impl Iterator) -> Result, ()> { + todo!() + } +}