Skip to content

Commit 9d77c0f

Browse files
Warn when layout base is near the end of storage
1 parent 125b39d commit 9d77c0f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libsolidity/analysis/PostTypeContractLevelChecker.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio
136136
solAssert(baseSlotExpressionType->isImplicitlyConvertibleTo(*TypeProvider::uint256()));
137137
storageLayoutSpecifier->annotation().baseSlot = u256(baseSlot);
138138

139+
if (
140+
u256 slotsLeft = std::numeric_limits<u256>::max() - *storageLayoutSpecifier->annotation().baseSlot;
141+
slotsLeft <= u256(1) << 64
142+
)
143+
m_errorReporter.warning(
144+
3495_error,
145+
storageLayoutSpecifier->baseSlotExpression().location(),
146+
fmt::format(
147+
"There are {} slots before the end of the contract storage when this specified base layout is used.",
148+
formatNumberReadable(slotsLeft)
149+
));
150+
139151
bigint size = contractStorageSizeUpperBound(_contract, VariableDeclaration::Location::Unspecified);
140152
solAssert(size < bigint(1) << 256);
141153
if (baseSlot + size >= bigint(1) << 256)

0 commit comments

Comments
 (0)