<p>Turns out I wasn't using the correct checkout of <code>plutus</code>. More details can be found at the following Cardano StackExchange answer: <a href="https://cardano.stackexchange.com/questions/3997/plutus-playground-server-sense-of-time-is-incorrect/3998#3998">plutus-playground-server sense of time is incorrect</a></p>

CC BY-SA 4.0
2021-10-02T20:38:53.697Z
2021-10-02T20:38:53.697Z
Paymahn Moghadasian
<p>I'm having some trouble figuring out the vesting logic in <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week03/src/Week03/Homework1.hs#L45-L49" rel="nofollow noreferrer">homework 1</a> of the Plutus pioneer program lecture. I eventually gave up and looked at the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week03/src/Week03/Solution1.hs#L46-L5" rel="nofollow noreferrer">solution</a> which seems to be exhibiting the same &quot;bug&quot; (I put bug in quotes because clearly I'm misunderstanding something).</p>
<p>As I understand the logic of the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week03/src/Week03/Homework1.hs#L82-L128" rel="nofollow noreferrer">transaction construction</a>, the <code>giver</code> (or <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/main/code/week03/src/Week03/Homework1.hs#L87" rel="nofollow noreferrer"><code>beneficiary2</code></a>) can claim the gift anytime after the deadline while the recipient (or <code>beneficiary1</code>) can claim the gift anytime before the deadline (inclusive). Is that correct?</p>
<p>If so, I'm having trouble understanding why the following simulation seems to succeed. I'll provide screenshots and then go through my understanding of it. Here are the values entered for the simulation that seems buggy to me:</p>
<p><a href="https://i.sstatic.net/xyPCt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xyPCt.png" alt="enter image description here" /></a></p>
<p>and here the final state of the blockchain:</p>
<p><a href="https://i.sstatic.net/qdAcC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qdAcC.png" alt="enter image description here" /></a></p>
<p>In this simulation, Wallet 1 is giving 10 ADA to <code>39f713d0a644253f04529421b9f51b9b08979d08295959c4f3990ee617f5139f</code> which is the hash of Wallet 2 (this can be confirmed by looking at the hash of the wallets in the final state screenshot). This gift has a deadline of <code>1596059101000</code> which is slot 10 based on:</p>
<pre><code>Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2&gt; posixTimeToEnclosingSlot def 1596059101000
Slot {getSlot = 10}
</code></pre>
<p>and</p>
<pre><code>Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2&gt; slotToBeginPOSIXTime de
f 10
POSIXTime {getPOSIXTime = 1596059101000}
</code></pre>
<p>Curiously, it seems that Wallet 2 can grab the gift at slot 11 which is after the deadline. It's very possible that my understanding of the transaction logic is incorrect. To double check, I also ran the same code with the following simulation (the only difference is that the second step of the simulation waits until slot 5 instead of slot 11) and it also succeeded which confuses me even more. I expect that one of these simulations should fail but can't figure out why.</p>
<p><a href="https://i.sstatic.net/CTXjb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CTXjb.png" alt="enter image description here" /></a></p>
<p>Is there a bug with the solution for homework 1 in lecture 3? Am I misunderstanding something about the logic of the solution?</p>
<p>EDIT: here's another interesting point, with the suggested solution I can't seem to get Wallet 1 to grab the gift it provides. I've tried waiting for 1 block after the gift, waiting until slot 5 and waiting until slot 15 before attempting for Wallet 1 to grab it's gift and in all cases it fails - the &quot;grab&quot; transaction never reaches the blockchain and seems to fail client side with <code>found 0 gift(s) to grab</code>.</p>

CC BY-SA 4.0
2021-10-01T17:19:29.233Z
On first glance, I don't see any flaws in your logic. Could be a bug in the Playground? I don't have time rn to dig in further. I'll try to come back to it.
Mitchell Turner
CC BY-SA 4.0
2021-10-01T20:27:19.387Z
ah yeah, could be a bug in the playground. I'm running the playground on commit `ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4` but now I'm realizing that the required plutus commit changes from week to week. `ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4` is from week 1 while week 3 requires `219992289c6615e197069d022735cb4059d43229`.
Paymahn Moghadasian
CC BY-SA 4.0
2021-10-02T19:22:11.823Z
Changing the commit of the local `plutus` repo to `219992289c6615e197069d022735cb4059d43229` doesn't fix this unfortunately 
Paymahn Moghadasian
CC BY-SA 4.0
2021-10-02T20:08:41.840Z
It was a long shot. I don't use the Playground at all, I just use the Emulator Trace: https://github.com/input-output-hk/plutus-pioneer-program/blob/9c83322743e393427acdc24525b04dfc1c49084d/code/week05/src/Week05/NFT.hs#L87 It might be easier to debug your code using that (but that's jumping ahead in the progam).
Mitchell Turner
CC BY-SA 4.0
2021-10-02T20:37:40.747Z
Oops, checking out commit `219992289c6615e197069d022735cb4059d43229` does solve the problem, I must have fat fingered something in the earlier comment which said it doesn't. Commit `ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4` seems to have a broken notion of time: https://cardano.stackexchange.com/questions/3997/plutus-playground-server-sense-of-time-is-incorrect/3998#3998
Paymahn Moghadasian
CC BY-SA 4.0
2021-10-02T21:05:15.900Z
Haha. Good to hear.
Mitchell Turner
<plutus-pioneer-program>
Plutus Pioneer lecture 3 homework 1 vesting logic
# Plutus Pioneer lecture 3 homework 1 vesting logic

