core-contracts icon indicating copy to clipboard operation
core-contracts copied to clipboard

Potential updates of factory contracts needed due to increased deployment cost

Open jakmeier opened this issue 2 years ago • 2 comments

Deployment costs per byte of code are going to be increased by a factor of ~5 with this change: https://github.com/near/nearcore/pull/6397

Probably this will happen with protocol version 53, which would be released on testnet by March 23 and on mainnet by April 20.

I listed all the indirect deployments from the past that would fail with the new cost. lockup-factory showed up 74 times and staking-pool-factory showed up once. Meaning today's usage patterns of these contracts will potentially break with this change.

  • For the lockup-factory, I believe no code changes are required. I recommend attaching 300Tgas on all caller sites. It should be checked if scripts and tools need to be updated for this.
  • For the staking-pool-factory, the one transaction that showed up is this. This looks like a false-positive. (My script generally overestimates the contract sizes and hence it is bound to have some false-positives.) Not sure if anything needs to be done here but I wanted to at least raise awareness.

Details on lockup-factory

It looks like today always 110Tgas is attached (example). 2x 25Tgas of that are reserved for function calls after the deployment, leaving 60Tgas for the create function call. Today's deployment cost for lockup_contract.wasm with 337 KB is ~4.96Tgas and it will change to ~24.43Tgas. And it looks like the function call execution itself costs ~40Tgas. So 40Tgas + 24.43Tgas < 60Tgas means calling create with the new costs and only 110Tgas will fail to execute.

Details on staking-pool-factory

The transaction in question attached 200Tgas. 2x 50Tgas are reserved and ~38.86 Tgas is burnt in the function call execution today. staking_pool.wasm is 250kB today, which translates to ~3.78Tgas for deployment with the current price and 18.22Tgas with new costs. So I reckon this should not break as it is.

cc @austinabell

jakmeier avatar Mar 09 '22 08:03 jakmeier

I also noticed the deployment of the multisig-factory contract require at least 2 near of storage balance for the new contract. I also tried creating a fresh factory contract that creates a ft contract and it costs 6 near to deploy the contract. why is it that expensive?

ConfidenceYobo avatar Sep 16 '22 00:09 ConfidenceYobo

@ConfidenceYobo storage costs are somewhat orthogonal to gas costs. But it could be that the contract you are deploying is larger than it needs to be. 100kB ~ 1 NEAR of storage staking, so if it requires 6 NEAR in your case it seems your contract WASM is 600kB. That's not unreasonable but intuitively I would have expected a simple FT contract to be smaller.

Here is some good documentation on how to reduce WASM size: https://rustwasm.github.io/docs/book/reference/code-size.html#optimizing-builds-for-code-size

jakmeier avatar Sep 20 '22 07:09 jakmeier