From 731806457f57aecf9a1700ce779cfdbffda02dbd Mon Sep 17 00:00:00 2001 From: Kirk Wight Date: Sun, 28 Nov 2021 12:59:44 -0800 Subject: [PATCH] Avoid potential re-entrancy attacks in the `donate()` method. --- contracts/Fundraisers.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/Fundraisers.sol b/contracts/Fundraisers.sol index d2ae1f7..5281f66 100644 --- a/contracts/Fundraisers.sol +++ b/contracts/Fundraisers.sol @@ -157,8 +157,6 @@ contract Fundraisers is Ownable { "program is not active" ); Program memory receivingProgram = programs[programId]; - (bool sent, ) = receivingProgram.charity.call{value: msg.value}(""); - require(sent, "ether not sent to charity"); donations.push( Donation({ doner: msg.sender, @@ -166,6 +164,8 @@ contract Fundraisers is Ownable { amount: msg.value }) ); + (bool sent, ) = receivingProgram.charity.call{value: msg.value}(""); + require(sent, "ether not sent to charity"); emit DonationReceived( msg.value, receivingProgram.charity,