In this level, you are presented with a straightforward vesting smart contract. The contract locks a certain amount of ADA assets, allowing the beneficiary to claim them in full once the specified vesting period expires. In our example, the vesting period is set to 5 hours. However, waiting for it is boring. Your task is to uncover the concealed vulnerability in the smart contract and unlock the funds much sooner.
The setup involves creating a vesting UTxO that secures an ADA amount for a 5-hour period, with you as the sole beneficiary.
There is a single validator in vesting.ak
.
Note the additional ?
after certain logical predicates in the code. These
indicators assist in pinpointing where the validator fails. You can check the
documentation
here. When
building the validator with the aikend build --keep-traces
command and
encountering a failure during its execution, the stack trace of failed
predicates will be displayed.
Similar to the previous levels, you need to duplicate the player_template.ts
file, naming it player.ts
, and executing the off-chain code with
deno run --allow-net --allow-read ./scripts/run.ts
.
Vesting operates with timestamps. However, the emulator used for testing
contains an own internal clock that does not correspond to the current time.
This creates a discrepancy between the code run on the emulator and on the
testnet, each requiring different timestamps. To address this issue, the
getCurrentTime(lucid)
function was introduced. This function returns the
current timestamp (in milliseconds) based on the used framework. You can then
manipulate this timestamp as usual.
For instance, the timestamp at the time of the vesting creation could be
getCurrentTime(lucid)
and the resulting vesting end would then be set to
getCurrentTime(lucid) + 5 * 60 * 60 * 1000
.
Transactions in this level are somewhat more intricate, involving the setting of multiple additional parameters to build the transactions. To understand the workings of these options and explore other configurable parameters, refer to the documentation. While this level provides all the necessary information, understanding the full extent of your options can prove valuable in later levels.