-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add
miden-package
crate with Package
type to represent
compiled Miden program/library.
- Loading branch information
Showing
16 changed files
with
841 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ members = [ | |
"assembly", | ||
"core", | ||
"miden", | ||
"package", | ||
"processor", | ||
"prover", | ||
"stdlib", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "miden-package" | ||
version = "0.11.0" | ||
description = "Miden VM package" | ||
documentation = "https://docs.rs/miden-package/0.10.5" | ||
readme = "README.md" | ||
categories = ["compilers", "no-std"] | ||
keywords = ["package", "language", "miden"] | ||
license.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
edition.workspace = true | ||
|
||
[lib] | ||
bench = false | ||
doctest = false | ||
|
||
[dependencies] | ||
vm-core = { package = "miden-core", path = "../core", version = "0.11", default-features = false } | ||
# processor = { package = "miden-processor", path = "../processor", version = "0.11", default-features = false } | ||
assembly = { package = "miden-assembly", path = "../assembly", version = "0.11", default-features = false, features = [ | ||
"serde", | ||
] } | ||
serde = { version = "1.0.208", features = ["alloc", "rc", "serde_derive"] } | ||
serde_bytes = "0.11.15" | ||
serde_repr = "0.1.19" | ||
bitcode = { version = "0.6.3", default-features = false, features = ["serde"] } | ||
|
||
[dev-dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Overview | ||
|
||
TBD | ||
|
||
## Binary Format | ||
|
||
TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use alloc::{fmt, sync::Arc}; | ||
|
||
use assembly::Library; | ||
use vm_core::{utils::Deserializable, Program}; | ||
|
||
use crate::{package::MastArtifact, Digest}; | ||
|
||
pub fn deserialize_digest<'de, D>(deserializer: D) -> Result<Digest, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
const DIGEST_BYTES: usize = 32; | ||
|
||
let bytes: [u8; DIGEST_BYTES] = serde_bytes::deserialize(deserializer)?; | ||
|
||
Digest::try_from(bytes).map_err(serde::de::Error::custom) | ||
} | ||
|
||
pub fn deserialize_mast<'de, D>(deserializer: D) -> Result<MastArtifact, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
struct MastArtifactVisitor; | ||
|
||
impl<'de> serde::de::Visitor<'de> for MastArtifactVisitor { | ||
type Value = MastArtifact; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("mast artifact") | ||
} | ||
|
||
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E> | ||
where | ||
E: serde::de::Error, | ||
{ | ||
if let Some(bytes) = v.strip_prefix(b"PRG\0") { | ||
Program::read_from_bytes(bytes) | ||
.map(Arc::new) | ||
.map(MastArtifact::Executable) | ||
.map_err(serde::de::Error::custom) | ||
} else if let Some(bytes) = v.strip_prefix(b"LIB\0") { | ||
Library::read_from_bytes(bytes) | ||
.map(Arc::new) | ||
.map(MastArtifact::Library) | ||
.map_err(serde::de::Error::custom) | ||
} else { | ||
Err(serde::de::Error::invalid_value( | ||
serde::de::Unexpected::Bytes(v.get(0..4).unwrap_or(v)), | ||
&"expected valid mast artifact type tag", | ||
)) | ||
} | ||
} | ||
} | ||
deserializer.deserialize_bytes(MastArtifactVisitor) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![no_std] | ||
|
||
extern crate alloc; | ||
|
||
mod de; | ||
mod package; | ||
mod se; | ||
|
||
#[cfg(test)] | ||
extern crate std; | ||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub use self::package::{ | ||
dep::{ | ||
resolver::{ | ||
DependencyResolution, DependencyResolver, LocalResolution, | ||
MemDependencyResolverByDigest, | ||
}, | ||
Dependency, DependencyName, SystemLibraryId, | ||
}, | ||
MastArtifact, Package, PackageExport, PackageManifest, PtrDesc, Rodata, | ||
}; | ||
|
||
type Digest = vm_core::chiplets::hasher::Digest; |
Oops, something went wrong.