Skip to content

Commit 609e72e

Browse files
committed
compute creator hash using metadata args
1 parent 573d61b commit 609e72e

File tree

4 files changed

+22
-65
lines changed

4 files changed

+22
-65
lines changed

programs/mmm/src/instructions/cnft/sol_cnft_fulfill_buy.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::{
1010
util::{
1111
assert_valid_fees_bp, check_allowlists_for_cnft, check_remaining_accounts_for_m2,
1212
get_buyside_seller_receives, get_lp_fee_bp, get_sol_fee, get_sol_lp_fee,
13-
get_sol_total_price_and_next_price, hash_metadata, log_pool, pay_creator_fees_in_sol_cnft,
14-
transfer_compressed_nft, try_close_escrow, try_close_pool, try_close_sell_state,
15-
verify_creators, withdraw_m2,
13+
get_sol_total_price_and_next_price, hash_creators_from_metadata_args, hash_metadata,
14+
log_pool, pay_creator_fees_in_sol_cnft, transfer_compressed_nft, try_close_escrow,
15+
try_close_pool, try_close_sell_state, withdraw_m2,
1616
},
1717
verify_referral::verify_referral,
1818
};
@@ -25,9 +25,6 @@ pub struct SolCnftFulfillBuyArgs {
2525
asset_id: Pubkey,
2626
// The Merkle root for the tree. Can be retrieved from off-chain data store.
2727
root: [u8; 32],
28-
// The Keccak256 hash of the NFTs existing creators array (without the verified flag for the creator changed).
29-
// The creators array is retrieved from off-chain data store.
30-
creator_hash: [u8; 32],
3128
// A nonce ("number used once") value used to make the Merkle tree leaves unique.
3229
// This is the value of num_minted for the tree stored in the TreeConfig account at the time the NFT was minted.
3330
// The unique value for each asset can be retrieved from off-chain data store.
@@ -207,26 +204,8 @@ pub fn handler<'info>(
207204
remaining_accounts.split_at(creator_length)
208205
};
209206

210-
let creator_shares = args
211-
.metadata_args
212-
.creators
213-
.iter()
214-
.map(|c| c.share as u16)
215-
.collect::<Vec<u16>>();
216-
217-
let creator_verified = args
218-
.metadata_args
219-
.creators
220-
.iter()
221-
.map(|c| c.verified)
222-
.collect();
223-
224-
verify_creators(
225-
creator_accounts.iter(),
226-
creator_shares,
227-
creator_verified,
228-
args.creator_hash,
229-
)?;
207+
let creator_hash =
208+
hash_creators_from_metadata_args(creator_accounts.iter(), &args.metadata_args)?;
230209

231210
// 3. Transfer CNFT to buyer (pool or owner)
232211
let data_hash = hash_metadata(&args.metadata_args)?;
@@ -253,7 +232,7 @@ pub fn handler<'info>(
253232
ctx.accounts.bubblegum_program.key(),
254233
args.root,
255234
data_hash,
256-
args.creator_hash,
235+
creator_hash,
257236
args.nonce,
258237
args.index,
259238
None, // signer passed through from ctx
@@ -284,7 +263,7 @@ pub fn handler<'info>(
284263
ctx.accounts.bubblegum_program.key(),
285264
args.root,
286265
data_hash,
287-
args.creator_hash,
266+
creator_hash,
288267
args.nonce,
289268
args.index,
290269
None, // signer passed through from ctx

programs/mmm/src/util.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,12 +1331,21 @@ pub fn hash_metadata(metadata: &MetadataArgs) -> Result<[u8; 32]> {
13311331
.to_bytes())
13321332
}
13331333

1334-
pub fn verify_creators(
1334+
pub fn hash_creators_from_metadata_args(
13351335
creator_accounts: Iter<AccountInfo>,
1336-
creator_shares: Vec<u16>,
1337-
creator_verified: Vec<bool>,
1338-
creator_hash: [u8; 32],
1339-
) -> Result<()> {
1336+
metadata_args: &MetadataArgs,
1337+
) -> Result<[u8; 32]> {
1338+
let creator_shares = metadata_args
1339+
.creators
1340+
.iter()
1341+
.map(|c| c.share as u16)
1342+
.collect::<Vec<u16>>();
1343+
1344+
let creator_verified = metadata_args
1345+
.creators
1346+
.iter()
1347+
.map(|c| c.verified)
1348+
.collect::<Vec<bool>>();
13401349
// Check that all input arrays/vectors are of the same length
13411350
if creator_accounts.len() != creator_shares.len()
13421351
|| creator_accounts.len() != creator_verified.len()
@@ -1360,17 +1369,7 @@ pub fn verify_creators(
13601369
// Compute the hash from the Creator vector
13611370
let computed_hash = hash_creators(&creators);
13621371

1363-
// Compare the computed hash with the provided hash
1364-
if computed_hash != creator_hash {
1365-
msg!(
1366-
"Computed hash does not match provided hash: {{\"computed\":{:?},\"provided\":{:?}}}",
1367-
computed_hash,
1368-
creator_hash
1369-
);
1370-
return Err(MMMErrorCode::InvalidCnftCreators.into());
1371-
}
1372-
1373-
Ok(())
1372+
Ok(computed_hash)
13741373
}
13751374

13761375
#[cfg(test)]

sdk/src/idl/mmm.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,15 +2688,6 @@ export type Mmm = {
26882688
]
26892689
}
26902690
},
2691-
{
2692-
"name": "creatorHash",
2693-
"type": {
2694-
"array": [
2695-
"u8",
2696-
32
2697-
]
2698-
}
2699-
},
27002691
{
27012692
"name": "nonce",
27022693
"type": "u64"
@@ -5969,15 +5960,6 @@ export const IDL: Mmm = {
59695960
]
59705961
}
59715962
},
5972-
{
5973-
"name": "creatorHash",
5974-
"type": {
5975-
"array": [
5976-
"u8",
5977-
32
5978-
]
5979-
}
5980-
},
59815963
{
59825964
"name": "nonce",
59835965
"type": "u64"

tests/mmm-cnft.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ describe('cnft tests', () => {
225225
.cnftFulfillBuy({
226226
assetId: new PublicKey(assetId),
227227
root: getByteArray(nft.tree.root),
228-
creatorHash: getByteArray(nft.tree.creatorHash),
229228
nonce: new BN(nft.tree.nonce),
230229
index: nft.nft.nftIndex,
231230
minPaymentAmount: new BN(expectedBuyPrices.sellerReceives),
@@ -467,7 +466,6 @@ describe('cnft tests', () => {
467466
.cnftFulfillBuy({
468467
assetId: new PublicKey(assetId),
469468
root: getByteArray(nft.tree.root),
470-
creatorHash: getByteArray(nft.tree.creatorHash),
471469
nonce: new BN(nft.tree.nonce),
472470
index: nft.nft.nftIndex,
473471
minPaymentAmount: new BN(expectedBuyPrices.sellerReceives),
@@ -683,7 +681,6 @@ describe('cnft tests', () => {
683681
.cnftFulfillBuy({
684682
assetId: new PublicKey(assetId),
685683
root: getByteArray(nft.tree.root),
686-
creatorHash: getByteArray(nft.tree.creatorHash),
687684
nonce: new BN(nft.tree.nonce),
688685
index: nft.nft.nftIndex,
689686
minPaymentAmount: new BN(expectedBuyPrices.sellerReceives),

0 commit comments

Comments
 (0)