mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change encoding to address-funid and add "function" as ABI type.
This commit is contained in:
parent
a8e7ed37a1
commit
ec31d08775
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
@ -236,7 +236,7 @@ bool ASTJsonConverter::visit(FunctionTypeName const& _node)
|
|||||||
make_pair("payable", _node.isPayable()),
|
make_pair("payable", _node.isPayable()),
|
||||||
make_pair("visibility", visibility),
|
make_pair("visibility", visibility),
|
||||||
make_pair("constant", _node.isDeclaredConst())
|
make_pair("constant", _node.isDeclaredConst())
|
||||||
});
|
}, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1930,6 +1930,12 @@ TypePointer FunctionType::unaryOperatorResult(Token::Value _operator) const
|
|||||||
return TypePointer();
|
return TypePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string FunctionType::canonicalName(bool) const
|
||||||
|
{
|
||||||
|
solAssert(m_location == Location::External, "");
|
||||||
|
return "function";
|
||||||
|
}
|
||||||
|
|
||||||
string FunctionType::toString(bool _short) const
|
string FunctionType::toString(bool _short) const
|
||||||
{
|
{
|
||||||
string name = "function (";
|
string name = "function (";
|
||||||
@ -2102,7 +2108,6 @@ TypePointer FunctionType::encodingType() const
|
|||||||
{
|
{
|
||||||
// Only external functions can be encoded, internal functions cannot leave code boundaries.
|
// Only external functions can be encoded, internal functions cannot leave code boundaries.
|
||||||
if (m_location == Location::External)
|
if (m_location == Location::External)
|
||||||
// This looks like bytes24, but bytes24 is stored differently on the stack.
|
|
||||||
return shared_from_this();
|
return shared_from_this();
|
||||||
else
|
else
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
@ -2111,7 +2116,7 @@ TypePointer FunctionType::encodingType() const
|
|||||||
TypePointer FunctionType::interfaceType(bool /*_inLibrary*/) const
|
TypePointer FunctionType::interfaceType(bool /*_inLibrary*/) const
|
||||||
{
|
{
|
||||||
if (m_location == Location::External)
|
if (m_location == Location::External)
|
||||||
return make_shared<FixedBytesType>(storageBytes());
|
return shared_from_this();
|
||||||
else
|
else
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
}
|
}
|
||||||
|
@ -897,6 +897,7 @@ public:
|
|||||||
|
|
||||||
virtual bool operator==(Type const& _other) const override;
|
virtual bool operator==(Type const& _other) const override;
|
||||||
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
|
virtual TypePointer unaryOperatorResult(Token::Value _operator) const override;
|
||||||
|
virtual std::string canonicalName(bool /*_addDataLocation*/) const override;
|
||||||
virtual std::string toString(bool _short) const override;
|
virtual std::string toString(bool _short) const override;
|
||||||
virtual unsigned calldataEncodedSize(bool _padded) const override;
|
virtual unsigned calldataEncodedSize(bool _padded) const override;
|
||||||
virtual bool canBeStored() const override { return m_location == Location::Internal || m_location == Location::External; }
|
virtual bool canBeStored() const override { return m_location == Location::Internal || m_location == Location::External; }
|
||||||
|
@ -317,27 +317,32 @@ void CompilerUtils::memoryCopy()
|
|||||||
|
|
||||||
void CompilerUtils::splitExternalFunctionType(bool _leftAligned)
|
void CompilerUtils::splitExternalFunctionType(bool _leftAligned)
|
||||||
{
|
{
|
||||||
// We have to split the left-aligned <function identifier><address> into two stack slots:
|
// We have to split the left-aligned <address><function identifier> into two stack slots:
|
||||||
// address (right aligned), function identifier (right aligned)
|
// address (right aligned), function identifier (right aligned)
|
||||||
if (_leftAligned)
|
if (_leftAligned)
|
||||||
m_context << (u256(1) << 64) << Instruction::SWAP1 << Instruction::DIV;
|
{
|
||||||
m_context << Instruction::DUP1 << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1;
|
m_context << Instruction::DUP1 << (u256(1) << (64 + 32)) << Instruction::SWAP1 << Instruction::DIV;
|
||||||
m_context << (u256(1) << 160) << Instruction::SWAP1 << Instruction::DIV;
|
// <input> <address>
|
||||||
if (!_leftAligned)
|
m_context << Instruction::SWAP1 << (u256(1) << 64) << Instruction::SWAP1 << Instruction::DIV;
|
||||||
m_context << u256(0xffffffffUL) << Instruction::AND;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_context << Instruction::DUP1 << (u256(1) << 32) << Instruction::SWAP1 << Instruction::DIV;
|
||||||
|
m_context << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1;
|
||||||
|
}
|
||||||
|
m_context << u256(0xffffffffUL) << Instruction::AND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerUtils::combineExternalFunctionType(bool _leftAligned)
|
void CompilerUtils::combineExternalFunctionType(bool _leftAligned)
|
||||||
{
|
{
|
||||||
if (_leftAligned)
|
// <address> <function_id>
|
||||||
m_context << (u256(1) << 224);
|
m_context << u256(0xffffffffUL) << Instruction::AND << Instruction::SWAP1;
|
||||||
else
|
if (!_leftAligned)
|
||||||
m_context << u256(0xffffffffUL) << Instruction::AND << (u256(1) << 160);
|
m_context << ((u256(1) << 160) - 1) << Instruction::AND;
|
||||||
m_context << Instruction::MUL << Instruction::SWAP1;
|
m_context << (u256(1) << 32) << Instruction::MUL;
|
||||||
m_context << ((u256(1) << 160) - 1) << Instruction::AND;
|
m_context << Instruction::OR;
|
||||||
if (_leftAligned)
|
if (_leftAligned)
|
||||||
m_context << (u256(1) << 64) << Instruction::MUL;
|
m_context << (u256(1) << 64) << Instruction::MUL;
|
||||||
m_context << Instruction::OR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerUtils::pushCombinedFunctionEntryLabel(Declaration const& _function)
|
void CompilerUtils::pushCombinedFunctionEntryLabel(Declaration const& _function)
|
||||||
|
@ -115,7 +115,7 @@ public:
|
|||||||
void memoryCopy();
|
void memoryCopy();
|
||||||
|
|
||||||
/// Converts the combined and left-aligned (right-aligned if @a _rightAligned is true)
|
/// Converts the combined and left-aligned (right-aligned if @a _rightAligned is true)
|
||||||
/// external function type <function identifier><address> into two stack slots:
|
/// external function type <address><function identifier> into two stack slots:
|
||||||
/// address (right aligned), function identifier (right aligned)
|
/// address (right aligned), function identifier (right aligned)
|
||||||
void splitExternalFunctionType(bool _rightAligned);
|
void splitExternalFunctionType(bool _rightAligned);
|
||||||
/// Performs the opposite operation of splitExternalFunctionType(_rightAligned)
|
/// Performs the opposite operation of splitExternalFunctionType(_rightAligned)
|
||||||
|
@ -597,7 +597,7 @@ void CompilerStack::compileContract(
|
|||||||
cloneCompiler.compileClone(_contract, _compiledContracts);
|
cloneCompiler.compileClone(_contract, _compiledContracts);
|
||||||
compiledContract.cloneObject = cloneCompiler.assembledObject();
|
compiledContract.cloneObject = cloneCompiler.assembledObject();
|
||||||
}
|
}
|
||||||
catch (eth::AssemblyException const& _e)
|
catch (eth::AssemblyException const&)
|
||||||
{
|
{
|
||||||
// In some cases (if the constructor requests a runtime function), it is not
|
// In some cases (if the constructor requests a runtime function), it is not
|
||||||
// possible to compile the clone.
|
// possible to compile the clone.
|
||||||
|
@ -7703,8 +7703,8 @@ BOOST_AUTO_TEST_CASE(receive_external_function_type)
|
|||||||
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
BOOST_CHECK(callContractFunction(
|
BOOST_CHECK(callContractFunction(
|
||||||
"f(bytes24)",
|
"f(function)",
|
||||||
FixedHash<4>(dev::keccak256("g()")).asBytes() + m_contractAddress.asBytes() + bytes(32 - 4 - 20, 0)
|
m_contractAddress.asBytes() + FixedHash<4>(dev::keccak256("g()")).asBytes() + bytes(32 - 4 - 20, 0)
|
||||||
) == encodeArgs(u256(7)));
|
) == encodeArgs(u256(7)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7722,7 +7722,7 @@ BOOST_AUTO_TEST_CASE(return_external_function_type)
|
|||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
BOOST_CHECK(
|
BOOST_CHECK(
|
||||||
callContractFunction("f()") ==
|
callContractFunction("f()") ==
|
||||||
FixedHash<4>(dev::keccak256("g()")).asBytes() + m_contractAddress.asBytes() + bytes(32 - 4 - 20, 0)
|
m_contractAddress.asBytes() + FixedHash<4>(dev::keccak256("g()")).asBytes() + bytes(32 - 4 - 20, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user