-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d653425
commit 0247c3b
Showing
1 changed file
with
15 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,25 @@ | |
pragma solidity ^0.8.20; | ||
|
||
contract ProofOfLiveness { | ||
uint256 constant PROOF_PERIOD = 24 hours; | ||
uint256 constant LAST_PERIODS_LENGTH = 5; | ||
|
||
// Mapping to track the last time the user proved liveness | ||
mapping(address => uint256) public lastProofTimestamp; | ||
|
||
// Custom error for when a user has already proved liveness within the last 24 hours | ||
// Custom error for when a user has already proved liveness within the last PROOF_PERIOD | ||
error ProofWithinLast24Hours(uint256 lastProofTime); | ||
|
||
// Event to log when liveness is proved | ||
event LivenessProved(address indexed user, uint256 proofTimestamp); | ||
|
||
// The function to prove liveness, can only be called once every 24 hours | ||
// The function to prove liveness, can only be called once every PROOF_PERIOD | ||
function proveLiveness() external { | ||
uint256 currentTime = block.timestamp; | ||
uint256 lastProofTime = lastProofTimestamp[msg.sender]; | ||
|
||
// Check if the user has proved liveness within the last 24 hours | ||
if (currentTime < lastProofTime + 24 hours) { | ||
// Check if the user has proved liveness within the last PROOF_PERIOD | ||
if (currentTime < lastProofTime + PROOF_PERIOD) { | ||
revert ProofWithinLast24Hours(lastProofTime); | ||
} | ||
|
||
|
@@ -28,22 +31,22 @@ contract ProofOfLiveness { | |
emit LivenessProved(msg.sender, currentTime); | ||
} | ||
Check notice Code scanning / Slither Block timestamp Low
ProofOfLiveness.proveLiveness() uses timestamp for comparisons
Dangerous comparisons: - currentTime < lastProofTime + PROOF_PERIOD |
||
|
||
// Helper function to check if a user can prove liveness (returns true if 24 hours have passed) | ||
// Helper function to check if a user can prove liveness (returns true if PROOF_PERIOD have passed) | ||
function canProveLiveness(address user) external view returns (bool) { | ||
uint256 currentTime = block.timestamp; | ||
return currentTime >= lastProofTimestamp[user] + 24 hours; | ||
return currentTime >= lastProofTimestamp[user] + PROOF_PERIOD; | ||
} | ||
Check notice Code scanning / Slither Block timestamp Low
ProofOfLiveness.canProveLiveness(address) uses timestamp for comparisons
Dangerous comparisons: - currentTime >= proofHistory[user][0] + PROOF_PERIOD |
||
|
||
// View function to return the liveness proof status for the last 5 periods (each 24 hours long) | ||
function getLastFivePeriodsStatus(address user) external view returns (bool[5] memory) { | ||
// View function to return the liveness proof status for the last LAST_PERIODS_LENGTH periods (each PROOF_PERIOD long) | ||
function getLastPeriodsStatus(address user) external view returns (bool[LAST_PERIODS_LENGTH] memory) { | ||
uint256 currentTime = block.timestamp; | ||
uint256 lastProofTime = lastProofTimestamp[user]; | ||
|
||
bool[5] memory proofStatus; | ||
uint256 periodDuration = 24 hours; | ||
bool[LAST_PERIODS_LENGTH] memory proofStatus; | ||
Check warning Code scanning / Slither Uninitialized local variables Medium
ProofOfLiveness.getLastPeriodsStatus(address).proofStatus is a local variable never initialized
|
||
uint256 periodDuration = PROOF_PERIOD; | ||
|
||
for (uint256 i = 0; i < 5; i++) { | ||
// Calculate the start of the period (going back i * 24 hours) | ||
for (uint256 i = 0; i < LAST_PERIODS_LENGTH; i++) { | ||
// Calculate the start of the period (going back i * PROOF_PERIOD) | ||
uint256 periodStart = currentTime - (i * periodDuration); | ||
uint256 periodEnd = periodStart - periodDuration; | ||
|
||
|