Skip to content

Commit

Permalink
fix token re-entrance
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Mar 5, 2024
1 parent 5ed71d2 commit a78859a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/airdrop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub trait IAirdrop<TStorage> {
pub mod Airdrop {
use core::array::{ArrayTrait, SpanTrait};
use core::hash::{LegacyHash};
use core::num::traits::zero::{Zero};
use core::num::traits::one::{One};
use core::num::traits::zero::{Zero};
use governance::interfaces::erc20::{IERC20DispatcherTrait};
use governance::utils::exp2::{exp2};
use super::{IAirdrop, ContractAddress, Claim, IERC20Dispatcher};
Expand Down Expand Up @@ -206,19 +206,16 @@ pub mod Airdrop {
let mut index: u8 = 0;
let mut num_claimed: u8 = 0;

let mut claims_to_execute: Array<Claim> = ArrayTrait::new();

loop {
match claims_for_claiming.pop_front() {
Option::Some(claim) => {
let already_claimed = (bitmap & exp2(index)).is_non_zero();

if !already_claimed {
bitmap = bitmap | exp2(index);

// todo: this assumes the token will not reenter this contract
self.token.read().transfer(*claim.claimee, (*claim.amount).into());

self.emit(Claimed { claim: *claim });

claims_to_execute.append(*claim);
num_claimed += 1;
}

Expand All @@ -229,7 +226,19 @@ pub mod Airdrop {
};

self.claimed_bitmap.write(word, bitmap);


let token = self.token.read();

loop {
match claims_to_execute.pop_front() {
Option::Some(claim) => {
token.transfer(claim.claimee, claim.amount.into());
self.emit(Claimed { claim });
},
Option::None => { break (); }
};
};

num_claimed
}

Expand Down

0 comments on commit a78859a

Please sign in to comment.