Context
In third weeks plutus pioneer lecture lars said that Vesting period shouldn't be longer than 36 hours. He argued that this is because time is calculated in slots on-chain and that this parameter might change in the future:
There is one slight complication that Ouroboros, the consensus protocol powering Cardano, does not use POSIX time; it uses slots. Plutus uses real time, so we need to be able to convert back and forth between real time and slots. Right now, the slot length is one second. Knowing that, it is easy to go back and forth between real time and slot numbers. However, this could change in future through a parameter change via a hard fork. And, of course, we can't know that in advance.
We do not know right now what the slot length will be in 10 years, for example. This means that we must not have a definite upper bound. We know what the slot length will be in the next 36 hours because if there's a change in protocol parameters, then we know that at least 36 hours in advance.You can not specify arbitrary time ranges in the transaction interval. It must only be at most 36 hours in the future, or it can be indefinite.
I would like to implement vesting smartcontract but for much longer time periods, for example 9 months.
Problem
Right now I see two ways to implement restriction by time:
- Use
txInfoValidRange
by specifying transaction valid range. However I see a huge problem here or maybe I just dont' understandtx valid range
correctly. Lets say that validator is of alwayssucceeds type but with addedtx valid range
check. I don't get it how to guarantee that funds are to be locked until specified SLOT, since in this case anyone can build transaction with w/e--invalid-before SLOT
parameter they want.
data VestingDatum = VestingDatum
{ deadline :: POSIXTime
} deriving Show
{-# INLINABLE mkValidator #-}
mkValidator :: VestingDatum -> () -> ScriptContext -> Bool
mkValidator dat () ctx = traceIfFalse "deadline not reached" deadlineReached
where
info :: TxInfo
info = scriptContextTxInfo ctx
deadlineReached :: Bool
deadlineReached = contains (from $ deadline dat) $ txInfoValidRange info
- Provide some kind of time NFT from oracle.
Questions
- What is currently the best way to implement Vesting with longer than 36 hours time periods?
- How likely is 1 SLOT == 1 Second parameter to change in the future, when and by how much?
- Does universal time NFT oracle exist in Cardano ecosystem?
- Is there a way to provide restriction that for funds to be unlocked from the smartcontract transaction must have specific
--invalid-before SLOT
parameter?