aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Compiler.cpp22
-rw-r--r--CompilerUtils.cpp13
-rw-r--r--CompilerUtils.h16
3 files changed, 28 insertions, 23 deletions
diff --git a/Compiler.cpp b/Compiler.cpp
index 47729964..b05a7a9b 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -165,10 +165,26 @@ void Compiler::appendConstructor(FunctionDefinition const& _constructor)
// copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
if (!_constructor.getParameters().empty())
{
+ unsigned argumentSize = 0;
+ for (ASTPointer<VariableDeclaration> const& var: _constructor.getParameters())
+ if (var->getType()->isDynamicallySized())
+ {
+ argumentSize = 0;
+ break;
+ }
+ else
+ argumentSize += var->getType()->getCalldataEncodedSize();
+
CompilerUtils(m_context).fetchFreeMemoryPointer();
- m_context.appendProgramSize(); // program itself
- // CODESIZE is program plus manually added arguments
- m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB;
+ if (argumentSize == 0)
+ {
+ // argument size is dynamic, use CODESIZE to determine it
+ m_context.appendProgramSize(); // program itself
+ // CODESIZE is program plus manually added arguments
+ m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB;
+ }
+ else
+ m_context << u256(argumentSize);
// stack: <memptr> <argument size>
m_context << eth::Instruction::DUP1;
m_context.appendProgramSize();
diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp
index baddbb12..47a9a354 100644
--- a/CompilerUtils.cpp
+++ b/CompilerUtils.cpp
@@ -92,13 +92,11 @@ void CompilerUtils::loadFromMemoryDynamic(
}
}
-unsigned CompilerUtils::storeInMemory(unsigned _offset, Type const& _type, bool _padToWordBoundaries)
+void CompilerUtils::storeInMemory(unsigned _offset)
{
- solAssert(_type.getCategory() != Type::Category::Array, "Unable to statically store dynamic type.");
- unsigned numBytes = prepareMemoryStore(_type, _padToWordBoundaries);
+ unsigned numBytes = prepareMemoryStore(IntegerType(256), true);
if (numBytes > 0)
m_context << u256(_offset) << eth::Instruction::MSTORE;
- return numBytes;
}
void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBoundaries)
@@ -502,11 +500,10 @@ unsigned CompilerUtils::getSizeOnStack(vector<shared_ptr<Type const>> const& _va
return size;
}
-void CompilerUtils::computeHashStatic(Type const& _type, bool _padToWordBoundaries)
+void CompilerUtils::computeHashStatic()
{
- unsigned length = storeInMemory(0, _type, _padToWordBoundaries);
- solAssert(length <= CompilerUtils::freeMemoryPointer, "");
- m_context << u256(length) << u256(0) << eth::Instruction::SHA3;
+ storeInMemory(0);
+ m_context << u256(32) << u256(0) << eth::Instruction::SHA3;
}
unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCalldata, bool _padToWordBoundaries)
diff --git a/CompilerUtils.h b/CompilerUtils.h
index ac70088b..a9e07f74 100644
--- a/CompilerUtils.h
+++ b/CompilerUtils.h
@@ -65,16 +65,10 @@ public:
bool _padToWordBoundaries = true,
bool _keepUpdatedMemoryOffset = true
);
- /// Stores data from stack in memory.
+ /// Stores a 256 bit integer from stack in memory.
/// @param _offset offset in memory
/// @param _type type of the data on the stack
- /// @param _padToWordBoundaries if true, pad the data to word (32 byte) boundaries
- /// @returns the number of bytes written to memory (can be different from _bytes if
- /// _padToWordBoundaries is true)
- unsigned storeInMemory(unsigned _offset,
- Type const& _type = IntegerType(256),
- bool _padToWordBoundaries = false
- );
+ void storeInMemory(unsigned _offset);
/// Dynamic version of @see storeInMemory, expects the memory offset below the value on the stack
/// and also updates that. For arrays, only copies the data part.
/// @param _padToWordBoundaries if true, adds zeros to pad to multiple of 32 bytes. Array elements
@@ -131,10 +125,8 @@ public:
static unsigned getSizeOnStack(std::vector<T> const& _variables);
static unsigned getSizeOnStack(std::vector<std::shared_ptr<Type const>> const& _variableTypes);
- /// Appends code that computes tha SHA3 hash of the topmost stack element of type @a _type.
- /// If @a _pad is set, padds the type to muliples of 32 bytes.
- /// @note Only works for types of fixed size.
- void computeHashStatic(Type const& _type = IntegerType(256), bool _padToWordBoundaries = false);
+ /// Appends code that computes tha SHA3 hash of the topmost stack element of 32 byte type.
+ void computeHashStatic();
/// Bytes we need to the start of call data.
/// - The size in bytes of the function (hash) identifier.