-
Notifications
You must be signed in to change notification settings - Fork 317
feat: serialize trusted trace proving inputs #3284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c2916ba
35922a0
cd6c0de
948432d
0139d6b
254aac9
9dff27c
893bcd5
b4d632a
e9669b9
26ea7f7
0c4c6f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,9 @@ use proptest::prelude::*; | |
| #[cfg(feature = "serde")] | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[cfg(feature = "serde")] | ||
| use crate::serde::SliceReader; | ||
|
|
||
| mod node; | ||
| #[cfg(any(test, feature = "arbitrary"))] | ||
| pub use node::arbitrary; | ||
|
|
@@ -61,19 +64,17 @@ pub use node::{ | |
| OpBatch, SplitNode, SplitNodeBuilder, | ||
| }; | ||
|
|
||
| #[cfg(feature = "serde")] | ||
| use crate::serde::{Deserializable, Serializable, SliceReader}; | ||
| use crate::{ | ||
| Felt, Word, | ||
| advice::AdviceMap, | ||
| serde::{ByteWriter, DeserializationError}, | ||
| serde::{ByteWriter, Deserializable, DeserializationError, Serializable}, | ||
| utils::{Idx, IndexVec, hash_string_to_word}, | ||
| }; | ||
|
|
||
| mod serialization; | ||
| pub use serialization::{ | ||
| AdviceMapView, AdviceValueView, MastForestReadMode, MastForestReadView, MastForestView, | ||
| MastForestWireView, MastNodeEntry, MastNodeInfo, | ||
| MastForestWireView, MastNodeEntry, MastNodeInfo, SparseMastForestReadOptions, | ||
| }; | ||
|
|
||
| mod untrusted; | ||
|
|
@@ -838,7 +839,10 @@ impl<T: ExecutableMastForest + ?Sized> ExecutableMastForest for Arc<T> { | |
| #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
| #[cfg_attr(feature = "serde", serde(transparent))] | ||
| #[cfg_attr(all(feature = "arbitrary", test), miden_test_serde_macros::serde_test)] | ||
| #[cfg_attr( | ||
| all(feature = "arbitrary", test), | ||
| miden_test_serde_macros::serde_test(binary_serde(true)) | ||
| )] | ||
|
huitseeker marked this conversation as resolved.
|
||
| pub struct MastNodeId(u32); | ||
|
|
||
| /// Operations that mutate a MAST often produce this mapping between old and new NodeIds. | ||
|
|
@@ -907,6 +911,24 @@ impl From<MastNodeId> for u32 { | |
| } | ||
| } | ||
|
|
||
| impl Serializable for MastNodeId { | ||
| fn write_into<W: ByteWriter>(&self, target: &mut W) { | ||
| Serializable::write_into(&self.0, target); | ||
| } | ||
| } | ||
|
|
||
| impl Deserializable for MastNodeId { | ||
| fn read_from<R: crate::serde::ByteReader>( | ||
| source: &mut R, | ||
| ) -> Result<Self, DeserializationError> { | ||
| Ok(Self(<u32 as Deserializable>::read_from(source)?)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is safe. I remember previously we've always avoided deserializing MAST node IDs directly and preferred using If this is not a concern now, we should explicitly document this. But also, I'm a bit weary of adding this serialization option as it could be easily misused.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| fn min_serialized_size() -> usize { | ||
| <u32 as Deserializable>::min_serialized_size() | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for MastNodeId { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "MastNodeId({})", self.0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,9 +76,14 @@ | |
| //! same contiguous array on the wire. | ||
| //! | ||
| //! Public entry points adopt these policies: | ||
| //! - [`MastForest::read_from_bytes`]: trusted execution payload, no hashless support. | ||
| //! - [`MastForest::read_from_bytes`]: trusted dense execution payload, no hashless or sparse | ||
| //! support. | ||
| //! - [`MastForestWireView::new`]: trusted wire-backed cache access; rejects hashless and legacy | ||
| //! debug-bearing payloads. | ||
| //! debug-bearing payloads, and rejects sparse payloads. | ||
| //! - [`crate::mast::SparseMastForest::read_from_bytes`] / | ||
| //! [`crate::mast::SparseMastForest::read_from_bytes_with_options`]: trusted sparse replay | ||
| //! payloads for serialized trace-generation inputs. Sparse payloads currently carry full-node | ||
| //! digests and do not recompute them on read. | ||
| //! - [`crate::mast::UntrustedMastForest::read_from_bytes`] / | ||
| //! [`crate::mast::UntrustedMastForest::read_from_bytes_with_options`]: untrusted parsing plus | ||
| //! later validation before use. | ||
|
|
@@ -112,6 +117,9 @@ mod layout; | |
| pub(super) use layout::ForestLayout; | ||
| use layout::{OffsetTrackingReader, TrackingReader, WireFlags, read_header_and_scan_layout}; | ||
|
|
||
| mod sparse; | ||
| pub use sparse::SparseMastForestReadOptions; | ||
|
|
||
| mod resolved; | ||
| use resolved::{ResolvedSerializedForest, basic_block_offset_for_node_index}; | ||
|
|
||
|
|
@@ -171,10 +179,16 @@ const MAGIC: &[u8; 4] = b"MAST"; | |
| /// from local structure. | ||
| pub(super) const FLAG_HASHLESS: u8 = 0x02; | ||
|
|
||
| /// Flag indicating that the payload uses sparse MAST replay serialization. | ||
| /// | ||
| /// Sparse payloads preserve the source forest's [`MastNodeId`] space and therefore cannot be read | ||
| /// through dense [`MastForest`] entry points. | ||
| pub(super) const FLAG_SPARSE: u8 = 0x04; | ||
|
Comment on lines
+182
to
+186
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: what's the benefit of combining regular and sparse MAST forest serializations? Could we treat sparse MAST forest as a completely separate object with its own serialization? I think the use cases for these are fairly distinct and I don't foresee the need to serialize sparse MAST forest outside of the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in #3313: Sparse payloads now use their own magic and version, and has its own writers/readers. |
||
|
|
||
| /// Mask for reserved flag bits that must be zero. | ||
| /// | ||
| /// Bit 0 and bits 2-7 are reserved for future use. If any are set, deserialization fails. | ||
| const FLAGS_RESERVED_MASK: u8 = 0xfd; | ||
| /// Bit 0 and bits 3-7 are reserved for future use. If any are set, deserialization fails. | ||
| const FLAGS_RESERVED_MASK: u8 = 0xf9; | ||
|
|
||
| /// The format version. | ||
| /// | ||
|
|
@@ -201,13 +215,15 @@ const FLAGS_RESERVED_MASK: u8 = 0xfd; | |
| /// records. MAST nodes are metadata-free identifiers. Before any public release on this branch, | ||
| /// the same unreleased wire version also reserved bit 0 and stopped using it as a forest-level | ||
| /// debug-presence flag. | ||
| /// - [0, 0, 5]: Added SPARSE flag (bit 2). Sparse payloads preserve sparse replay IDs and are | ||
| /// accepted only by SparseMastForest readers. | ||
| /// | ||
| /// Legacy wire versions (pre-#3192 decorator terminology): | ||
| /// [0,0,1] stored metadata as serialized decorator variants in CSR per-node slots. | ||
| /// [0,0,2] removed AssemblyOp from the decorator enum and stored them separately in DebugInfo. | ||
| /// [0,0,3] removed the unused decorator-count wire field. | ||
| /// [0,0,4] eliminated the decorator wire slots entirely. | ||
| const VERSION: [u8; 3] = [0, 0, 4]; | ||
| const VERSION: [u8; 3] = [0, 0, 5]; | ||
|
|
||
| // MAST FOREST SERIALIZATION/DESERIALIZATION | ||
| // ================================================================================================ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are doing this because we don't have have serialization implemented for
VecDequeinmiden-crypto? If so, should we just implement it it there?If we'd rather keep it here for now, I'd move it
src/utils/mod.rs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3314 moves the
VecDequehelper tocore::utils. I did not add it tomiden-cryptofor now because (besides release propagation delays) the only current caller is trace replay.