-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdos.sol
More file actions
34 lines (29 loc) · 1.35 KB
/
dos.sol
File metadata and controls
34 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/// @dev A Denial-of-Service (DoS) attack on a Ethereum smart
/// @dev contract occurs when an attacker floods the contract
/// @dev with a large number of requests, leading to high gas
/// @dev costs and rendering the contract unusable. This can
/// @dev occur in various forms, such as sending many
/// @dev transactions to a contract in a short period of time,
/// @dev calling a function repeatedly with high gas costs,
/// @dev or using reentrancy attacks to repeatedly call a function.
/// @dev To prevent DoS attacks, you can implement rate limiting,
/// @dev access control checks, or contract incentives that encourage
/// @dev users to submit proposals in a responsible manner.
pragma solidity >=0.5.0 <0.8.0;
contract Proposal {
uint256 public proposalCount;
uint256 public maxProposalsPerMinute;
uint256 public lastSubmissionTimestamp;
// limit the number of proposals that can be submitted per minute
modifier limitProposalsPerMinute() {
if (proposalCount >= maxProposalsPerMinute) {
require(now >= lastSubmissionTimestamp + 60 seconds, "Too many proposals submitted in a short period of time. Please try again later.");
}
proposalCount++;
lastSubmissionTimestamp = now;
_;
}
function submitProposal(string memory proposal) public limitProposalsPerMinute {
// ...
}
}