Skip to content

Commit 8d8f010

Browse files
committed
feat: random nft for mint
1 parent e5bec8a commit 8d8f010

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎rewards-delegated-vrf/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub fn consume_random_reward(
2525

2626
{
2727
let reward_list = &mut ctx.accounts.reward_list;
28+
// Log the raw randomness proof as hex for auditability
29+
msg!("Randomness proof: {:?}", randomness.map(|b| b));
2830
let rnd_u32 = ephemeral_vrf_sdk::rnd::random_u32(&randomness);
2931
let range = (reward_list.global_range_max as u64)
3032
.checked_sub(reward_list.global_range_min as u64)
@@ -61,7 +63,15 @@ pub fn consume_random_reward(
6163
let reward_type = reward.reward_type.clone();
6264
let mint = match reward_type {
6365
RewardType::LegacyNft | RewardType::ProgrammableNft => {
64-
reward.reward_mints.remove(0)
66+
let mint_count = reward.reward_mints.len();
67+
// Use a different slice of randomness to pick which mint
68+
// to send — avoids correlation with the reward selection.
69+
let mut rnd_bytes = [0u8; 32];
70+
rnd_bytes.copy_from_slice(&randomness);
71+
rnd_bytes.rotate_left(4);
72+
let rnd_mint = ephemeral_vrf_sdk::rnd::random_u32(&rnd_bytes);
73+
let mint_index = (rnd_mint as usize) % mint_count;
74+
reward.reward_mints.remove(mint_index)
6575
}
6676
_ => reward.reward_mints[0],
6777
};

0 commit comments

Comments
 (0)