Skip to content

Commit

Permalink
WIP on master
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 17, 2024
1 parent b0ab8d5 commit bac2355
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/api/alu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,7 +63,7 @@ pub struct Api<Vm: ApiVm> {
/// 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.
Expand Down Expand Up @@ -105,7 +105,7 @@ pub trait CallSite {}
impl<T> CallSite for T {}

pub trait ApiVm {
const TYPE: ApiVmType;
const TYPE: VmType;
type Arithm: StateArithm;
type ReaderSite: CallSite;
type AdaptorSite: CallSite;
Expand Down
4 changes: 2 additions & 2 deletions src/api/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions src/api/issuer.rs
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
// Written in 2024-2025 by Dr Maxim Orlovsky <[email protected]>
//
// 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<StateName, StateApi<Vm>>,

/// 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<MethodName, CallId>,

/// Maps error type reported by a contract verifier via `EA` value to an error description taken
/// from the interfaces.
pub issue_errors: TinyOrdMap<u128, TinyString>,
}
4 changes: 3 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
1 change: 1 addition & 0 deletions src/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
mod stash;
mod state;
mod trace;
mod stock;

pub use stash::{Stash, StashProvider};
pub use state::{State, StateProvider};
Expand Down
45 changes: 45 additions & 0 deletions src/persistence/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StateName, StructData>,
destructible: TinyOrdMap<StateName, DataCell>,
) -> Result<Operation, ()> {
// 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<StateName, CellAddr>,
destructivle_input: TinyOrdMap<StateName, CellAddr>,
append_only_output: TinyOrdMap<StateName, StructData>,
destructible_output: TinyOrdMap<StateName, DataCell>,
) -> Result<Operation, ()> {
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<Item = Opid>) -> Result<impl Iterator<Item = &Operation>, ()> {
todo!()
}
}

0 comments on commit bac2355

Please sign in to comment.