diff --git a/Cargo.lock b/Cargo.lock index 73a52bf..a832702 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -878,12 +878,6 @@ dependencies = [ "glob", ] -[[package]] -name = "fixedbitset" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" - [[package]] name = "flate2" version = "1.0.30" @@ -1336,6 +1330,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "iai" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" + [[package]] name = "idna" version = "0.5.0" @@ -1632,7 +1632,6 @@ name = "mugraph-core" version = "0.0.1" dependencies = [ "bytemuck", - "fixedbitset", "hex", "minicbor", "onlyerror", @@ -1649,16 +1648,14 @@ name = "mugraph-core-programs" version = "0.0.1" dependencies = [ "mugraph-core", - "mugraph-core-programs-guest", "risc0-build", - "risc0-zkvm", ] [[package]] name = "mugraph-core-programs-guest" version = "0.0.1" dependencies = [ - "minicbor", + "iai", "mugraph-core", "risc0-zkvm", ] diff --git a/core/Cargo.toml b/core/Cargo.toml index b275aec..24c8a79 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -4,18 +4,20 @@ version = "0.0.1" edition = "2021" [dependencies] -minicbor = { version = "0.24.2", features = ["std", "derive"] } +bytemuck = "1.16.3" +hex = "0.4.3" +minicbor = { version = "0.24.2", default-features = false, features = [ + "std", + "derive", +] } +onlyerror = { version = "0.1.4", default-features = false } +paste = "1.0.15" risc0-zkvm = { version = "1.0.5" } serde = { version = "1.0.204", features = ["derive"] } serde_bytes = "0.11.15" proptest = { version = "1.5.0", optional = true } test-strategy = { version = "0.4.0", optional = true } -bytemuck = "1.16.3" -fixedbitset = "0.5.7" -paste = "1.0.15" -onlyerror = "0.1.4" -hex = "0.4.3" [features] default = ["proptest"] diff --git a/core/src/types/hash.rs b/core/src/types/hash.rs index 5976e02..5450773 100644 --- a/core/src/types/hash.rs +++ b/core/src/types/hash.rs @@ -84,6 +84,19 @@ impl From<[u32; 8]> for Hash { } } +impl TryFrom<&[u8]> for Hash { + type Error = crate::error::Error; + + fn try_from(value: &[u8]) -> Result { + assert_eq!(value.len(), 32); + + let mut result = Hash::default(); + result.0.copy_from_slice(value); + + Ok(result) + } +} + impl LowerHex for Hash { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Display::fmt(&hex::encode(self.0), f) diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index 292e90e..f81c7cc 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -4,4 +4,4 @@ mod operation; mod reaction; mod sealed; -pub use self::{hash::Hash, note::Note, operation::Operation, reaction::Reaction, sealed::Sealed}; +pub use self::{hash::*, note::*, operation::*, reaction::*, sealed::*}; diff --git a/core/src/types/operation.rs b/core/src/types/operation.rs index 4c15db1..e2bf1cc 100644 --- a/core/src/types/operation.rs +++ b/core/src/types/operation.rs @@ -25,14 +25,14 @@ pub enum Operation { output: Note, }, #[n(2)] - Fission { + Split { #[n(0)] input: Sealed, #[b(1)] outputs: Vec, }, #[n(3)] - Fusion { + Join { #[b(0)] inputs: Vec>, #[n(1)] diff --git a/core/src/types/reaction.rs b/core/src/types/reaction.rs index b63d8b0..b171486 100644 --- a/core/src/types/reaction.rs +++ b/core/src/types/reaction.rs @@ -1,6 +1,6 @@ use minicbor::{Decode, Encode}; -pub use crate::types::Hash; +pub use crate::types::*; #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] pub struct Reaction { diff --git a/core/src/types/sealed.rs b/core/src/types/sealed.rs index 774667f..0635fdb 100644 --- a/core/src/types/sealed.rs +++ b/core/src/types/sealed.rs @@ -4,6 +4,16 @@ use serde::{Deserialize, Serialize}; use crate::{error::Result, types::Hash}; +#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize)] +pub struct Seal { + #[n(0)] + pub parent: Hash, + #[n(1)] + pub index: u8, + #[n(2)] + pub data: Hash, +} + #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize)] #[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))] pub struct Sealed { @@ -24,4 +34,17 @@ impl> Sealed { Ok((*Impl::hash_bytes(&buf)).into()) } + + pub fn seal(&self) -> Result { + let mut buf = Vec::new(); + let mut encoder = Encoder::new(&mut buf); + encoder.encode(&self.data)?; + let data = (*Impl::hash_bytes(&buf)).into(); + + Ok(Seal { + parent: self.parent, + index: self.index, + data, + }) + } } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 55ef30a..cde0301 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -4,9 +4,10 @@ version = "0.0.1" edition = "2021" [dependencies] -minicbor = "0.24.2" mugraph-core = { path = "../core", default-features = false } mugraph-core-programs = { path = "../core/programs" } + +minicbor = "0.24.2" risc0-zkvm = { version = "1.0.5", features = ["std"] } tracing = "0.1.40" tracing-subscriber = "0.3.18" @@ -14,13 +15,5 @@ tracing-timing = "0.6.0" [features] default = [] -metal = [ - "mugraph-core-programs/metal", - "mugraph-core/metal", - "risc0-zkvm/metal", -] -cuda = [ - "mugraph-core-programs/cuda", - "mugraph-core/cuda", - "risc0-zkvm/cuda", -] +metal = ["risc0-zkvm/metal"] +cuda = ["risc0-zkvm/cuda"]