Skip to content
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

Revert "Derive Ord and PartialOrd for NoteTag" #654

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion miden-lib/asm/miden/kernels/tx/tx.masm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export.create_note
assertz.err=ERR_NOTE_INVALID_TAG_HIGH_BIT_SET
# => [tag_low, note_type, ASSET, tag, note_type, RECIPIENT]

u32shr.30 assert_eq.err=ERR_NOTE_INVALID_TAG_PREFIX_FOR_TYPE
u32shr.30 u32and assertz.err=ERR_NOTE_INVALID_TAG_PREFIX_FOR_TYPE
# => [ASSET, tag, note_type, RECIPIENT]

# get the index for the next note to be created and increment counter
Expand Down
21 changes: 9 additions & 12 deletions miden-lib/src/notes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use miden_objects::{
accounts::AccountId,
assets::Asset,
crypto::rand::FeltRng,
notes::{Note, NoteAssets, NoteInputs, NoteMetadata, NoteRecipient, NoteTag, NoteType},
notes::{
Note, NoteAssets, NoteExecutionMode, NoteInputs, NoteMetadata, NoteRecipient, NoteTag,
NoteType,
},
NoteError, Word, ZERO,
};

Expand Down Expand Up @@ -36,7 +39,7 @@ pub fn create_p2id_note<R: FeltRng>(
let note_script = build_note_script(bytes)?;

let inputs = NoteInputs::new(vec![target.into()])?;
let tag = NoteTag::from_account_id(target, NoteType::Public)?;
let tag = NoteTag::from_account_id(target, NoteExecutionMode::Local)?;
let serial_num = rng.draw_word();
let aux = ZERO;

Expand Down Expand Up @@ -70,7 +73,7 @@ pub fn create_p2idr_note<R: FeltRng>(
let note_script = build_note_script(bytes)?;

let inputs = NoteInputs::new(vec![target.into(), recall_height.into()])?;
let tag = NoteTag::from_account_id(target, NoteType::Public)?;
let tag = NoteTag::from_account_id(target, NoteExecutionMode::Local)?;
let serial_num = rng.draw_word();
let aux = ZERO;

Expand All @@ -95,19 +98,13 @@ pub fn create_swap_note<R: FeltRng>(
note_type: NoteType,
mut rng: R,
) -> Result<(Note, Word), NoteError> {
assert_eq!(
note_type,
NoteType::OffChain,
"OffChain note type is currently hardcoded in the SWAP script"
);

let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/assets/note_scripts/SWAP.masb"));
let note_script = build_note_script(bytes)?;

let payback_serial_num = rng.draw_word();
let payback_recipient = utils::build_p2id_recipient(sender, payback_serial_num)?;
let asset_word: Word = requested_asset.into();
let payback_tag = NoteTag::from_account_id(sender, note_type)?;
let payback_tag = NoteTag::from_account_id(sender, NoteExecutionMode::Local)?;

let inputs = NoteInputs::new(vec![
payback_recipient[0],
Expand All @@ -121,8 +118,8 @@ pub fn create_swap_note<R: FeltRng>(
payback_tag.inner().into(),
])?;

// TODO: build a tag for the SWAP use case (#640)
let tag = NoteTag::from(note_type);
// TODO: build the tag for the SWAP use case
let tag = 0.into();
let serial_num = rng.draw_word();
let aux = ZERO;

Expand Down
30 changes: 11 additions & 19 deletions miden-lib/src/tests/test_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::vec::Vec;

use miden_objects::{
accounts::account_id::testing::ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN,
notes::{Note, NoteAssets, NoteInputs, NoteMetadata, NoteRecipient, NoteTag, NoteType},
notes::{Note, NoteAssets, NoteInputs, NoteMetadata, NoteRecipient, NoteType},
transaction::{OutputNote, OutputNotes},
Word, ONE, ZERO,
};
Expand Down Expand Up @@ -30,7 +30,7 @@ fn test_create_note() {
let account_id = tx_inputs.account().id();

let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)];
let tag: NoteTag = NoteType::Public.into();
let tag = Felt::new(4);
let asset = [Felt::new(10), ZERO, ZERO, Felt::new(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN)];

let code = format!(
Expand Down Expand Up @@ -72,7 +72,7 @@ fn test_create_note() {

assert_eq!(
read_root_mem_value(&process, CREATED_NOTE_SECTION_OFFSET + CREATED_NOTE_METADATA_OFFSET),
[tag.into(), Felt::from(account_id), NoteType::Public.into(), ZERO],
[tag, Felt::from(account_id), NoteType::Public.into(), ZERO],
"metadata must be stored at the correct memory location",
);

Expand Down Expand Up @@ -102,7 +102,7 @@ fn test_create_note_with_invalid_tag() {
mock_inputs(MockAccountType::StandardExisting, AssetPreservationStatus::Preserved);

let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)];
let tag = 0;
let tag = Felt::new((NoteType::Public as u64) << 62);
let asset = [Felt::new(10), ZERO, ZERO, Felt::new(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN)];

let code = format!(
Expand Down Expand Up @@ -136,7 +136,7 @@ fn test_create_note_with_invalid_tag() {
#[test]
fn test_create_note_too_many_notes() {
let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)];
let tag: NoteTag = NoteType::Public.into();
let tag = Felt::new(4);
let asset = [Felt::new(10), ZERO, ZERO, Felt::new(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN)];

let code = format!(
Expand Down Expand Up @@ -183,28 +183,20 @@ fn test_get_output_notes_hash() {

// create output note 1
let output_serial_no_1 = [Felt::new(8); 4];
let output_tag_1 = 8888.into();
let assets = NoteAssets::new(vec![input_asset_1]).unwrap();
let metadata = NoteMetadata::new(
tx_inputs.account().id(),
NoteType::Public,
NoteType::Public.into(),
ZERO,
)
.unwrap();
let metadata =
NoteMetadata::new(tx_inputs.account().id(), NoteType::Public, output_tag_1, ZERO).unwrap();
let inputs = NoteInputs::new(vec![]).unwrap();
let recipient = NoteRecipient::new(output_serial_no_1, input_note_1.script().clone(), inputs);
let output_note_1 = Note::new(assets, metadata, recipient);

// create output note 2
let output_serial_no_2 = [Felt::new(11); 4];
let output_tag_2 = 1111.into();
let assets = NoteAssets::new(vec![input_asset_2]).unwrap();
let metadata = NoteMetadata::new(
tx_inputs.account().id(),
NoteType::Public,
NoteType::Public.into(),
ZERO,
)
.unwrap();
let metadata =
NoteMetadata::new(tx_inputs.account().id(), NoteType::Public, output_tag_2, ZERO).unwrap();
let inputs = NoteInputs::new(vec![]).unwrap();
let recipient = NoteRecipient::new(output_serial_no_2, input_note_2.script().clone(), inputs);
let output_note_2 = Note::new(assets, metadata, recipient);
Expand Down
6 changes: 2 additions & 4 deletions miden-tx/src/compiler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,15 @@ fn mock_consumed_notes(
const SERIAL_NUM_1: Word = [Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)];
let vault =
NoteAssets::new(vec![fungible_asset_1, fungible_asset_2, fungible_asset_3]).unwrap();
let metadata =
NoteMetadata::new(sender, NoteType::Public, NoteType::Public.into(), ZERO).unwrap();
let metadata = NoteMetadata::new(sender, NoteType::Public, 0.into(), ZERO).unwrap();
let inputs = NoteInputs::new(vec![Felt::new(1)]).unwrap();
let recipient = NoteRecipient::new(SERIAL_NUM_1, note_script.clone(), inputs);
let note_1 = Note::new(vault, metadata, recipient);

const SERIAL_NUM_2: Word = [Felt::new(5), Felt::new(6), Felt::new(7), Felt::new(8)];
let vault =
NoteAssets::new(vec![fungible_asset_1, fungible_asset_2, fungible_asset_3]).unwrap();
let metadata =
NoteMetadata::new(sender, NoteType::Public, NoteType::Public.into(), ZERO).unwrap();
let metadata = NoteMetadata::new(sender, NoteType::Public, 0.into(), ZERO).unwrap();
let inputs = NoteInputs::new(vec![Felt::new(2)]).unwrap();
let recipient = NoteRecipient::new(SERIAL_NUM_2, note_script, inputs);
let note_2 = Note::new(vault, metadata, recipient);
Expand Down
11 changes: 4 additions & 7 deletions miden-tx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use miden_objects::{
assembly::{Assembler, ModuleAst, ProgramAst},
assets::{Asset, FungibleAsset},
block::BlockHeader,
notes::{NoteId, NoteTag, NoteType},
notes::{NoteId, NoteType},
transaction::{
ChainMmr, InputNote, InputNotes, ProvenTransaction, TransactionArgs, TransactionWitness,
},
Expand Down Expand Up @@ -203,23 +203,23 @@ fn executed_transaction_account_delta() {
# partially deplete fungible asset balance
push.0.1.2.3 # recipient
push.{OFFCHAIN} # note_type
push.{tag_1} # tag
push.999 # tag
push.{REMOVED_ASSET_1} # asset
call.wallet::send_asset dropw dropw drop drop
# => []
# totally deplete fungible asset balance
push.0.1.2.3 # recipient
push.{OFFCHAIN} # note_type
push.{tag_2} # tag
push.998 # tag
push.{REMOVED_ASSET_2} # asset
call.wallet::send_asset dropw dropw drop drop
# => []
# send non-fungible asset
push.0.1.2.3 # recipient
push.{OFFCHAIN} # note_type
push.{tag_3} # tag
push.997 # tag
push.{REMOVED_ASSET_3} # asset
call.wallet::send_asset dropw dropw drop drop
# => []
Expand All @@ -242,9 +242,6 @@ fn executed_transaction_account_delta() {
REMOVED_ASSET_1 = prepare_word(&Word::from(removed_asset_1)),
REMOVED_ASSET_2 = prepare_word(&Word::from(removed_asset_2)),
REMOVED_ASSET_3 = prepare_word(&Word::from(removed_asset_3)),
tag_1 = NoteTag::from(NoteType::OffChain),
tag_2 = NoteTag::from(NoteType::OffChain),
tag_3 = NoteTag::from(NoteType::OffChain),
OFFCHAIN = NoteType::OffChain as u8,
);
let tx_script_code = ProgramAst::parse(&tx_script).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions miden-tx/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ pub fn get_note_with_fungible_asset_and_script(
let sender_id = AccountId::try_from(ACCOUNT_ID_SENDER).unwrap();

let vault = NoteAssets::new(vec![fungible_asset.into()]).unwrap();
let metadata =
NoteMetadata::new(sender_id, NoteType::Public, NoteType::Public.into(), ZERO).unwrap();
let metadata = NoteMetadata::new(sender_id, NoteType::Public, 1.into(), ZERO).unwrap();
let inputs = NoteInputs::new(vec![]).unwrap();
let recipient = NoteRecipient::new(SERIAL_NUM, note_script, inputs);

Expand Down
2 changes: 1 addition & 1 deletion miden-tx/tests/integration/scripts/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn prove_faucet_contract_mint_fungible_asset_succeeds() {
let note_ids = data_store.notes.iter().map(|note| note.id()).collect::<Vec<_>>();

let recipient = [Felt::new(0), Felt::new(1), Felt::new(2), Felt::new(3)];
let tag = NoteType::OffChain.into();
let tag = 4.into();
let amount = Felt::new(100);

let tx_script_code = ProgramAst::parse(
Expand Down
6 changes: 3 additions & 3 deletions miden-tx/tests/integration/scripts/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use miden_objects::{
assembly::ProgramAst,
assets::{Asset, AssetVault, FungibleAsset, NonFungibleAsset, NonFungibleAssetDetails},
crypto::rand::RpoRandomCoin,
notes::{NoteAssets, NoteEnvelope, NoteId, NoteMetadata, NoteTag, NoteType},
notes::{NoteAssets, NoteEnvelope, NoteExecutionMode, NoteId, NoteMetadata, NoteTag, NoteType},
transaction::TransactionArgs,
Felt, ZERO,
};
Expand Down Expand Up @@ -52,7 +52,7 @@ fn prove_swap_script() {
sender_account_id,
fungible_asset,
non_fungible_asset,
NoteType::OffChain,
NoteType::Public,
RpoRandomCoin::new([Felt::new(1), Felt::new(2), Felt::new(3), Felt::new(4)]),
)
.unwrap();
Expand Down Expand Up @@ -98,7 +98,7 @@ fn prove_swap_script() {

// Check if the created `Note` is what we expect
let recipient = build_p2id_recipient(sender_account_id, repay_serial_num).unwrap();
let tag = NoteTag::from_account_id(sender_account_id, NoteType::OffChain).unwrap();
let tag = NoteTag::from_account_id(sender_account_id, NoteExecutionMode::Local).unwrap();
let note_metadata =
NoteMetadata::new(target_account_id, NoteType::OffChain, tag, ZERO).unwrap();
let assets = NoteAssets::new(vec![non_fungible_asset]).unwrap();
Expand Down
8 changes: 5 additions & 3 deletions miden-tx/tests/integration/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use miden_objects::{
assembly::ProgramAst,
assets::{Asset, AssetVault, FungibleAsset},
crypto::dsa::rpo_falcon512::SecretKey,
notes::{NoteTag, NoteType},
notes::NoteType,
transaction::TransactionArgs,
Felt, Word, ONE, ZERO,
};
Expand Down Expand Up @@ -124,12 +124,14 @@ fn prove_send_asset_via_wallet() {
// --------------------------------------------------------------------------------------------
let data_store = MockDataStore::with_existing(Some(sender_account.clone()), Some(vec![]));

let mut executor = TransactionExecutor::new(data_store.clone()).with_debug_mode(true);
let mut executor = TransactionExecutor::new(data_store.clone());
executor.load_account(sender_account.id()).unwrap();

let block_ref = data_store.block_header.block_num();
let note_ids = data_store.notes.iter().map(|note| note.id()).collect::<Vec<_>>();

let recipient = [ZERO, ONE, Felt::new(2), Felt::new(3)];
let tag = Felt::new(4);

let tx_script_code = ProgramAst::parse(
format!(
Expand All @@ -149,7 +151,7 @@ fn prove_send_asset_via_wallet() {
",
recipient = prepare_word(&recipient),
note_type = NoteType::OffChain as u8,
tag = NoteTag::from(NoteType::OffChain),
tag = tag,
asset = prepare_word(&fungible_asset_1.into())
)
.as_str(),
Expand Down
6 changes: 3 additions & 3 deletions mock/src/builders/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl NoteBuilder {
assets: vec![],
note_type: NoteType::Public,
serial_num,
tag: NoteType::Public.into(),
tag: 0.into(),
code: DEFAULT_NOTE_CODE.to_string(),
proof: None,
aux: ZERO,
Expand All @@ -69,8 +69,8 @@ impl NoteBuilder {
self
}

pub fn tag(mut self, tag: NoteTag) -> Self {
self.tag = tag;
pub fn tag(mut self, tag: u32) -> Self {
self.tag = tag.into();
self
}

Expand Down
4 changes: 2 additions & 2 deletions mock/src/mock/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ pub fn mock_account_storage() -> AccountStorage {
// account's procedures.
const MASTS: [&str; 9] = [
"0xe06a83054c72efc7e32698c4fc6037620cde834c9841afb038a5d39889e502b6",
"0xb39350cf554e78d4819764a1755f219abf4a6ab8dae5aa3be809c9d65f03c955",
"0xd0260c15a64e796833eb2987d4072ac2ea824b3ce4a54a1e693bada6e82f71dd",
"0xd765111e22479256e87a57eaf3a27479d19cc876c9a715ee6c262e0a0d47a2ac",
"0x17b326d5403115afccc0727efa72bd929bfdc7bbf284c7c28a7aadade5d4cc9d",
"0x6682a0e0f4e49820e5c547f1b60a82cb326a56c972999e36bf6d45459393ac87",
"0x73c14f65d2bab6f52eafc4397e104b3ab22a470f6b5cbc86d4aa4d3978c8b7d4",
"0x5bdf8858cc463910f9cfc9864f0ef42501baf8bd38d9e8848d3decde2e440bed",
"0xef07641ea1aa8fe85d8f854d29bf729b92251e1433244892138fd9ca898a5a22",
"0xff06b90f849c4b262cbfbea67042c4ea017ea0e9c558848a951d44b23370bec5",
"0x8ef0092134469a1330e3c468f57c7f085ce611645d09cc7516c786fefc71d794",
];
Expand Down
Loading
Loading