miden_objects/note/note_tag.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
use core::{fmt, num::TryFromIntError};
use miden_crypto::Felt;
use super::{
AccountId, ByteReader, ByteWriter, Deserializable, DeserializationError, NoteError, NoteType,
Serializable,
};
// CONSTANTS
// ================================================================================================
const NETWORK_EXECUTION: u8 = 0;
const LOCAL_EXECUTION: u8 = 1;
// The 2 most significant bits are set to `0b11`.
const LOCAL_EXECUTION_WITH_ALL_NOTE_TYPES_ALLOWED: u32 = 0xc000_0000;
// The 2 most significant bits are set to `0b10`.
const PUBLIC_USECASE: u32 = 0x8000_0000;
/// [super::Note]'s execution mode hints.
///
/// The execution hints are _not_ enforced, therefore function only as hints. For example, if a
/// note's tag is created with the [NoteExecutionMode::Network], further validation is necessary to
/// check the account_id is known, that the account's state is on-chain, and the account is
/// controlled by the network.
///
/// The goal of the hint is to allow for a network node to quickly filter notes that are not
/// intended for network execution, and skip the validation steps mentioned above.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum NoteExecutionMode {
Network = NETWORK_EXECUTION,
Local = LOCAL_EXECUTION,
}
// NOTE TAG
// ================================================================================================
/// [NoteTag]`s are best effort filters for notes registered with the network.
///
/// Tags are light-weight values used to speed up queries. The 2 most significant bits of the tags
/// have the following interpretation:
///
/// | Prefix | Execution mode | Target | Allowed [NoteType] |
/// | ------ | :------------: | :------: | :----------------: |
/// | `0b00` | Network | Specific | [NoteType::Public] |
/// | `0b01` | Network | Use case | [NoteType::Public] |
/// | `0b10` | Local | Any | [NoteType::Public] |
/// | `0b11` | Local | Any | Any |
///
/// Where:
///
/// - [`NoteExecutionMode`] is set to [`NoteExecutionMode::Network`] to hint a [`Note`](super::Note)
/// should be consumed by the network. These notes will be further validated and if possible
/// consumed by it.
/// - Target describes how to further interpret the bits in the tag. For tags with a specific
/// target, the rest of the tag is interpreted as a partial [`AccountId`]. For use case values,
/// the meaning of the rest of the tag is not specified by the protocol and can be used by
/// applications built on top of the rollup.
///
/// The note type is the only value enforced by the protocol. The rationale is that any note
/// intended to be consumed by the network must be public to have all the details available. The
/// public note for local execution is intended to allow users to search for notes that can be
/// consumed right away, without requiring an off-band communication channel.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct NoteTag(u32);
impl NoteTag {
// CONSTANTS
// --------------------------------------------------------------------------------------------
/// The exponent of the maximum allowed use case id. In other words, 2^exponent is the maximum
/// allowed use case id.
pub(crate) const MAX_USE_CASE_ID_EXPONENT: u8 = 14;
// CONSTRUCTORS
// --------------------------------------------------------------------------------------------
/// Returns a new [NoteTag] instantiated from the specified account ID and execution mode.
///
/// The tag is constructed as follows:
///
/// - For local execution, the two most significant bits are set to `0b11`, which allows for any
/// note type to be used. The following 14 bits are set to the most significant bits of the
/// account ID, and the remaining 16 bits are set to 0.
/// - For network execution, the most significant bits are set to `0b00` and the remaining bits
/// are set to the 30 most significant bits of the account ID.
///
/// # Errors
///
/// This will return an error if the account_id is not for a public account and the execution
/// hint is set to [NoteExecutionMode::Network].
pub fn from_account_id(
account_id: AccountId,
execution: NoteExecutionMode,
) -> Result<Self, NoteError> {
match execution {
NoteExecutionMode::Local => {
let prefix_id: u64 = account_id.prefix().into();
// Shift the high bits of the account ID such that they are layed out as:
// [34 zero bits | remaining high bits (30 bits)].
let high_bits = prefix_id >> 34;
// This is equivalent to the following layout, interpreted as a u32:
// [2 zero bits | remaining high bits (30 bits)].
let high_bits = high_bits as u32;
// Select the upper half of the u32 which then contains the 14 most significant bits
// of the account ID, i.e.:
// [2 zero bits | remaining high bits (14 bits) | 16 zero bits].
let high_bits = high_bits & 0xffff0000;
// Set the local execution tag in the two most significant bits.
Ok(Self(high_bits | LOCAL_EXECUTION_WITH_ALL_NOTE_TYPES_ALLOWED))
},
NoteExecutionMode::Network => {
if !account_id.is_public() {
Err(NoteError::NetworkExecutionRequiresOnChainAccount)
} else {
let prefix_id: u64 = account_id.prefix().into();
// Shift the high bits of the account ID such that they are layed out as:
// [34 zero bits | remaining high bits (30 bits)].
let high_bits = prefix_id >> 34;
// This is equivalent to the following layout, interpreted as a u32:
// [2 zero bits | remaining high bits (30 bits)].
// The two most significant zero bits match the tag we need for network
// execution.
Ok(Self(high_bits as u32))
}
},
}
}
/// Returns a new [NoteTag] instantiated for a custom use case which requires a public note.
///
/// The public use_case tag requires a [NoteType::Public] note.
///
/// The two high bits are set to the `b10` or `b01` depending on the execution hint, the next 14
/// bits are set to the `use_case_id`, and the low 16 bits are set to `payload`.
///
/// # Errors
///
/// - If `use_case_id` is larger than or equal to $2^{14}$.
pub fn for_public_use_case(
use_case_id: u16,
payload: u16,
execution: NoteExecutionMode,
) -> Result<Self, NoteError> {
if (use_case_id >> 14) != 0 {
return Err(NoteError::NoteTagUseCaseTooLarge(use_case_id));
}
let execution_bits = match execution {
NoteExecutionMode::Local => PUBLIC_USECASE, // high bits set to `0b10`
NoteExecutionMode::Network => 0x40000000, // high bits set to `0b01`
};
let use_case_bits = (use_case_id as u32) << 16;
let payload_bits = payload as u32;
Ok(Self(execution_bits | use_case_bits | payload_bits))
}
/// Returns a new [NoteTag] instantiated for a custom local use case.
///
/// The local use_case tag is the only tag type that allows for [NoteType::Private] notes.
///
/// The two high bits are set to the `b11`, the next 14 bits are set to the `use_case_id`, and
/// the low 16 bits are set to `payload`.
///
/// # Errors
///
/// - If `use_case_id` is larger than or equal to 2^14.
pub fn for_local_use_case(use_case_id: u16, payload: u16) -> Result<Self, NoteError> {
if (use_case_id >> NoteTag::MAX_USE_CASE_ID_EXPONENT) != 0 {
return Err(NoteError::NoteTagUseCaseTooLarge(use_case_id));
}
let execution_bits = LOCAL_EXECUTION_WITH_ALL_NOTE_TYPES_ALLOWED;
let use_case_bits = (use_case_id as u32) << 16;
let payload_bits = payload as u32;
Ok(Self(execution_bits | use_case_bits | payload_bits))
}
// PUBLIC ACCESSORS
// --------------------------------------------------------------------------------------------
/// Returns true if the note is intended for execution by a specific account.
///
/// A note is intended for execution by a single account if the first two bits are zeros
pub fn is_single_target(&self) -> bool {
let first_2_bit = self.0 >> 30;
first_2_bit == 0b00
}
/// Returns note execution mode defined by this tag.
///
/// If the most significant bit of the tag is 0 the note is intended for local execution;
/// otherwise, the note is intended for network execution.
pub fn execution_mode(&self) -> NoteExecutionMode {
let first_bit = self.0 >> 31;
if first_bit == (LOCAL_EXECUTION as u32) {
NoteExecutionMode::Local
} else {
NoteExecutionMode::Network
}
}
/// Returns the inner u32 value of this tag.
pub fn inner(&self) -> u32 {
self.0
}
// UTILITY METHODS
// --------------------------------------------------------------------------------------------
/// Returns an error if this tag is not consistent with the specified note type, and self
/// otherwise.
pub fn validate(&self, note_type: NoteType) -> Result<Self, NoteError> {
if self.execution_mode() == NoteExecutionMode::Network && note_type != NoteType::Public {
return Err(NoteError::NetworkExecutionRequiresPublicNote(note_type));
}
let is_public_use_case = (self.0 & 0xc0000000) == PUBLIC_USECASE;
if is_public_use_case && note_type != NoteType::Public {
Err(NoteError::PublicUseCaseRequiresPublicNote(note_type))
} else {
Ok(*self)
}
}
}
impl fmt::Display for NoteTag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
// CONVERSIONS INTO NOTE TAG
// ================================================================================================
impl From<u32> for NoteTag {
fn from(value: u32) -> Self {
Self(value)
}
}
impl TryFrom<u64> for NoteTag {
type Error = TryFromIntError;
fn try_from(value: u64) -> Result<Self, Self::Error> {
Ok(Self(value.try_into()?))
}
}
impl TryFrom<Felt> for NoteTag {
type Error = TryFromIntError;
fn try_from(value: Felt) -> Result<Self, Self::Error> {
Ok(Self(value.as_int().try_into()?))
}
}
// CONVERSIONS FROM NOTE TAG
// ================================================================================================
impl From<NoteTag> for u32 {
fn from(value: NoteTag) -> Self {
value.0
}
}
impl From<NoteTag> for u64 {
fn from(value: NoteTag) -> Self {
value.0 as u64
}
}
impl From<NoteTag> for Felt {
fn from(value: NoteTag) -> Self {
Felt::from(value.0)
}
}
// SERIALIZATION
// ================================================================================================
impl Serializable for NoteTag {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.0.write_into(target);
}
}
impl Deserializable for NoteTag {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let tag = u32::read_from(source)?;
Ok(Self(tag))
}
}
// TESTS
// ================================================================================================
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use super::{NoteExecutionMode, NoteTag};
use crate::{
account::AccountId,
note::NoteType,
testing::account_id::{
ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN,
ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_1, ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_2,
ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_3, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_OFF_CHAIN,
ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1,
ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN_2,
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN,
ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2, ACCOUNT_ID_SENDER,
},
NoteError,
};
#[test]
fn test_from_account_id() {
let off_chain_accounts = [
AccountId::try_from(ACCOUNT_ID_SENDER).unwrap(),
AccountId::try_from(ACCOUNT_ID_OFF_CHAIN_SENDER).unwrap(),
AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN).unwrap(),
AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_OFF_CHAIN).unwrap(),
AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_OFF_CHAIN).unwrap(),
];
let on_chain_accounts = [
AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN).unwrap(),
AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN_2).unwrap(),
AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN).unwrap(),
AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN_2).unwrap(),
AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(),
AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_1).unwrap(),
AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_2).unwrap(),
AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN_3).unwrap(),
AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(),
AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN_1).unwrap(),
];
for off_chain in off_chain_accounts {
assert_matches!(
NoteTag::from_account_id(off_chain, NoteExecutionMode::Network).unwrap_err(),
NoteError::NetworkExecutionRequiresOnChainAccount,
"Tag generation must fail if network execution and off-chain account ID are mixed"
)
}
for on_chain in on_chain_accounts {
let tag = NoteTag::from_account_id(on_chain, NoteExecutionMode::Network)
.expect("tag generation must work with network execution and on-chain account ID");
assert!(tag.is_single_target());
assert_eq!(tag.execution_mode(), NoteExecutionMode::Network);
tag.validate(NoteType::Public)
.expect("network execution should require notes to be public");
assert_matches!(
tag.validate(NoteType::Private),
Err(NoteError::NetworkExecutionRequiresPublicNote(NoteType::Private))
);
assert_matches!(
tag.validate(NoteType::Encrypted),
Err(NoteError::NetworkExecutionRequiresPublicNote(NoteType::Encrypted))
);
}
for off_chain in off_chain_accounts {
let tag = NoteTag::from_account_id(off_chain, NoteExecutionMode::Local)
.expect("tag generation must work with local execution and off-chain account ID");
assert!(!tag.is_single_target());
assert_eq!(tag.execution_mode(), NoteExecutionMode::Local);
tag.validate(NoteType::Public)
.expect("local execution should support public notes");
tag.validate(NoteType::Private)
.expect("local execution should support private notes");
tag.validate(NoteType::Encrypted)
.expect("local execution should support encrypted notes");
}
for on_chain in on_chain_accounts {
let tag = NoteTag::from_account_id(on_chain, NoteExecutionMode::Local)
.expect("Tag generation must work with local execution and on-chain account ID");
assert!(!tag.is_single_target());
assert_eq!(tag.execution_mode(), NoteExecutionMode::Local);
tag.validate(NoteType::Public)
.expect("local execution should support public notes");
tag.validate(NoteType::Private)
.expect("local execution should support private notes");
tag.validate(NoteType::Encrypted)
.expect("local execution should support encrypted notes");
}
}
#[test]
fn test_from_account_id_values() {
// Off-Chain Account ID with the following bit pattern in the first and second byte:
// 0b11001100_01010101
// ^^^^^^^^ ^^^^^^ <- these are the 14 bits used in the tag.
const OFF_CHAIN_INT: u128 = ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN
| 0x0055_0000_0000_0000_0000_0000_0000_0000;
let off_chain = AccountId::try_from(OFF_CHAIN_INT).unwrap();
// Expected off-chain tag with LOCAL_EXECUTION_WITH_ALL_NOTE_TYPES_ALLOWED.
let expected_off_chain_local_tag = NoteTag(0b11110011_00010101_00000000_00000000);
// On-Chain Account ID with the following bit pattern in the first and second byte:
// 0b10101010_01010101_11001100_01110111
// ^^^^^^^^ ^^^^^^^^ ^^^^^^^^ ^^^^^^ <- 30 bits of the network tag.
// ^^^^^^^^ ^^^^^^ <- 14 bits of the local tag.
let on_chain_int = ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN
| 0x0055_cc77_0000_0000_0000_0000_0000_0000;
let on_chain = AccountId::try_from(on_chain_int).unwrap();
// Expected on-chain tag with LOCAL_EXECUTION_WITH_ALL_NOTE_TYPES_ALLOWED.
let expected_on_chain_local_tag = NoteTag(0b11101010_10010101_00000000_00000000);
// Expected on-chain tag with leading 00 tag bits for network execution.
let expected_on_chain_network_tag = NoteTag(0b00101010_10010101_01110011_00011101);
assert_eq!(
NoteTag::from_account_id(on_chain, NoteExecutionMode::Network).unwrap(),
expected_on_chain_network_tag,
);
assert_matches!(
NoteTag::from_account_id(off_chain, NoteExecutionMode::Network),
Err(NoteError::NetworkExecutionRequiresOnChainAccount)
);
assert_eq!(
NoteTag::from_account_id(off_chain, NoteExecutionMode::Local).unwrap(),
expected_off_chain_local_tag,
);
// We expect the 16th most significant bit to be cut off.
assert_eq!(
NoteTag::from_account_id(on_chain, NoteExecutionMode::Local).unwrap(),
expected_on_chain_local_tag,
);
}
#[test]
fn test_for_public_use_case() {
// NETWORK
// ----------------------------------------------------------------------------------------
let tag = NoteTag::for_public_use_case(0b0, 0b0, NoteExecutionMode::Network).unwrap();
assert_eq!(tag, NoteTag(0b01000000_00000000_00000000_00000000));
tag.validate(NoteType::Public).unwrap();
assert_matches!(
tag.validate(NoteType::Private).unwrap_err(),
NoteError::NetworkExecutionRequiresPublicNote(NoteType::Private)
);
assert_matches!(
tag.validate(NoteType::Encrypted).unwrap_err(),
NoteError::NetworkExecutionRequiresPublicNote(NoteType::Encrypted)
);
let tag = NoteTag::for_public_use_case(0b1, 0b0, NoteExecutionMode::Network).unwrap();
assert_eq!(tag, NoteTag(0b01000000_00000001_00000000_00000000));
let tag = NoteTag::for_public_use_case(0b0, 0b1, NoteExecutionMode::Network).unwrap();
assert_eq!(tag, NoteTag(0b01000000_00000000_00000000_00000001));
let tag = NoteTag::for_public_use_case(1 << 13, 0b0, NoteExecutionMode::Network).unwrap();
assert_eq!(tag, NoteTag(0b01100000_00000000_00000000_00000000));
// LOCAL
// ----------------------------------------------------------------------------------------
let tag = NoteTag::for_public_use_case(0b0, 0b0, NoteExecutionMode::Local).unwrap();
assert_eq!(tag, NoteTag(0b10000000_00000000_00000000_00000000));
tag.validate(NoteType::Public).unwrap();
assert_matches!(
tag.validate(NoteType::Private).unwrap_err(),
NoteError::PublicUseCaseRequiresPublicNote(NoteType::Private)
);
assert_matches!(
tag.validate(NoteType::Encrypted).unwrap_err(),
NoteError::PublicUseCaseRequiresPublicNote(NoteType::Encrypted)
);
let tag = NoteTag::for_public_use_case(0b0, 0b1, NoteExecutionMode::Local).unwrap();
assert_eq!(tag, NoteTag(0b10000000_00000000_00000000_00000001));
let tag = NoteTag::for_public_use_case(0b1, 0b0, NoteExecutionMode::Local).unwrap();
assert_eq!(tag, NoteTag(0b10000000_00000001_00000000_00000000));
let tag = NoteTag::for_public_use_case(1 << 13, 0b0, NoteExecutionMode::Local).unwrap();
assert_eq!(tag, NoteTag(0b10100000_00000000_00000000_00000000));
assert_matches!(
NoteTag::for_public_use_case(1 << 15, 0b0, NoteExecutionMode::Local).unwrap_err(),
NoteError::NoteTagUseCaseTooLarge(use_case) if use_case == 1 << 15
);
assert_matches!(
NoteTag::for_public_use_case(1 << 14, 0b0, NoteExecutionMode::Local).unwrap_err(),
NoteError::NoteTagUseCaseTooLarge(use_case) if use_case == 1 << 14
);
}
#[test]
fn test_for_private_use_case() {
let tag = NoteTag::for_local_use_case(0b0, 0b0).unwrap();
assert_eq!(tag, NoteTag(0b11000000_00000000_00000000_00000000));
tag.validate(NoteType::Public)
.expect("local execution should support public notes");
tag.validate(NoteType::Private)
.expect("local execution should support private notes");
tag.validate(NoteType::Encrypted)
.expect("local execution should support encrypted notes");
let tag = NoteTag::for_local_use_case(0b0, 0b1).unwrap();
assert_eq!(tag, NoteTag(0b11000000_00000000_00000000_00000001));
let tag = NoteTag::for_local_use_case(0b1, 0b0).unwrap();
assert_eq!(tag, NoteTag(0b11000000_00000001_00000000_00000000));
let tag = NoteTag::for_local_use_case(1 << 13, 0b0).unwrap();
assert_eq!(tag, NoteTag(0b11100000_00000000_00000000_00000000));
assert_matches!(
NoteTag::for_local_use_case(1 << 15, 0b0).unwrap_err(),
NoteError::NoteTagUseCaseTooLarge(use_case) if use_case == 1 << 15
);
assert_matches!(
NoteTag::for_local_use_case(1 << 14, 0b0).unwrap_err(),
NoteError::NoteTagUseCaseTooLarge(use_case) if use_case == 1 << 14
);
}
}