Skip to content

Commit

Permalink
refactor: update comments, add constant for zero word
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Jun 1, 2024
1 parent 42f65c4 commit 40ba7b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Replaced `cargo-make` with just `make` for running tasks (#696).
* [BREAKING] Introduce `OutputNote::Partial` variant (#698).
* [BREAKING] Split `Account` struct constructor into `new()` and `from_parts()` (#699).
* Added validation for the output stack to make sure it was properly cleaned (#717).

## 0.3.0 (2024-05-14)

Expand Down
12 changes: 8 additions & 4 deletions miden-lib/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub use errors::{
TransactionEventParsingError, TransactionKernelError, TransactionTraceParsingError,
};

// CONSTANTS
// ================================================================================================

const ZERO_WORD: [Felt; 4] = [ZERO, ZERO, ZERO, ZERO];

// TRANSACTION KERNEL
// ================================================================================================

Expand Down Expand Up @@ -138,7 +143,7 @@ impl TransactionKernel {
///
/// # Errors
/// Returns an error if:
/// - Two last words on the stack are not equal to zero words.
/// - Words 3 and 4 on the stack are not ZERO.
/// - Overflow addresses are not empty.
pub fn parse_output_stack(
stack: &StackOutputs,
Expand All @@ -153,13 +158,12 @@ impl TransactionKernel {
.into();

// make sure that the stack has been properly cleaned
let zero_word = [ZERO, ZERO, ZERO, ZERO];
if stack.get_stack_word(8).expect("third word missing") != zero_word {
if stack.get_stack_word(8).expect("third word missing") != ZERO_WORD {
return Err(TransactionOutputError::OutputStackInvalid(
"Third word on output stack should consist only of ZEROs".into(),
));
}
if stack.get_stack_word(12).expect("fourth word missing") != zero_word {
if stack.get_stack_word(12).expect("fourth word missing") != ZERO_WORD {
return Err(TransactionOutputError::OutputStackInvalid(
"Fourth word on output stack should consist only of ZEROs".into(),
));
Expand Down

0 comments on commit 40ba7b8

Please sign in to comment.