Skip to content

Comments

feat: deposit_v4 with cheaper depositTopUp#29

Closed
86667 wants to merge 1 commit intomainfrom
1991-spread-gas-cost-across-deposit-topups
Closed

feat: deposit_v4 with cheaper depositTopUp#29
86667 wants to merge 1 commit intomainfrom
1991-spread-gas-cost-across-deposit-topups

Conversation

@86667
Copy link

@86667 86667 commented Jan 6, 2025

Reduce the work done by updateLatestComputedEpoch() to minimise gas cost of depositTopUp().

To view diff with deposit_v3 eg:

diff ~/zq2/zilliqa/src/contracts/deposit_v3.sol ~/delegated_staking/test/deposit-development/deposit_v4.sol 

Results

Gas costs before:

1st top up owner 1: Gas used 341943
1st top up owner 2: Gas used 16149

Rolling ahead 1 epoch
2nd top up owner 1: Gas used 111502
2nd top up owner 2: Gas used 16149

Rolling ahead a 2 epochs
3rd top up owner 1: Gas used 205615
3rd top up owner 2: Gas used 16158

After:

1st top up owner 1: Gas used 262857
1st top up owner 2: Gas used 16149

Rolling ahead 1 epoch
2nd top up owner 1: Gas used 27168
2nd top up owner 2: Gas used 16149

Rolling ahead a 2 epochs
3rd top up owner 1: Gas used 36947
3rd top up owner 2: Gas used 16158

Showing that it costs ~120_000 gas per new key added and is charged to whoever is first to call deposit(), unstake() or depositTopUp() AFTER a deposit is made and one epoch has passed. If 2 or more epochs pass and none of those fns are called, then the next to call them must pay to write the new key into 2 committees, meaning a cost of ~240_000 gas.

Outstanding TODO

First TopUp pays for writing of stakerKeys for inititial deposits.

@86667
Copy link
Author

86667 commented Jan 7, 2025

Moved changes to zq2 repo - Zilliqa/zq2#2102

@86667 86667 closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant