Skip to content
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

Support timestamps #310

Open
DJRHails opened this issue Aug 9, 2018 · 0 comments
Open

Support timestamps #310

DJRHails opened this issue Aug 9, 2018 · 0 comments
Labels

Comments

@DJRHails
Copy link
Member

DJRHails commented Aug 9, 2018

The standard library should include some support for timestamps. Although difficult and dangerous in decentralised environments a large segment of contracts use them extensively in relatively safe ways. In Flint we would want the safe way to be the only way.

Using the block timestamp is dangerous as it has been shown that it can be manipulated by a miner. However this, through game theory principles, is limited in scope.

Two suggested methods for including time dependence in a safe way are:

Restricted to fixed timescales

Due to the reverse incentive for other miners to mine on top of a block clearly in the future. 12 Minutes has been approximated as a safe dift boundary.

if startTime.isNHoursLater(2) {

}

struct Time {
  functions isNHoursLater(hour: Int) {
    return blockTimestamp() > self.start + hour * HOUR_FACTOR
  }
}

Block based timestamp

Block numbers and average block time can be used to estimate time, but this is not future proof as block times may change (such as the changes expected during Casper).

Namely a new block is mined approximately every 12s therefore we can include a standard library function like below:

if Time.roughlyExceeds("2018-07-01", "19:00") {

}

struct Time {
  functions roughlyExceeds(date: Date, time: Time) {
    epocTime = epoc(date, time) // Number of seconds from first block creation
    expectedBlockNumber = epoc / 12 
    return blockNumber() > expectedBlockNumber
  }
}
@DJRHails DJRHails changed the title Timestamp support Support timestamps Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant