Sword-Smith / Sword

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

Design and implement a balance checker. #5

Closed einar-io closed 3 years ago

einar-io commented 3 years ago

Design and implement a balance checker. The checker should take either an AST, or probably better, an immediate langauge representation and check if both branches of each if e within t then b1 else b2 amount to the same value.

Sword-Smith commented 3 years ago

If this is not done, we risk that the derivative contract ends up with a positive balance once all the parties have been paid out their share of the settlement token. So we risk that value is locked on the DC and no one would be able to get this value out.

Ulrik-dk commented 3 years ago

A minimal example showcasing loss of SA's could be:

if false within seconds(1) then
  transfer(DAI, pos1)
else
  zero

If we decide to remove zero as a valid contract, what would be a minimal example of a contract where SA's would be lost?

Maybe something like this?

if false within seconds(1) 
then
  scale(2,2,transfer(DAI, pos1))
else
  scale(1,1,transfer(DAI, pos2))
Sword-Smith commented 3 years ago

This problem has been superseded/deprecated by #21 as we decided to allow these "skewed" contracts but simply make a tokenID=0 to receive any refunds of the collateral.