Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.8.35 (unreleased)

Language Features:
* Custom Storage Layout: Allow signed positive expressions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this up to maintain alphabetical ordering.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, fixed!

* General: Add a builtin that computes the base slot of a storage namespace using the `erc7201` formula from ERC-7201.

Compiler Features:
Expand Down
12 changes: 0 additions & 12 deletions libsolidity/analysis/PostTypeContractLevelChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,6 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio
return;
}

if (!baseSlotExpressionType->isImplicitlyConvertibleTo(*TypeProvider::uint256()))
{
m_errorReporter.typeError(
1481_error,
baseSlotExpression.location(),
fmt::format(
"Base slot expression of type '{}' is not convertible to uint256.",
baseSlotExpressionType->humanReadableName()
)
);
return;
}
storageLayoutSpecifier->annotation().baseSlot = u256(baseSlot);

bigint size = contractStorageSizeUpperBound(_contract, VariableDeclaration::Location::Unspecified);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
int constant INT256 = -42;
int8 constant INT8 = -64;
int constant EXPRESSION = INT256 * 2;
int constant COMPLEX = EXPRESSION * -2 + EXPRESSION * 4;
contract A layout at INT256 {}
contract B layout at INT8 {}
contract C layout at EXPRESSION {}
contract D layout at COMPLEX {}
// ----
// TypeError 6753: (169-175): The base slot of the storage layout evaluates to -42, which is outside the range of type uint256.
// TypeError 6753: (200-204): The base slot of the storage layout evaluates to -64, which is outside the range of type uint256.
// TypeError 6753: (229-239): The base slot of the storage layout evaluates to -84, which is outside the range of type uint256.
// TypeError 6753: (264-271): The base slot of the storage layout evaluates to -168, which is outside the range of type uint256.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to add some max values in here, e.g. int constant x = type(int).max, although I assume we already have them around somewhere (likely in the initial implementation of the storage layout specifiers).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, just checked and type(<type>).max is not supported by the constant expression evaluator at the moment :D

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int constant x = 42;
int16 constant y = 64;
contract C layout at x {}
contract D layout at y {}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int constant SIGNED2 = 2;
int constant SIGNED2_NEGATIVE = -2;
uint constant UNSIGNED2 = 2;

contract A layout at SIGNED2 * 1 {}
contract B layout at SIGNED2_NEGATIVE * -1 {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the opposite covered somewhere, i.e. where a 'complex' expression evaluates to a negative number, e.g. SIGNED2_NEGATIVE * 1? Although int_const_negative.sol would be a better place for such a test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to int_constant_negative.sol.

contract C layout at SIGNED2_NEGATIVE * SIGNED2_NEGATIVE {}
contract D layout at 2 * -1 * -1 {}
contract E layout at 2 * SIGNED2 {}
contract F layout at 2 * -1 * SIGNED2_NEGATIVE {}
// ----