Skip to content

Latest commit

 

History

History
61 lines (39 loc) · 3.44 KB

1.md

File metadata and controls

61 lines (39 loc) · 3.44 KB

Task 1: Inheritance Smart Contract

File with solution

Create a contract that has the ability to transfer all TONs from its balance in case the owner of the contract stops communicating.

The contract must accept an external message (meaning the contract will process the message at the expense of its balance) with op = 0x9df10277, which contains information and a signature that is obtained after signing this information.

The information must contain a 32-bit uint number, which will indicate how many seconds the execution of the will is delayed (locked_for) and a seqno to prevent scammers from using old messages on behalf of the contract owner multiple times.

After this time (the number of seconds passed in locked_for) any user can call external message with op = 0xbb4be234, which will transfer all TONs from the contract balance to the recipient's address (taken from the store, set via init_store of the contract).

Contract Store:

  • public_key: uint256
  • execution_time: uint32
  • receiver: MsgAddressInt
  • seqno: uint32

Function 0x9df10277

The body of the message op = 0x9df10277 must have a signature and 1 ref that will point to the cell with locked_for and new_seqno.

TL-B:

update#9df10277 signature:bits512 ^[ locked_for:uint32 new_seqno:uint32 ] = ExtInMsgBody

The contract will read the signature (512 bits), get ref, calculate its hash and check the validity of the received signature using the public key from its storage.

The checks go strictly in the following order:

  • If new_seqno != seqno + 1, error 119 must be thrown. This is a check for the fact that this is a new transaction (and not an old one that was sent again).
  • If the signature does not match, you should throw error 120. This is a check on the admin.
  • If locked_for <= 0, then error 121 must be thrown. locked_for must be strictly positive.
  • If execution_time < now(), you should throw error 122. Checking that execution_time has not passed yet.
  • If now + locked_for < execution_time, throw error 123. Checking that the deferral of the will is strictly greater than the value by which it has already been deferred.

If all checks pass, then you need to update the execution_time field in the contract.

The logic is as follows:

For example, if the admin passes locked_for = 100, it means that for 100 seconds from now (execution_time = now() + locked_for) the contract will be locked for the beneficiary to receive the will. For example, if the admin set the execution of the will at 100 seconds, and 60 seconds later came back and "postpone" execution for another 200 seconds, then execution_time = T0 + 60 + 200, where T0 is now() from the first transaction to postpone the will.

Function 0xbb4be234

If execution_time has already occurred, then any user can send a message with op = 0xbb4be234 and the receiver will receive the translation of the will.

TL-B:

take_ownership#bb4be234 public_key:uint256 = ExtInMsgBody
  • If execution_time has not occurred, error 124 should be thrown.
  • If execution_time has passed, the contract sends all TONs from its balance to the receiver's balance from the store. Mode = 128 / Ton value = 0 / No message body in transaction

GET methods

The contract must have the following GET methods:

  • get_seqno: returns the last up-to-date seqno from the store
  • get_execution_time: returns the time in seconds when the contract should be unlocked to transfer the TONs to the beneficiary address.