tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
394 stars 111 forks source link

Do not store self smart-contract code: use MYCODE asm instruction instead #1012

Open imartemy1524 opened 2 weeks ago

imartemy1524 commented 2 weeks ago

The problem

Lets take a look on a 2 simple smart-contracts:

contract Parent{
    id: Int = 0;
    init(){}
    receive("new"){
        self.id += 1;
        let data = initOf Child(self.id);
        self.forward(contractAddress(data), "init".asComment(), true, data);
    }
}

contract Child{
    id: Int;
    init(id: Int){
        self.id = id;
    }

    receive("init"){}

    receive("deploy_random"){
        let data = initOf Child(randomInt());
        self.forward(contractAddress(data), "init".asComment(), true, data);
    }
}

Under the hood, both Parent and Child contracts stores the code of Child smart contract in the system dictionary, because in both of them initOf Child() used.

But storing code of Child smart contract inside Child is useless because one can call MYCODE asm instruction to get it.

This approach would reduce not only storageFees, but also forwardFees when initializing new smart-contracts.

It is really useful feature for developing Jetton smart contracts (when one child deploys another child), which optimizes fees a lot.

Feel free to argue to my point.

Gusarich commented 4 days ago

you're definitely right!