Skip to content

Incorrect estimation and high gas costs of some calls to deposit::topupDeposit() #1991

@DrZoltanFazekas

Description

@DrZoltanFazekas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions