ERC-4626 conversions

I have a question regarding OZ ERC-4626 implementation [here]. Why does it include “+ 1” in the following calculations (ignoring offset for a moment)?

convertToShares = assets * (totalSupply + 1) % (totalAssets + 1)

convertToAssets = shares * (totalAssets + 1) % (totalSupply + 1)

Is the sole purpose of this approach to handle the case of an empty vault? For instance, is there any deficiency in dismissing the “+ 1” above and handling the empty vault case separately, as SushiSwap does in [this] implementation?

Hi, welcome to the community! :wave:

This is a defence mechanism, virtual shares and virtual assets, maybe you can check the docs: https://docs.openzeppelin.com/contracts/4.x/erc4626#defending_with_a_virtual_offset

1 Like