-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding time check contract #8
Draft
wei3erHase
wants to merge
2
commits into
dev
Choose a base branch
from
feat/time-check
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[workspace] | ||
members = [ | ||
"src/token_contract" | ||
"src/token_contract", | ||
"src/time_check_contract" | ||
] |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "time_check_contract" | ||
authors = [""] | ||
compiler_version = ">=1.0.0" | ||
type = "contract" | ||
|
||
[dependencies] | ||
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "aztec-packages-v0.72.1", directory = "noir-projects/aztec-nr/aztec" } |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Timestamp verification in private circuits | ||
|
||
## Overview | ||
|
||
In private circuits, timestamps are challenging to use since circuits are timeless, and proofs cannot depend on when they are generated. Aztec’s PrivateContext does not include a timestamp variable due to the transaction lifecycle: proving → broadcasting → inclusion on-chain. | ||
|
||
However, many DeFi applications require time-based logic, such as vesting schedules. The usual alternative block numbers may not be suitable in all cases. | ||
|
||
## Solution | ||
|
||
To verify timestamps privately: | ||
|
||
- Users optimistically input the timestamp in the circuit. | ||
- A call to a public function is enqueued to check its validity against the execution timestamp. | ||
- If incorrect, the transaction and state changes (private and public) revert. | ||
- To prevent privacy leaks, this intermediary contract TimeCheck is used: | ||
- Instead of `ContractA(private)` → `ContractA(public)`, | ||
- Transaction flows as `ContractA(private)` → `TimeCheck(private)` → `TimeCheck(public)`. | ||
|
||
This prevents observers from linking the timestamp check to a specific contract, ensuring confidentiality. |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use dep::aztec::macros::aztec; | ||
|
||
#[aztec] | ||
// Timestamp validation in private circuits, for secure and anonymous time-based logic execution. | ||
contract TimeCheck { | ||
|
||
/** ========================================================== | ||
* ========================= IMPORTS ========================= | ||
* ======================================================== */ | ||
|
||
use dep::aztec::macros::functions::{internal, private, public}; | ||
|
||
/** ========================================================== | ||
* ==================== PRIVATE ENTRYPOINTS ================== | ||
* ======================================================== */ | ||
|
||
#[private] | ||
fn timestamp_gt(t: u64) { | ||
TimeCheck::at(context.this_address()).assert_timestamp_gt(t).enqueue(&mut context); | ||
} | ||
|
||
#[private] | ||
fn timestamp_lt(t: u64) { | ||
TimeCheck::at(context.this_address()).assert_timestamp_lt(t).enqueue(&mut context); | ||
} | ||
|
||
/** ========================================================== | ||
* ===================== PUBLIC ENTRYPOINTS ================== | ||
* ======================================================== */ | ||
|
||
#[public] | ||
#[internal] // TODO: is internal needed here? | ||
fn assert_timestamp_gt(t: u64) { | ||
let current_t = context.timestamp(); | ||
// TODO: define if = should pass or not | ||
assert(current_t >= t, "Timestamp not greater than current"); | ||
} | ||
|
||
#[public] | ||
#[internal] // TODO: is internal needed here? | ||
fn assert_timestamp_lt(t: u64) { | ||
let current_t = context.timestamp(); | ||
// TODO: define if = should pass or not | ||
assert(current_t <= t, "Timestamp not lesser than current"); | ||
} | ||
|
||
// NOTE: assert_timestamp_eq has no actual application (prone to fail) | ||
/* TODO: | ||
* Implement: | ||
* - timestamp_gt_by_delta(t:64, delta: 64) | ||
* - timestamp_lt_by_delta(t:64, delta: 64) | ||
*/ | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt about using these banners and order of declaration?
i'd suggest sth like: