archethic-foundation / archethic-node

Official Archethic Blockchain node, written in Elixir
GNU Affero General Public License v3.0
71 stars 22 forks source link

Ensure enough funds during smart contract call validation #1493

Closed samuelmanzanera closed 5 months ago

samuelmanzanera commented 5 months ago

Description

This PR aims to fix an issue to accept a smart contract call if the contract doesn't have funds for the transaction triggered by the contract based on the movements.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Create a smart contract which send UCO once a trigger transaction is received. Do not funds the contract with the UCO to send in the action; If a client call the contract it should be rejected. Fund more the contract to satisfy the UCO to send in the action Resent the transaction from the client to call the contract, the contract's transaction should be validated and emitted.

Checklist:

samuelmanzanera commented 5 months ago

I think this kind of verification should not be done in the Interpreter module. Interpreter is intended to execute a contract code and create an output transaction, but it should not have functional verification on other domain than contract code execution. I guess this verification could be done in ValidateSmartContractCall message.

Moreover, the contract could create movement based on the inputs received by the trigger. So if this verification is done during trigger transaction validation, the UTXO balance of the contract will not contains the inputs of the trigger tx so the verification might fail. But this could work for the worker execution of the contract.

Other question more functional, is the responsibility to determine if the contract has enough fund assigned to the worker or to the consensus through validation nodes ?

For the location of the code, yes I can do it in the P2P message itself no problem.

For the functional aspect, because validation do not execute the contracts locally, we have to request the workers to give us information about the feasibility of this transaction, including enough funds to execute it based on the funds retrieved by the validation nodes. As we should not accept a transaction where the validation nodes can know if this will be invalid just after.