Skip to content

Commit 0104e7f

Browse files
Create opt.sol
1 parent 9966773 commit 0104e7f

File tree

1 file changed

+34
-0
lines changed
  • program-analysis/echidna/example

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pragma solidity ^0.8.0;
2+
3+
contract TestDutchAuctionOptimization {
4+
int256 maxPriceDifference;
5+
6+
function setMaxPriceDifference(
7+
uint256 startPrice,
8+
uint256 endPrice,
9+
uint256 startTime,
10+
uint256 endTime
11+
) public {
12+
if (endTime < (startTime + 900)) {
13+
revert();
14+
}
15+
if (startPrice <= endPrice) {
16+
revert();
17+
}
18+
uint256 numerator = (startPrice - endPrice) *
19+
(block.timestamp - startTime);
20+
uint256 denominator = endTime - startTime;
21+
uint256 stepDecrease = numerator / denominator;
22+
uint256 currentAuctionPrice = startPrice - stepDecrease;
23+
if (currentAuctionPrice < endPrice) {
24+
maxPriceDifference = int256(endPrice - currentAuctionPrice);
25+
}
26+
if (currentAuctionPrice > startPrice) {
27+
maxPriceDifference = int256(currentAuctionPrice - startPrice);
28+
}
29+
}
30+
31+
function echidna_opt_price_difference() public view returns (int256) {
32+
return maxPriceDifference;
33+
}
34+
}

0 commit comments

Comments
 (0)