Skip to content

Commit

Permalink
Merge pull request #314 from 0xPolygonMiden/plafer-accountid-new_unch…
Browse files Browse the repository at this point in the history
…ecked

Make `AccountId::new_unchecked()` safe
  • Loading branch information
plafer authored Nov 20, 2023
2 parents 6bf6e96 + 1e6676d commit bd9a7ac
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions miden-tx/src/host/event/vault_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ impl AccountVaultDeltaHandler {
if amount > 0 {
added_assets.push(Asset::Fungible(
FungibleAsset::new(
unsafe { AccountId::new_unchecked(faucet_id.into()) },
AccountId::new_unchecked(faucet_id.into()),
amount.unsigned_abs() as u64,
)
.expect("fungible asset is well formed"),
));
} else {
removed_assets.push(Asset::Fungible(
FungibleAsset::new(
unsafe { AccountId::new_unchecked(faucet_id.into()) },
AccountId::new_unchecked(faucet_id.into()),
amount.unsigned_abs() as u64,
)
.expect("fungible asset is well formed"),
Expand Down
3 changes: 1 addition & 2 deletions objects/src/accounts/account_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ impl AccountId {

/// Creates a new [AccountId] without checking its validity.
///
/// # Safety
/// This function requires that the provided value is a valid [Felt] representation of an
/// [AccountId].
pub unsafe fn new_unchecked(value: Felt) -> AccountId {
pub fn new_unchecked(value: Felt) -> AccountId {
AccountId(value)
}

Expand Down
2 changes: 1 addition & 1 deletion objects/src/assets/fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl FungibleAsset {
/// Creates a new [FungibleAsset] without checking its validity.
pub(crate) fn new_unchecked(value: Word) -> FungibleAsset {
FungibleAsset {
faucet_id: unsafe { AccountId::new_unchecked(value[3]) },
faucet_id: AccountId::new_unchecked(value[3]),
amount: value[0].as_int(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion objects/src/assets/nonfungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl NonFungibleAsset {

/// Return ID of the faucet which issued this asset.
pub fn faucet_id(&self) -> AccountId {
unsafe { AccountId::new_unchecked(self.0[FAUCET_ID_POS]) }
AccountId::new_unchecked(self.0[FAUCET_ID_POS])
}

// HELPER FUNCTIONS
Expand Down

0 comments on commit bd9a7ac

Please sign in to comment.