Skip to content

stETH and wstETH addresses can be saved on implementation to save gas #77

@zobront

Description

@zobront

The LidoSplitFactory contract holds two immutable values for the addresses of the stETH and wstETH tokens.

When new clones are deployed, these values are encoded as immutable args. This adds the values to the contract code of the clone, so that each time a call is made, they are passed as calldata along to the implementation, which reads the values from the calldata for use.

Since these values will be consistent across all clones on the same chain, it would be more gas efficient to store them in the implementation directly, which can be done with immutable storage values, set in the constructor.

This would save 40 bytes of calldata on each call to the clone, which leads to a savings of approximately 640 gas on each call.

Recommendation

  1. Add the following to LidoSplit.sol:
address immutable public stETH;
address immutable public wstETH;
  1. Add a constructor to LidoSplit.sol which sets these immutable values. Solidity treats immutable values as constants and stores them directly in the contract bytecode, so they will be accessible from the clones.

  2. Remove stETH and wstETH from LidoSplitFactory.sol, both as storage values, arguments to the constructor, and arguments to clone().

  3. Adjust the distribute() function in LidoSplit.sol to read the storage values for these two addresses, and remove the helper functions to read the clone's immutable arguments for these two values.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions