From 34fdb21d820bbb2310ff68382982190bc159d5fe Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Fri, 27 Jun 2025 20:31:07 +0300 Subject: [PATCH] try to avoid re-entrancy on burn function Signed-off-by: Uncle Fatso --- src/mocks/Reserve.sol | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mocks/Reserve.sol b/src/mocks/Reserve.sol index d491add..2ad8a1d 100644 --- a/src/mocks/Reserve.sol +++ b/src/mocks/Reserve.sol @@ -55,12 +55,15 @@ contract Reserve is ERC20Permit { } function burn(uint256 amount) external payable { - (bool sent,) = msg.sender.call{ value: estimateAmount(amount) }(""); - require(sent, "Failed to send Ether"); _innerBurn(msg.sender, amount); + uint256 valueDiff = address(this).balance - accumulatedDonation; + uint256 valueBack = amount * valueDiff / (amount + totalSupply()); + + (bool sent,) = msg.sender.call{ value: valueBack }(""); + require(sent, "Failed to send Ether"); } - function estimateAmount(uint256 amount) public view returns (uint256) { + function estimateAmount(uint256 amount) external view returns (uint256) { uint256 valueDiff = address(this).balance - accumulatedDonation; return amount * valueDiff / totalSupply(); }