Repository navigation
Conversation
…nd OFTCore Align the state mutability of sharedDecimals() in OFTCoreUpgradeable from pure to view. In the IOFT interface, sharedDecimals() is declared as external view returns (uint8). Similarly, in all other implementations across the LayerZero V2 ecosystem (OFTCore, OFTAltCore, OFTAltCoreUpgradeable), sharedDecimals() is defined as public view virtual. Because Solidity forbids overriding a pure virtual function with a view function, declaring sharedDecimals() as pure in OFTCoreUpgradeable blocked custom upgradeable implementations from overriding sharedDecimals() to read contract state (e.g. from storage/initializer). Fixes LayerZero-Labs#1954
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Aligns the state mutability of
sharedDecimals()inOFTCoreUpgradeablefrompuretoview.Why is this change needed?
In
IOFT.sol,sharedDecimals()is declared asexternal view returns (uint8). Similarly, in all other implementations across the LayerZero V2 ecosystem:packages/oft-evm/contracts/OFTCore.sol:public view virtualpackages/oft-alt-evm/contracts/OFTAltCore.sol:public view virtualpackages/oft-alt-evm/contracts/OFTAltCoreUpgradeable.sol:public view virtualpackages/layerzero-v2/evm/oapp/contracts/oft/OFTCore.sol:public view virtualOnly
packages/oft-evm-upgradeable/contracts/oft/OFTCoreUpgradeable.soldeclaredsharedDecimals()aspure virtual.Under Solidity's function overriding rules, an overriding function can only maintain or tighten state mutability (
view->pure), but cannot loosen it (pure->view). BecauseOFTCoreUpgradeabledeclared it aspure virtual, any derived upgradeable contract wishing to overridesharedDecimals()by reading state (such as an initialized storage variable or underlying token decimals) failed compilation with:TypeError: Overriding function is missing "pure" mutability (specified in base contract).Changing
puretoviewresolves this asymmetry while remaining 100% backward compatible for all callers and existing pure overrides.Fixes #1954
How was this tested?
test_shared_decimals_view()regression test inpackages/oft-evm-upgradeable/test/OFT.t.solassertingsharedDecimals()returns expected values via view calls onOFTUpgradeableMockandOFTAdapterUpgradeableMock.@layerzerolabs/oft-evm-upgradeable.