SWC-119_Shadowing State Variables
Shadowing State Variables
Description: Solidity allows for ambiguous naming of state variables when inheritance is used. Contract
A
with a variablex
could inherit contractB
that also has a state variablex
defined. This would result in two separate versions ofx
, one of them being accessed from contractA
and the other one from contractB
. In more complex contract systems this condition could go unnoticed and subsequently lead to security issues.Shadowing state variables can also occur within a single contract when there are multiple definitions on the contract and function level.
Remediation: Review storage variable layouts for your contract systems carefully and remove any ambiguities. Always check for compiler warnings as they can flag the issue within a single contract.
vulnerability contract 1:
1 | pragma solidity 0.4.24; |
vulnerability contract 2:
1 | pragma solidity 0.4.24; |