Skip to content

Commit

Permalink
stl: generate files
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 22, 2024
1 parent 6edcb48 commit 8663eef
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ edition = "2021"
rust-version = "1.77.0"
exclude = [".github"]

[[bin]]
name = "ultrasonic-stl"
required-features = ["stl"]

[lib]
name = "ultrasonic"
crate-type = ["dylib", "rlib"]
Expand Down
5 changes: 5 additions & 0 deletions scripts/typelib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cargo run --features stl --package ultrasonic --bin ultrasonic-stl -- --stl
cargo run --features stl --package ultrasonic --bin ultrasonic-stl -- --sty
cargo run --features stl --package ultrasonic --bin ultrasonic-stl -- --sta
113 changes: 113 additions & 0 deletions src/bin/ultrasonic-stl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// UltraSONIC: transactional execution layer with capability-based memory access for zk-AluVM
//
// SPDX-License-Identifier: Apache-2.0
//
// Designed in 2019-2025 by Dr Maxim Orlovsky <[email protected]>
// Written in 2024-2025 by Dr Maxim Orlovsky <[email protected]>
//
// Copyright (C) 2019-2024 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 std::fs;
use std::io::Write;

use commit_verify::stl::commit_verify_stl;
use commit_verify::CommitmentLayout;
use strict_types::stl::{std_stl, strict_types_stl};
use strict_types::{parse_args, SystemBuilder};
use ultrasonic::stl::usonic_stl;
use ultrasonic::{Codex, Contract, Operation};
use zkaluvm::stl::aluvm_stl;
use zkaluvm::zkstl::finite_field_stl;

fn main() {
let (format, dir) = parse_args();

let lib = usonic_stl();
lib.serialize(
format,
dir.as_ref(),
"0.13.0",
Some(
"
Description: Transactional execution layer with capability-based memory access for zk-AluVM
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
All rights reserved.
License: Apache-2.0",
),
)
.expect("unable to write to the file");

let std = std_stl();
let ff = finite_field_stl();
let st = strict_types_stl();
let cv = commit_verify_stl();
let alu = aluvm_stl();

let dir = dir.unwrap_or_else(|| ".".to_owned());
let sys = SystemBuilder::new()
.import(std)
.unwrap()
.import(st)
.unwrap()
.import(ff)
.unwrap()
.import(cv)
.unwrap()
.import(alu)
.unwrap()
.import(lib)
.unwrap()
.finalize()
.expect("Not all libraries present");

let mut file = fs::File::create(format!("{dir}/UltraSONIC.vesper")).unwrap();
writeln!(
file,
"{{-
Description: Transactional execution layer with capability-based memory access for zk-AluVM
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
All rights reserved.
License: Apache-2.0
-}}
@@lexicon(types+commitments)
"
)
.unwrap();

writeln!(file, "\nvesper Codex:\n").unwrap();
let layout = Codex::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("UltraSONIC.Codex").unwrap();
writeln!(file, "{tt}").unwrap();

writeln!(file, "\nvesper Contract:\n").unwrap();
let layout = Contract::<0>::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("UltraSONIC.Contract0").unwrap();
writeln!(file, "{tt}").unwrap();

writeln!(file, "\nvesper Operation:\n").unwrap();
let layout = Operation::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("UltraSONIC.Operation").unwrap();
writeln!(file, "{tt}").unwrap();
}
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{ContractId, ContractPrivate, Operation, Opid, LIB_NAME_ULTRASONIC};

/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_ULTRASONIC: &str =
"stl:uce9Urh6-~pIQenU-B9GrWzm-9KWHyzy-9xv5UIS-OwP4u2o#atomic-equator-life";
"stl:Kap_vAdl-jB83HME-3knT273-xFzyG2v-HJ_OeEO-rt8xF6c#human-century-philips";

