Provably Fair
Raffle uses NoisRNG - https://nois.network/ as a source of randomness during the raffle draw. The raffle can only be drawn by us randomly after the end. This ensures that no one can draw the raffle during a favorable time.
The randomness is then used to determine the winner by generating a random number with the code below:
pub fn extractWinner(raffle: Raffle){
let randomness: [u8; 32] = randomness
.to_array()
.maperr(|| ContractError::InvalidRandomness)?;
let winner_index = int_in_range(randomness, 0, (raffle.ticket_list.len() - 1) as u64);
let winner = if winner_index < raffle.ticket_list.len() as u64 {
raffle.ticket_list[winner_index as usize].clone()
}
else {
raffle.creator.clone()
};
}
let winner = extractWinner(raffle);
Here winner_index is the index of winner drawn i.e. 0 for 1st winner, 1 for 2nd winner and so on. The random number is then used to find the winner's index from the list of buyers stored onchain.
Last updated