1

Is it possible for a validator to get the current time without it being passed in via the redeemer? My validator is heavily dependent on the time being correct so it would probably be a bad design choice to allow the wallet to pass in the time, as it can lie about the current time.

2

The usual way to handle time in Plutus is using Slot ranges. This means that the script does not query the time. Instead it checks that the validation happens in a given slot interval that corresponds to a time. You can have a look at the notes about slots from the Plutus Pioneers Course.

With these slots, you can ensure that the validation takes place before, after or in a certain slot interval. And when you are sure that the validation takes place in a specific time interval, you also know the corresponding time. Each slot corresponds to one second as described here.

1
  • Perfect. Your response captures everything I questioning! Oct 25 '21 at 13:59
1

How about parameterizing the validator with Slot or POSIXTime and passing the current time from the contract to the validator script using Contract.currentTime or Contract.currentSlot?

That way, the wallet has no influence on it.

1
  • I could do this, but the issue is that the contract I am creating has quite a lot of different deadlines floating around. So asking for all of these up front would be annoying for someone using it and could allow for more mistakes/vulnerabilities. Oct 25 '21 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.