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

Incorrect estimation and high gas costs on first call to deposit::topupDeposit() #1991

Open
DrZoltanFazekas opened this issue Dec 9, 2024 · 0 comments
Assignees
Labels
Agate Required for mainnet launch

Comments

@DrZoltanFazekas
Copy link
Contributor

When the deposit contract's topupDeposit() function is called for the very first time (in the example below from a proto-testnet delegation contract's stake() function) it uses a large amount of gas:

[Success]Hash: 0x35168b94728dd1182ef88e52ec7447bff380c2a9c79fc0ebf2afe0ab44994314
Block: 7777350
Paid: 5.2112190893088 ETH (1094356 gas * 4761.9048 gwei)

When it's called for the second time by another staker's control address (i.e. in the example below by another delegation contract) it uses one order of magnitude less gas:

[Success]Hash: 0x5c81ccf531a88c020fc88598fb5d36c644868bf100d3955445ffb0b41226511b
Block: 7777407
Paid: 0.8082523874184 ETH (169733 gas * 4761.9048 gwei)

Finally, each time it's called by the same staker's control address again, it uses a constant amount of gas:

[Success]Hash: 0xe6b01ba749c3cbdcdecb9f83d9ea23c9d91b8734c6b331a4b063e6d4e7d7773e
Block: 7777451
Paid: 0.6453952432584 ETH (135533 gas * 4761.9048 gwei)

Most likely the first initialization of storage slots makes the very first call so expensive. Investigate how to make the distribution of gas costs across the calls more fair.

Another issue that was observed is that if the first call was in a transaction submitted from the Rabby wallet, the transaction ran out of gas i.e. the estimation delivered a gas limit that was too low to execute the transaction. If the transaction was submitted using a Forge script like above, the estimated gas limit was sufficient though.

@DrZoltanFazekas DrZoltanFazekas changed the title High gas costs on first call to deposit::topupDeposit() Incorrect estimation and high gas costs on first call to deposit::topupDeposit() Dec 9, 2024
@DrZoltanFazekas DrZoltanFazekas added the Agate Required for mainnet launch label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agate Required for mainnet launch
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants