Skip to content

Commit

Permalink
chore: feature adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
cfcosta committed Aug 4, 2024
1 parent fb23939 commit 7887f1a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 31 deletions.
17 changes: 7 additions & 10 deletions Cargo.lock

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

14 changes: 8 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions core/src/types/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
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)
Expand Down
2 changes: 1 addition & 1 deletion core/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*};
4 changes: 2 additions & 2 deletions core/src/types/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ pub enum Operation {
output: Note,
},
#[n(2)]
Fission {
Split {
#[n(0)]
input: Sealed<Note>,
#[b(1)]
outputs: Vec<Note>,
},
#[n(3)]
Fusion {
Join {
#[b(0)]
inputs: Vec<Sealed<Note>>,
#[n(1)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/types/reaction.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions core/src/types/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand All @@ -24,4 +34,17 @@ impl<T: Encode<()>> Sealed<T> {

Ok((*Impl::hash_bytes(&buf)).into())
}

pub fn seal(&self) -> Result<Seal> {
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,
})
}
}
15 changes: 4 additions & 11 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ 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"
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"]

0 comments on commit 7887f1a

Please sign in to comment.