Skip to content

Commit

Permalink
feat: implement serialization/deserialization for Operation (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer authored Jul 11, 2024
1 parent 63170ca commit bbd3bb7
Show file tree
Hide file tree
Showing 12 changed files with 546 additions and 307 deletions.
4 changes: 2 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ pub mod prettier {

mod operations;
pub use operations::{
AdviceInjector, AssemblyOp, DebugOptions, Decorator, DecoratorIterator, DecoratorList,
Operation, SignatureKind,
opcode_constants::*, AdviceInjector, AssemblyOp, DebugOptions, Decorator, DecoratorIterator,
DecoratorList, Operation, SignatureKind,
};

pub mod stack;
Expand Down
12 changes: 7 additions & 5 deletions core/src/mast/node/call_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use core::fmt;
use miden_crypto::{hash::rpo::RpoDigest, Felt};
use miden_formatting::prettier::PrettyPrint;

use crate::{chiplets::hasher, Operation};

use crate::mast::{MastForest, MastNodeId, MerkleTreeNode};
use crate::{
chiplets::hasher,
mast::{MastForest, MastNodeId, MerkleTreeNode},
OPCODE_CALL, OPCODE_SYSCALL,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CallNode {
Expand All @@ -17,9 +19,9 @@ pub struct CallNode {
/// Constants
impl CallNode {
/// The domain of the call block (used for control block hashing).
pub const CALL_DOMAIN: Felt = Felt::new(Operation::Call.op_code() as u64);
pub const CALL_DOMAIN: Felt = Felt::new(OPCODE_CALL as u64);
/// The domain of the syscall block (used for control block hashing).
pub const SYSCALL_DOMAIN: Felt = Felt::new(Operation::SysCall.op_code() as u64);
pub const SYSCALL_DOMAIN: Felt = Felt::new(OPCODE_SYSCALL as u64);
}

/// Constructors
Expand Down
4 changes: 2 additions & 2 deletions core/src/mast/node/dyn_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use miden_crypto::{hash::rpo::RpoDigest, Felt};

use crate::{
mast::{MastForest, MerkleTreeNode},
Operation,
OPCODE_DYN,
};

#[derive(Debug, Clone, Default, PartialEq, Eq)]
Expand All @@ -13,7 +13,7 @@ pub struct DynNode;
/// Constants
impl DynNode {
/// The domain of the Dyn block (used for control block hashing).
pub const DOMAIN: Felt = Felt::new(Operation::Dyn.op_code() as u64);
pub const DOMAIN: Felt = Felt::new(OPCODE_DYN as u64);
}

impl MerkleTreeNode for DynNode {
Expand Down
11 changes: 7 additions & 4 deletions core/src/mast/node/join_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use core::fmt;

use miden_crypto::{hash::rpo::RpoDigest, Felt};

use crate::{chiplets::hasher, prettier::PrettyPrint, Operation};

use crate::mast::{MastForest, MastNodeId, MerkleTreeNode};
use crate::{
chiplets::hasher,
mast::{MastForest, MastNodeId, MerkleTreeNode},
prettier::PrettyPrint,
OPCODE_JOIN,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JoinNode {
Expand All @@ -15,7 +18,7 @@ pub struct JoinNode {
/// Constants
impl JoinNode {
/// The domain of the join block (used for control block hashing).
pub const DOMAIN: Felt = Felt::new(Operation::Join.op_code() as u64);
pub const DOMAIN: Felt = Felt::new(OPCODE_JOIN as u64);
}

/// Constructors
Expand Down
10 changes: 6 additions & 4 deletions core/src/mast/node/loop_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use core::fmt;
use miden_crypto::{hash::rpo::RpoDigest, Felt};
use miden_formatting::prettier::PrettyPrint;

use crate::{chiplets::hasher, Operation};

use crate::mast::{MastForest, MastNodeId, MerkleTreeNode};
use crate::{
chiplets::hasher,
mast::{MastForest, MastNodeId, MerkleTreeNode},
OPCODE_LOOP,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LoopNode {
Expand All @@ -16,7 +18,7 @@ pub struct LoopNode {
/// Constants
impl LoopNode {
/// The domain of the loop node (used for control block hashing).
pub const DOMAIN: Felt = Felt::new(Operation::Loop.op_code() as u64);
pub const DOMAIN: Felt = Felt::new(OPCODE_LOOP as u64);
}

/// Constructors
Expand Down
10 changes: 6 additions & 4 deletions core/src/mast/node/split_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use core::fmt;
use miden_crypto::{hash::rpo::RpoDigest, Felt};
use miden_formatting::prettier::PrettyPrint;

use crate::{chiplets::hasher, Operation};

use crate::mast::{MastForest, MastNodeId, MerkleTreeNode};
use crate::{
chiplets::hasher,
mast::{MastForest, MastNodeId, MerkleTreeNode},
OPCODE_SPLIT,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SplitNode {
Expand All @@ -16,7 +18,7 @@ pub struct SplitNode {
/// Constants
impl SplitNode {
/// The domain of the split node (used for control block hashing).
pub const DOMAIN: Felt = Felt::new(Operation::Split.op_code() as u64);
pub const DOMAIN: Felt = Felt::new(OPCODE_SPLIT as u64);
}

/// Constructors
Expand Down
Loading

0 comments on commit bbd3bb7

Please sign in to comment.