Skip to content

Commit

Permalink
Merge branch 'v0.11' into validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 25, 2023
2 parents 1b4fbcd + 709363e commit 81c58f2
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 62 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ wasm-bindgen-test = "0.3"
features = [ "all" ]

[patch.crates-io]
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "doubleanchors" }
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
aluvm = { git = "https://github.com/AluVM/rust-aluvm", branch = "v0.11" }
4 changes: 2 additions & 2 deletions src/schema/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::LIB_NAME_RGB;

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
#[display(LowerHex)]
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[cfg_attr(
Expand All @@ -46,7 +46,7 @@ impl AssignmentType {

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
#[display(LowerHex)]
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[cfg_attr(
Expand Down
6 changes: 3 additions & 3 deletions src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::{Ffv, GlobalStateSchema, Occurrences, LIB_NAME_RGB};

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
#[display(LowerHex)]
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[cfg_attr(
Expand All @@ -54,7 +54,7 @@ impl GlobalStateType {

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
#[display(LowerHex)]
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
Expand All @@ -70,7 +70,7 @@ impl ExtensionType {

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
#[display(LowerHex)]
#[display("0x{0:04X}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]
Expand Down
5 changes: 5 additions & 0 deletions src/schema/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ impl Script {
Script::AluVM(_) => VmType::AluVM,
}
}

pub fn as_alu_script(&self) -> &AluScript {
let Script::AluVM(alu) = self;
alu
}
}
20 changes: 18 additions & 2 deletions src/vm/isa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeSet;
use std::collections::{BTreeSet, HashSet};
use std::ops::RangeInclusive;

use aluvm::isa;
use aluvm::isa::{Bytecode, BytecodeError, ExecStep, InstructionSet};
use aluvm::library::{CodeEofError, LibSite, Read, Write};
use aluvm::reg::CoreRegs;
use aluvm::reg::{CoreRegs, Reg};

use super::{ContractOp, TimechainOp};
use crate::validation::OpInfo;
Expand All @@ -52,6 +52,22 @@ impl InstructionSet for RgbIsa {
bset! {"RGB"}
}

fn src_regs(&self) -> HashSet<Reg> {
match self {
RgbIsa::Contract(op) => op.src_regs(),
RgbIsa::Timechain(op) => op.src_regs(),
RgbIsa::Fail(_) => set![],
}
}

fn dst_regs(&self) -> HashSet<Reg> {
match self {
RgbIsa::Contract(op) => op.dst_regs(),
RgbIsa::Timechain(op) => op.dst_regs(),
RgbIsa::Fail(_) => set![],
}
}

fn exec(&self, regs: &mut CoreRegs, site: LibSite, context: &Self::Context<'_>) -> ExecStep {
match self {
RgbIsa::Contract(op) => op.exec(regs, site, context),
Expand Down
41 changes: 41 additions & 0 deletions src/vm/macroasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// RGB Core Library: consensus layer for RGB smart contracts.
//
// SPDX-License-Identifier: Apache-2.0
//
// Written in 2019-2023 by
// Dr Maxim Orlovsky <[email protected]>
//
// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved.
// Copyright (C) 2019-2023 Dr Maxim Orlovsky. All rights 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.

#[macro_export]
macro_rules! rgbasm {
($( $tt:tt )+) => {{ #[allow(unused_imports)] {
use $crate::vm::{RgbIsa, ContractOp, TimechainOp};
use $crate::vm::aluasm_isa;
use $crate::isa_instr;
aluasm_isa! { RgbIsa => $( $tt )+ }
} }};
}

#[macro_export]
macro_rules! isa_instr {
(pcvs $no:literal) => {{ RgbIsa::Contract(ContractOp::PcVs($no.into())) }};
(pccs $no1:literal, $no2:literal) => {{ RgbIsa::Contract(ContractOp::PcCs($no1.into(), $no2.into())) }};
(ldg $t:literal, $no:literal,s16[$s_idx:literal]) => {{ RgbIsa::Contract(ContractOp::LdG($t.into(), $no, RegS::from($s_idx))) }};
(lds $t:literal, $no:literal,s16[$s_idx:literal]) => {{ RgbIsa::Contract(ContractOp::LdS($t.into(), $no, RegS::from($s_idx))) }};
(ldp $t:literal, $no:literal,s16[$s_idx:literal]) => {{ RgbIsa::Contract(ContractOp::LdP($t.into(), $no, RegS::from($s_idx))) }};
($op:ident $($tt:tt)+) => {{ compile_error!(concat!("unknown RGB assembly opcode `", stringify!($op), "`")) }};
}
3 changes: 3 additions & 0 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ mod op_contract;
mod op_timechain;
mod script;
mod runtime;
#[macro_use]
mod macroasm;

pub use aluvm::aluasm_isa;
pub use isa::RgbIsa;
pub use op_contract::ContractOp;
pub use op_timechain::TimechainOp;
Expand Down
Loading

0 comments on commit 81c58f2

Please sign in to comment.