diff options
author | chriseth <chris@ethereum.org> | 2018-04-06 21:14:55 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-04-12 19:09:38 +0800 |
commit | 4faa839813ce76fc87f99b002aad6cadd2b784e1 (patch) | |
tree | c461378847bc2ad15f0cc85fc2100a26b9ee9902 /libsolidity/codegen | |
parent | 338a875134f2e41e9a7e254cc3f7d87c7f4d462e (diff) | |
download | dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.tar dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.tar.gz dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.tar.bz2 dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.tar.lz dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.tar.xz dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.tar.zst dexon-solidity-4faa839813ce76fc87f99b002aad6cadd2b784e1.zip |
Use error signature for revert data.
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 14 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerUtils.h | 7 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 23 |
3 files changed, 24 insertions, 20 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 34337d7d..b4550153 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -78,6 +78,20 @@ void CompilerUtils::toSizeAfterFreeMemoryPointer() m_context << Instruction::SWAP1; } +void CompilerUtils::revertWithStringData(Type const& _argumentType) +{ + solAssert(_argumentType.isImplicitlyConvertibleTo(*Type::fromElementaryTypeName("string memory")), ""); + fetchFreeMemoryPointer(); + m_context << (u256(FixedHash<4>::Arith(FixedHash<4>(dev::keccak256("Error(string)")))) << (256 - 32)); + m_context << Instruction::DUP2 << Instruction::MSTORE; + m_context << u256(4) << Instruction::ADD; + // Stack: <string data> <mem pos of encoding start> + abiEncode({_argumentType.shared_from_this()}, {make_shared<ArrayType>(DataLocation::Memory, true)}); + toSizeAfterFreeMemoryPointer(); + m_context << Instruction::REVERT; + m_context.adjustStackOffset(_argumentType.sizeOnStack()); +} + unsigned CompilerUtils::loadFromMemory( unsigned _offset, Type const& _type, diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h index a32c5c6e..476a7559 100644 --- a/libsolidity/codegen/CompilerUtils.h +++ b/libsolidity/codegen/CompilerUtils.h @@ -54,6 +54,13 @@ public: /// Stack post: <size> <mem_start> void toSizeAfterFreeMemoryPointer(); + /// Appends code that performs a revert, providing the given string data. + /// Will also append an error signature corresponding to Error(string). + /// @param _argumentType the type of the string argument, will be converted to memory string. + /// Stack pre: string data + /// Stack post: + void revertWithStringData(Type const& _argumentType); + /// Loads data from memory to the stack. /// @param _offset offset in memory (or calldata) /// @param _type data type to load diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3f521f2d..b67e7b68 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -685,17 +685,11 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) { if (!arguments.empty()) { + // function-sel(Error(string)) + encoding solAssert(arguments.size() == 1, ""); solAssert(function.parameterTypes().size() == 1, ""); - m_context << u256(0); arguments.front()->accept(*this); - utils().fetchFreeMemoryPointer(); - utils().abiEncode( - {make_shared<IntegerType>(256), arguments.front()->annotation().type}, - {make_shared<IntegerType>(256), make_shared<ArrayType>(DataLocation::Memory, true)} - ); - utils().toSizeAfterFreeMemoryPointer(); - m_context << Instruction::REVERT; + utils().revertWithStringData(*arguments.front()->annotation().type); } else m_context.appendRevert(); @@ -937,18 +931,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // condition was not met, flag an error m_context.appendInvalid(); else if (arguments.size() > 1) - { - m_context << u256(0); - utils().moveIntoStack(arguments.at(1)->annotation().type->sizeOnStack(), 1); - utils().fetchFreeMemoryPointer(); - utils().abiEncode( - {make_shared<IntegerType>(256), arguments.at(1)->annotation().type}, - {make_shared<IntegerType>(256), make_shared<ArrayType>(DataLocation::Memory, true)} - ); - utils().toSizeAfterFreeMemoryPointer(); - m_context << Instruction::REVERT; - m_context.adjustStackOffset(arguments.at(1)->annotation().type->sizeOnStack()); - } + utils().revertWithStringData(*arguments.at(1)->annotation().type); else m_context.appendRevert(); // the success branch |