(Asked by: username_0 on 2021-10-01)

I'm having some trouble figuring out the vesting logic in homework 1 of the Plutus pioneer program lecture. I eventually gave up and looked at the solution which seems to be exhibiting the same "bug" (I put bug in quotes because clearly I'm misunderstanding something).
As I understand the logic of the transaction construction, the giver (or beneficiary2) can claim the gift anytime after the deadline while the recipient (or beneficiary1) can claim the gift anytime before the deadline (inclusive). Is that correct?
If so, I'm having trouble understanding why the following simulation seems to succeed. I'll provide screenshots and then go through my understanding of it. Here are the values entered for the simulation that seems buggy to me:

and here the final state of the blockchain:

In this simulation, Wallet 1 is giving 10 ADA to 39f713d0a644253f04529421b9f51b9b08979d08295959c4f3990ee617f5139f which is the hash of Wallet 2 (this can be confirmed by looking at the hash of the wallets in the final state screenshot). This gift has a deadline of 1596059101000 which is slot 10 based on:
Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2> posixTimeToEnclosingSlot def 1596059101000
Slot {getSlot = 10}

and
Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2> slotToBeginPOSIXTime de
f 10
POSIXTime {getPOSIXTime = 1596059101000}

Curiously, it seems that Wallet 2 can grab the gift at slot 11 which is after the deadline. It's very possible that my understanding of the transaction logic is incorrect. To double check, I also ran the same code with the following simulation (the only difference is that the second step of the simulation waits until slot 5 instead of slot 11) and it also succeeded which confuses me even more. I expect that one of these simulations should fail but can't figure out why.

Is there a bug with the solution for homework 1 in lecture 3? Am I misunderstanding something about the logic of the solution?
EDIT: here's another interesting point, with the suggested solution I can't seem to get Wallet 1 to grab the gift it provides. I've tried waiting for 1 block after the gift, waiting until slot 5 and waiting until slot 15 before attempting for Wallet 1 to grab it's gift and in all cases it fails - the "grab" transaction never reaches the blockchain and seems to fail client side with found 0 gift(s) to grab.

**Tags:** plutus-pioneer-program
> **Comments:**
> **username_1**: On first glance, I don't see any flaws in your logic. Could be a bug in the Playground? I don't have time rn to dig in further. I'll try to come back to it.  
> **username_0**: ah yeah, could be a bug in the playground. I'm running the playground on commit `ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4` but now I'm realizing that the required plutus commit changes from week to week. `ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4` is from week 1 while week 3 requires `219992289c6615e197069d022735cb4059d43229`.  
> **username_0**: Changing the commit of the local `plutus` repo to `219992289c6615e197069d022735cb4059d43229` doesn't fix this unfortunately   
> **username_1**: It was a long shot. I don't use the Playground at all, I just use the Emulator Trace: https://github.com/input-output-hk/plutus-pioneer-program/blob/9c83322743e393427acdc24525b04dfc1c49084d/code/week05/src/Week05/NFT.hs#L87 It might be easier to debug your code using that (but that's jumping ahead in the progam).  
> **username_0**: Oops, checking out commit `219992289c6615e197069d022735cb4059d43229` does solve the problem, I must have fat fingered something in the earlier comment which said it doesn't. Commit `ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4` seems to have a broken notion of time: https://cardano.stackexchange.com/questions/3997/plutus-playground-server-sense-of-time-is-incorrect/3998#3998  
> **username_1**: Haha. Good to hear.  

---

## 1 answers

### Answer by username_0 on 2021-10-02. Score: 1 | Accepted answer

Turns out I wasn't using the correct checkout of `plutus`. More details can be found at the following Cardano StackExchange answer: [plutus-playground-server sense of time is incorrect](https://cardano.stackexchange.com/questions/3997/plutus-playground-server-sense-of-time-is-incorrect/3998#3998)


---

