Sword-Smith / Sword

Sword — A financial derivative language for the blockchain
MIT License
29 stars 2 forks source link

Allow PT_0 holder to calculate PT_i values #24

Closed Sword-Smith closed 3 years ago

Sword-Smith commented 3 years ago

PT_0 will only get their payouts once all PT_i values are evaluated such that they are no longer stored as -1 values in storage. If we on a PT0 payout execution encounter a -1 evaluated value for the ith PT we must check if the PT_i value can be calculated before we determine if the PT_0 payout should occur or not.

Sword-Smith commented 3 years ago

The problem here would be that the balance check-guard for a specific TransferCall would happen before the EvaluatedTcValue for this TransferCall was set in storage. This would mean that the EvaluatedTcValue might never be set for this TransferCall and that PT0's payout was stuck (or certainly delayed) in the derivative contract.

Sword-Smith commented 3 years ago

Our fix must work both when a non-invoked PT_i, for i != 0 has a zero value and a positive value. The only way to ensure this is to ensure a specific flow looping over all TCs even when balance(TC_i) = 0, for i != 0. In other words: we must ensure payout evaluation of all PTs although balance(PT_i) = 0, for i != 0.

Sword-Smith commented 3 years ago

It seems to me that the current state of the compiler only makes the evaluation when the branch is dead, but not when the branch has a zero or non-zero value but the branch is not dead.

Sword-Smith commented 3 years ago

This has been verified to work correctly through commits up to 3dbdb189c343d3fdf7b253692c2d5af81832c3b5 in geth_tools. Here, we have tested that PT0 calls to pay() work even though no TransferCall payout values have been evaluated prior to the call to pay() by the party with a non-zero PT0 balance but a zero PT_i balance for all i != 0.