Merge pull request #12050 from ethereum/signedImmutablesBug

Fix signed immutables bug.
This commit is contained in:
chriseth
2021-09-29 11:46:58 +02:00
committed by GitHub
8 changed files with 96 additions and 17 deletions
+3 -3
View File
@@ -95,9 +95,9 @@ public:
/// @returns the number of bytes consumed in memory.
unsigned loadFromMemory(
unsigned _offset,
Type const& _type = *TypeProvider::uint256(),
bool _fromCalldata = false,
bool _padToWords = false
Type const& _type,
bool _fromCalldata,
bool _padToWords
);
/// Dynamic version of @see loadFromMemory, expects the memory offset on the stack.
/// Stack pre: memory_offset
+7 -2
View File
@@ -192,7 +192,12 @@ size_t ContractCompiler::packIntoContractCreator(ContractDefinition const& _cont
auto const& immutables = contractType.immutableVariables();
// Push all immutable values on the stack.
for (auto const& immutable: immutables)
CompilerUtils(m_context).loadFromMemory(static_cast<unsigned>(m_context.immutableMemoryOffset(*immutable)), *immutable->annotation().type);
CompilerUtils(m_context).loadFromMemory(
static_cast<unsigned>(m_context.immutableMemoryOffset(*immutable)),
*immutable->annotation().type,
false,
true
);
m_context.pushSubroutineSize(m_context.runtimeSub());
if (immutables.empty())
m_context << Instruction::DUP1;
@@ -439,7 +444,7 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
// retrieve the function signature hash from the calldata
if (!interfaceFunctions.empty())
{
CompilerUtils(m_context).loadFromMemory(0, IntegerType(CompilerUtils::dataStartOffset * 8), true);
CompilerUtils(m_context).loadFromMemory(0, IntegerType(CompilerUtils::dataStartOffset * 8), true, false);
// stack now is: <can-call-non-view-functions>? <funhash>
vector<FixedHash<4>> sortedIDs;
+4 -2
View File
@@ -159,7 +159,9 @@ void ImmutableItem::retrieveValue(SourceLocation const&, bool) const
if (m_context.runtimeContext())
CompilerUtils(m_context).loadFromMemory(
static_cast<unsigned>(m_context.immutableMemoryOffset(m_variable)),
*m_dataType
*m_dataType,
false,
true
);
else
for (auto&& slotName: m_context.immutableVariableSlotNames(m_variable))
@@ -178,7 +180,7 @@ void ImmutableItem::storeValue(Type const& _sourceType, SourceLocation const&, b
utils.moveIntoStack(m_dataType->sizeOnStack());
else
utils.copyToStackTop(m_dataType->sizeOnStack() + 1, m_dataType->sizeOnStack());
utils.storeInMemoryDynamic(*m_dataType, false);
utils.storeInMemoryDynamic(*m_dataType);
m_context << Instruction::POP;
}