Skip to content

Commit

Permalink
Warn when layout base is near the end of storage
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusaaguiar committed Mar 4, 2025
1 parent 125b39d commit 9d77c0f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libsolidity/analysis/PostTypeContractLevelChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio
solAssert(baseSlotExpressionType->isImplicitlyConvertibleTo(*TypeProvider::uint256()));
storageLayoutSpecifier->annotation().baseSlot = u256(baseSlot);

if (
u256 slotsLeft = std::numeric_limits<u256>::max() - *storageLayoutSpecifier->annotation().baseSlot;
slotsLeft <= u256(1) << 64
)
m_errorReporter.warning(
3495_error,
storageLayoutSpecifier->baseSlotExpression().location(),
fmt::format(
"There are {} slots before the end of the contract storage when this specified base layout is used.",
formatNumberReadable(slotsLeft)
));

bigint size = contractStorageSizeUpperBound(_contract, VariableDeclaration::Location::Unspecified);
solAssert(size < bigint(1) << 256);
if (baseSlot + size >= bigint(1) << 256)
Expand Down

0 comments on commit 9d77c0f

Please sign in to comment.