fn _usonic_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_ULTRASONIC), tiny_bset! {
Expand Down
199 changes: 199 additions & 0 deletions stl/UltraSONIC.vesper
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{-
Description: Transactional execution layer with capability-based memory access for zk-AluVM
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
All rights reserved.
License: Apache-2.0
-}

@@lexicon(types+commitments)


vesper Codex:

commitment CodexId, hasher SHA256, tagged urn:ubideco:sonic:codex#2024-11-19
serialized Codex

rec Codex
bytes version, len 2, aka ReservedBytes2
str name, len 0..MAX8
ascii developer, aka Identity, first AsciiPrintable, rest AsciiPrintable, len 1..4096
is timestamp, I64
is fieldOrder, U256
rec inputConfig, CoreConfig
enum halt, Bool, false 0, true 1
is some, U64, option, wrapped, tag 1
rec verificationConfig, CoreConfig
enum halt, Bool, false 0, true 1
is some, U64, option, wrapped, tag 1
map verifiers, len 0..MAX8
is key, U16
rec value, LibSite
bytes libId, len 32, aka LibId
is offset, U16


vesper Contract:

commitment ContractId, hasher SHA256, tagged urn:ubideco:sonic:contract#2024-11-16
serialized Contract0

rec Contract0
bytes version, len 2, aka ReservedBytes2
rec meta, ContractMeta0
is capabilities, U32, aka ConstU320
is timestamp, I64
union name, ContractName
is unnamed, Unit, tag 0
ascii named, wrapped, aka TypeName, first AlphaCapsLodash, rest AlphaNumLodash, len 1..100, tag 1
ascii issuer, aka Identity, first AsciiPrintable, rest AsciiPrintable, len 1..4096
rec codex, Codex
bytes version, len 2, aka ReservedBytes2
str name, len 0..MAX8
ascii developer, aka Identity, first AsciiPrintable, rest AsciiPrintable, len 1..4096
is timestamp, I64
is fieldOrder, U256
rec inputConfig, CoreConfig
enum halt, Bool, false 0, true 1
is some, U64, option, wrapped, tag 1
rec verificationConfig, CoreConfig
enum halt, Bool, false 0, true 1
is some, U64, option, wrapped, tag 1
map verifiers, len 0..MAX8
is key, U16
rec value, LibSite
bytes libId, len 32, aka LibId
is offset, U16
rec genesis, Genesis
bytes codexId, len 32, aka CodexId
is callId, U16
is nonce, U256, aka Fe256
bytes blank1, len 2, aka ReservedBytes2
bytes blank2, len 2, aka ReservedBytes2
list destructible, len 0..MAX16
rec StateCell
union data, StateValue
is none, Unit, tag 0
rec single, tag 1
is first, U256, aka Fe256
rec double, tag 2
is first, U256, aka Fe256
is second, U256, aka Fe256
rec three, tag 3
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
rec four, tag 4
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
is fourth, U256, aka Fe256
is auth, U256, aka AuthToken, aka Fe256
rec some, LibSite, option, wrapped, tag 1
bytes libId, len 32, aka LibId
is offset, U16
list immutable, len 0..MAX16
rec StateData
union value, StateValue
is none, Unit, tag 0
rec single, tag 1
is first, U256, aka Fe256
rec double, tag 2
is first, U256, aka Fe256
is second, U256, aka Fe256
rec three, tag 3
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
rec four, tag 4
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
is fourth, U256, aka Fe256
bytes some, len 0..MAX16, option, wrapped, aka RawData, tag 1


vesper Operation:

commitment Opid, hasher SHA256, tagged urn:ubideco:ultrasonic:operation#2024-11-14
serialized ContractId
serialized U16
serialized Fe256
merklized Input
merklized CellAddr
merklized StateCell
merklized StateData
serialized ReservedBytes8

rec Operation
bytes contractId, len 32, aka ContractId
is callId, U16
is nonce, U256, aka Fe256
list destroying, len 0..MAX16
rec Input
rec addr, CellAddr
bytes opid, len 32, aka Opid
is pos, U16
union witness, StateValue
is none, Unit, tag 0
rec single, tag 1
is first, U256, aka Fe256
rec double, tag 2
is first, U256, aka Fe256
is second, U256, aka Fe256
rec three, tag 3
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
rec four, tag 4
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
is fourth, U256, aka Fe256
list reading, len 0..MAX16
rec CellAddr
bytes opid, len 32, aka Opid
is pos, U16
list destructible, len 0..MAX16
rec StateCell
union data, StateValue
is none, Unit, tag 0
rec single, tag 1
is first, U256, aka Fe256
rec double, tag 2
is first, U256, aka Fe256
is second, U256, aka Fe256
rec three, tag 3
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
rec four, tag 4
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
is fourth, U256, aka Fe256
is auth, U256, aka AuthToken, aka Fe256
rec some, LibSite, option, wrapped, tag 1
bytes libId, len 32, aka LibId
is offset, U16
list immutable, len 0..MAX16
rec StateData
union value, StateValue
is none, Unit, tag 0
rec single, tag 1
is first, U256, aka Fe256
rec double, tag 2
is first, U256, aka Fe256
is second, U256, aka Fe256
rec three, tag 3
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
rec four, tag 4
is first, U256, aka Fe256
is second, U256, aka Fe256
is third, U256, aka Fe256
is fourth, U256, aka Fe256
bytes some, len 0..MAX16, option, wrapped, aka RawData, tag 1

Loading

0 comments on commit 8663eef

Please sign in to comment.