-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1055 from 0xPolygonMiden/grjte-dyn-block
Add Dyn block to MAST
- Loading branch information
Showing
12 changed files
with
372 additions
and
5 deletions.
There are no files selected for viewing
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,64 @@ | ||
use super::{fmt, Digest, Felt, Operation}; | ||
|
||
// CONSTANTS | ||
// ================================================================================================ | ||
|
||
/// The Dyn block is represented by a constant, which is set to be the hash of two empty words | ||
/// ([ZERO, ZERO, ZERO, ZERO]) with a domain value of `DYN_DOMAIN`, i.e. | ||
/// hasher::merge_in_domain(&[Digest::default(), Digest::default()], Dyn::DOMAIN) | ||
const DYN_CONSTANT: Digest = Digest::new([ | ||
Felt::new(8115106948140260551), | ||
Felt::new(13491227816952616836), | ||
Felt::new(15015806788322198710), | ||
Felt::new(16575543461540527115), | ||
]); | ||
|
||
// Dyn BLOCK | ||
// ================================================================================================ | ||
/// Block for dynamic code where the target is specified by the stack. | ||
/// | ||
/// Executes the code block referenced by the hash on top of the stack. Fails if the body is | ||
/// unavailable to the VM, or if the execution of the dynamically-specified code block fails. | ||
/// | ||
/// The child of a Dyn block (the target specified by the stack) is always dynamic and does not | ||
/// affect the representation of the Dyn block. Therefore all Dyn blocks are represented by the same | ||
/// constant (rather than by unique hashes), which is computed as an RPO hash of two empty words | ||
/// ([ZERO, ZERO, ZERO, ZERO]) with a domain value of `DYN_DOMAIN`. | ||
#[derive(Clone, Debug)] | ||
pub struct Dyn {} | ||
|
||
impl Dyn { | ||
// CONSTANTS | ||
// -------------------------------------------------------------------------------------------- | ||
/// The domain of the Dyn block (used for control block hashing). | ||
pub const DOMAIN: Felt = Felt::new(Operation::Dyn.op_code() as u64); | ||
|
||
// CONSTRUCTOR | ||
// -------------------------------------------------------------------------------------------- | ||
/// Returns a new [Dyn] block instantiated with the specified function body hash. | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
// PUBLIC ACCESSORS | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
/// Returns a hash of this code block. | ||
pub fn hash(&self) -> Digest { | ||
DYN_CONSTANT | ||
} | ||
} | ||
|
||
impl Default for Dyn { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl fmt::Display for Dyn { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "Dyn")?; | ||
|
||
Ok(()) | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.