Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential updates of factory contracts needed due to increased deployment cost #206

Open
jakmeier opened this issue Mar 9, 2022 · 2 comments

Comments

@jakmeier
Copy link

jakmeier commented Mar 9, 2022

Deployment costs per byte of code are going to be increased by a factor of ~5 with this change: near/nearcore#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

@ConfidenceYobo
Copy link

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?

@jakmeier
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants