Uniswap / v4-core

🦄 🦄 🦄 🦄 Core smart contracts of Uniswap v4
https://blog.uniswap.org/uniswap-v4
2.03k stars 979 forks source link

Intent to Implement: Remove Multimappings #849

Closed wjmelements closed 3 months ago

wjmelements commented 3 months ago

Component

Gas Optimization

Describe the suggested feature and problem it solves.

Multi-level mappings in solidity are implemented with recursive keccak. This means that each level is another hash. This is fine in situations like Pool where the intermediate storage key is useful. It is wasteful in erc20 and erc6909.

Describe the desired implementation.

I'm going to write storage key functions for the erc6909 multimappings. These storage keys will then be accessed with sload and sstore.

Describe alternatives.

No response

Additional context.

Experimentally for erc20, replacing multimappings with a single keccak can save a few hundred gas for approve and transferFrom.

linear[bot] commented 3 months ago

PROTO-508 Intent to Implement: Remove Multimappings

wjmelements commented 3 months ago

As with #752, the savings should be even larger after they increase the sha3 gas.

wjmelements commented 3 months ago

My first attempt demonstrates that it is currently slightly worse (though this could change after 7667). Gonna tinker with it a bit before abandoning the branch.

wjmelements commented 3 months ago

My current theory is that the recursive advantage is from the mapping's ability to use the "scratch space".

wjmelements commented 3 months ago

Abandoning this. My WIP branch is here.