Skip to content

Commit

Permalink
after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik1999 committed Jun 12, 2024
1 parent 97016d5 commit 423b13d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
5 changes: 2 additions & 3 deletions miden-lib/asm/kernels/transaction/api.masm
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ end
#! tag is the tag to be included in the note.
#! note_type is the note storage type
#! RECIPIENT is the recipient of the note.
#! note_idx is the index of the the note.
#! note_idx is the index of the crated note.
export.create_note
# authenticate that the procedure invocation originates from the account context
exec.authenticate_account_origin
Expand All @@ -543,8 +543,7 @@ export.create_note
# => [note_idx, 0, 0, 0, 0, 0]
end

#! Adds an ASSET to the specified note and returns the index of the note
#! to which the asset is added.
#! Adds the ASSET to the note specified by the index.
#!
#! Inputs: [note_idx, ASSET]
#! Outputs: [note_idx, 0, 0, 0, 0]
Expand Down
9 changes: 4 additions & 5 deletions miden-lib/asm/miden/kernels/tx/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ proc.add_fungible_asset_to_note
# => [note_ptr, note_idx]
end

#! Creates a new note and returns the index of the created note.
#! Creates a new note and returns the index of the note.
#!
#! Inputs: [tag, note_type, RECIPIENT]
#! Outputs: [note_idx]
#!
#! - tag is the tag to be included in the note.
#! - RECIPIENT defines spend conditions for the note.
#! - note_idx is the index of the the note.
#! - note_idx is the index of the crated note.
#!
#! Panics if:
#! - the note_type is not valid.
Expand Down Expand Up @@ -312,13 +312,12 @@ export.create_note
# => [note_idx]
end

#! Adds an ASSET to the specified note and returns the index of the note
#! to which the asset is added.
#! Adds the ASSET to the note specified by the index.
#!
#! Inputs: [note_idx, ASSET]
#! Outputs: [note_idx]
#!
#! note_idx is the index of the the note to which the asset is added.
#! - note_idx is the index of the the note to which the asset is added.
#! - ASSET can be a fungible or non-fungible asset.
#!
#! Panics if:
Expand Down
7 changes: 3 additions & 4 deletions miden-lib/asm/miden/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
#! tag is the tag to be included in the note.
#! note_type is the storage type of the note
#! RECIPIENT is the recipient of the note.
#! note_idx is the index of the the note to which the asset is added.
#! note_idx is the index of the crated note.
export.create_note
syscall.create_note
# => [note_idx, ZERO, 0]
Expand All @@ -71,13 +71,12 @@ export.create_note
# => [note_idx]
end

#! Adds an ASSET to the specified note and returns the index of the note
#! to which the asset is added.
#! Adds the ASSET to the note specified by the index.
#!
#! Inputs: [note_idx, ASSET]
#! Outputs: [note_idx]
#!
#! note_idx is the index of the the note to which the asset is added.
#! note_idx is the index of the note to which the asset is added.
#! ASSET can be a fungible or non-fungible asset.
export.add_asset_to_note
syscall.add_asset_to_note
Expand Down
4 changes: 0 additions & 4 deletions miden-lib/src/transaction/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub enum TransactionKernelError {
MalformedAssetOnAccountVaultUpdate(AssetError),
MalformedNoteInputs(NoteError),
MalformedNoteMetadata(NoteError),
MalformedNoteIndex(u64),
MalformedNoteScript(Vec<Felt>),
MalformedNoteType(NoteError),
MalformedRecipientData(Vec<Felt>),
Expand Down Expand Up @@ -68,9 +67,6 @@ impl fmt::Display for TransactionKernelError {
TransactionKernelError::MalformedNoteMetadata(err) => {
write!(f, "Note metadata created by the event handler is not well formed {err}")
},
TransactionKernelError::MalformedNoteIndex(err) => {
write!(f, "Note index is malformed {err}")
},
TransactionKernelError::MalformedNoteScript(data) => {
write!( f, "Note script data extracted from the advice map by the event handler is not well formed {data:?}")
},
Expand Down
18 changes: 7 additions & 11 deletions miden-tx/src/host/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use alloc::{collections::BTreeMap, rc::Rc, string::ToString, vec::Vec};

use miden_lib::transaction::{
memory::{ACCT_STORAGE_ROOT_PTR, CURRENT_CONSUMED_NOTE_PTR},
TransactionEvent, TransactionKernelError, TransactionTrace,
memory::CURRENT_CONSUMED_NOTE_PTR, TransactionEvent, TransactionKernelError, TransactionTrace,
};
use miden_objects::{
accounts::{AccountDelta, AccountId, AccountStorage, AccountStub},
Expand Down Expand Up @@ -118,6 +117,8 @@ impl<A: AdviceProvider, T: TransactionAuthenticator> TransactionHost<A, T> {

let note_idx: usize = stack[9].as_int() as usize;

assert_eq!(note_idx, self.output_notes.len(), "note index mismatch");

let note_builder = OutputNoteBuilder::new(stack, &self.adv_provider)?;

self.output_notes.insert(note_idx, note_builder);
Expand All @@ -135,21 +136,16 @@ impl<A: AdviceProvider, T: TransactionAuthenticator> TransactionHost<A, T> {
let stack = process.get_stack_state();
//# => [ASSET, note_ptr, num_of_assets, note_idx]

// this is a safe conversion because the note index (in theory) is always a u64
// in theory, the user can provide any note index. However, we already check in
// the kernel that the note index < MAX_OUTPUT_NOTES_PER_TX
let note_idx_u64 = stack[6].as_int();
if note_idx_u64 >= usize::MAX as u64 {
return Err(TransactionKernelError::MalformedNoteIndex(note_idx_u64));
}
let note_idx = note_idx_u64 as usize;
let note_idx = stack[6].as_int();
assert!(note_idx < self.output_notes.len() as u64);
let node_idx = note_idx as usize;

let asset = Asset::try_from(process.get_stack_word(0))
.map_err(TransactionKernelError::MalformedAsset)?;

let note_builder = self
.output_notes
.get_mut(&note_idx)
.get_mut(&node_idx)
.ok_or_else(|| TransactionKernelError::MissingNote(format!("{:?}", &note_idx)))?;

note_builder.add_asset(asset)?;
Expand Down

0 comments on commit 423b13d

Please sign in to comment.