aboutsummaryrefslogtreecommitdiffstats
path: root/ExpressionCompiler.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-04-22 02:09:20 +0800
committerchriseth <c@ethdev.com>2015-04-22 17:43:50 +0800
commita3820fa0468ebe63b858a85a81eae38b0ec11cdd (patch)
treef348dfbbd05f56472d57325c5f742a4de45d98f3 /ExpressionCompiler.cpp
parenta6d08950c6a81de3698ea8be01d2d5c472fe41e6 (diff)
downloaddexon-solidity-a3820fa0468ebe63b858a85a81eae38b0ec11cdd.tar.gz
dexon-solidity-a3820fa0468ebe63b858a85a81eae38b0ec11cdd.tar.zst
dexon-solidity-a3820fa0468ebe63b858a85a81eae38b0ec11cdd.zip
Fix regarding memory overwrite during sha3 computation.
Diffstat (limited to 'ExpressionCompiler.cpp')
-rw-r--r--ExpressionCompiler.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index a11c9944..8c07fbd1 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -531,9 +531,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
break;
case Location::SHA3:
{
- m_context << u256(0);
+ // we might compute a sha as part of argumentsAppendCopyToMemory, this is only a hack
+ // and should be removed once we have a real free memory pointer
+ m_context << u256(0x40);
appendArgumentsCopyToMemory(arguments, TypePointers(), function.padArguments(), false, true);
- m_context << u256(0) << eth::Instruction::SHA3;
+ m_context << u256(0x40) << eth::Instruction::SWAP1 << eth::Instruction::SUB;
+ m_context << u256(0x40) << eth::Instruction::SHA3;
break;
}
case Location::Log0:
@@ -574,7 +577,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
}
solAssert(numIndexed <= 4, "Too many indexed arguments.");
// Copy all non-indexed arguments to memory (data)
- m_context << u256(0);
+ // Memory position is only a hack and should be removed once we have free memory pointer.
+ m_context << u256(0x40);
vector<ASTPointer<Expression const>> nonIndexedArgs;
TypePointers nonIndexedTypes;
for (unsigned arg = 0; arg < arguments.size(); ++arg)
@@ -584,7 +588,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
nonIndexedTypes.push_back(function.getParameterTypes()[arg]);
}
appendArgumentsCopyToMemory(nonIndexedArgs, nonIndexedTypes);
- m_context << u256(0) << eth::logInstruction(numIndexed);
+ m_context << u256(0x40) << eth::Instruction::SWAP1 << eth::Instruction::SUB;
+ m_context << u256(0x40) << eth::logInstruction(numIndexed);
break;
}
case Location::BlockHash: