mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
add new opcode instructions to the parser
STATICCALL 0xfa 6 inputs (gas address mem1 mem2 mem3 mem4)
This commit is contained in:
parent
d693822a6f
commit
c20cdd0a05
@ -2,7 +2,7 @@
|
||||
|
||||
Features:
|
||||
* Assembly: renamed ``SHA3`` to ``KECCAK256``.
|
||||
* Assembly: Add ``CREATE2`` (EIP86), ``RETURNDATASIZE`` and ``RETURNDATACOPY`` (EIP211) instructions.
|
||||
* Assembly: Add ``CREATE2`` (EIP86), ``STATICCALL`` (EIP214), ``RETURNDATASIZE`` and ``RETURNDATACOPY`` (EIP211) instructions.
|
||||
* AST: export all attributes to JSON format.
|
||||
* Inline Assembly: Present proper error message when not supplying enough arguments to a functional
|
||||
instruction.
|
||||
|
@ -236,11 +236,15 @@ In the grammar, opcodes are represented as pre-defined identifiers.
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| returndatasize | | size of the last returndata |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| returndatacopy(t, f, s) | `*` | copy s bytes from returndata at position f to mem at position t |
|
||||
| returndatacopy(t, f, s) | `-` | copy s bytes from returndata at position f to mem at position t |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| create(v, p, s) | | create new contract with code mem[p..(p+s)) and send v wei |
|
||||
| | | and return the new address |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| create2(v, n, p, s) | | create new contract with code mem[p..(p+s)) at address |
|
||||
| | | keccak256(<address> . n . keccak256(mem[p..(p+s))) and send v |
|
||||
| | | wei and return the new address |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| call(g, a, v, in, | | call contract at address a with input mem[in..(in+insize)) |
|
||||
| insize, out, outsize) | | providing g gas and v wei and output area |
|
||||
| | | mem[out..(out+outsize)) returning 0 on error (eg. out of gas) |
|
||||
@ -252,6 +256,9 @@ In the grammar, opcodes are represented as pre-defined identifiers.
|
||||
| delegatecall(g, a, in, | | identical to `callcode` but also keep ``caller`` |
|
||||
| insize, out, outsize) | | and ``callvalue`` |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| staticcall(g, a, in, | | identical to `call(g, a, 0, in, insize, out, outsize)` but do |
|
||||
| insize, out, outsize) | | not allow state modifications |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| return(p, s) | `-` | end execution, return data mem[p..(p+s)) |
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| revert(p, s) | `-` | end execution, revert state changes, return data mem[p..(p+s)) |
|
||||
|
@ -129,6 +129,7 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
|
||||
case Instruction::CALL:
|
||||
case Instruction::CALLCODE:
|
||||
case Instruction::DELEGATECALL:
|
||||
case Instruction::STATICCALL:
|
||||
{
|
||||
if (_includeExternalCosts)
|
||||
// We assume that we do not know the target contract and thus, the consumption is infinite.
|
||||
@ -142,8 +143,10 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
|
||||
gas = GasConsumption::infinite();
|
||||
if (_item.instruction() == Instruction::CALL)
|
||||
gas += GasCosts::callNewAccountGas; // We very rarely know whether the address exists.
|
||||
int valueSize = _item.instruction() == Instruction::DELEGATECALL ? 0 : 1;
|
||||
if (!classes.knownZero(m_state->relativeStackElement(-1 - valueSize)))
|
||||
int valueSize = 1;
|
||||
if (_item.instruction() == Instruction::DELEGATECALL || _item.instruction() == Instruction::STATICCALL)
|
||||
valueSize = 0;
|
||||
else if (!classes.knownZero(m_state->relativeStackElement(-1 - valueSize)))
|
||||
gas += GasCosts::callValueTransferGas;
|
||||
gas += memoryGas(-2 - valueSize, -3 - valueSize);
|
||||
gas += memoryGas(-4 - valueSize, -5 - valueSize);
|
||||
|
@ -159,6 +159,7 @@ const std::map<std::string, Instruction> dev::solidity::c_instructions =
|
||||
{ "CREATE", Instruction::CREATE },
|
||||
{ "CALL", Instruction::CALL },
|
||||
{ "CALLCODE", Instruction::CALLCODE },
|
||||
{ "STATICCALL", Instruction::STATICCALL },
|
||||
{ "RETURN", Instruction::RETURN },
|
||||
{ "DELEGATECALL", Instruction::DELEGATECALL },
|
||||
{ "CREATE2", Instruction::CREATE2 },
|
||||
@ -300,6 +301,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
|
||||
{ Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } },
|
||||
{ Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } },
|
||||
{ Instruction::DELEGATECALL, { "DELEGATECALL", 0, 6, 1, true, Tier::Special } },
|
||||
{ Instruction::STATICCALL, { "STATICCALL", 0, 6, 1, true, Tier::Special } },
|
||||
{ Instruction::CREATE2, { "CREATE2", 0, 4, 1, true, Tier::Special } },
|
||||
{ Instruction::REVERT, { "REVERT", 0, 2, 0, true, Tier::Zero } },
|
||||
{ Instruction::INVALID, { "INVALID", 0, 0, 0, true, Tier::Zero } },
|
||||
|
@ -77,8 +77,8 @@ enum class Instruction: uint8_t
|
||||
GASPRICE, ///< get price of gas in current environment
|
||||
EXTCODESIZE, ///< get external code size (from another contract)
|
||||
EXTCODECOPY, ///< copy external code (from another contract)
|
||||
RETURNDATASIZE, ///< get size of the last return data
|
||||
RETURNDATACOPY, ///< copy last return data to memory
|
||||
RETURNDATASIZE = 0x3d, ///< get size of return data buffer
|
||||
RETURNDATACOPY = 0x3e, ///< copy return data in current environment to memory
|
||||
|
||||
BLOCKHASH = 0x40, ///< get hash of most recent complete block
|
||||
COINBASE, ///< get the block's coinbase address
|
||||
@ -187,7 +187,8 @@ enum class Instruction: uint8_t
|
||||
CALLCODE, ///< message-call with another account's code only
|
||||
RETURN, ///< halt execution returning output data
|
||||
DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender
|
||||
CREATE2 = 0xfb, ///< create new account with associated code
|
||||
STATICCALL = 0xfa, ///< like CALL but disallow state modifications
|
||||
CREATE2 = 0xfb, ///< create new account with associated code at address `sha3(sender + salt + sha3(init code)) % 2**160`
|
||||
|
||||
REVERT = 0xfd, ///< halt execution, revert state and return output data
|
||||
INVALID = 0xfe, ///< invalid instruction for expressing runtime errors (e.g., division-by-zero)
|
||||
|
@ -137,6 +137,7 @@ bool SemanticInformation::isDeterministic(AssemblyItem const& _item)
|
||||
case Instruction::CALL:
|
||||
case Instruction::CALLCODE:
|
||||
case Instruction::DELEGATECALL:
|
||||
case Instruction::STATICCALL:
|
||||
case Instruction::CREATE:
|
||||
case Instruction::CREATE2:
|
||||
case Instruction::GAS:
|
||||
@ -165,6 +166,7 @@ bool SemanticInformation::invalidatesMemory(Instruction _instruction)
|
||||
case Instruction::CALL:
|
||||
case Instruction::CALLCODE:
|
||||
case Instruction::DELEGATECALL:
|
||||
case Instruction::STATICCALL:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <libsolidity/interface/Utils.h>
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
@ -447,25 +448,18 @@ void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _loc
|
||||
|
||||
void AsmAnalyzer::warnOnFutureInstruction(solidity::Instruction _instr, SourceLocation const& _location)
|
||||
{
|
||||
string instr;
|
||||
switch (_instr)
|
||||
{
|
||||
case solidity::Instruction::CREATE2:
|
||||
instr = "create2";
|
||||
break;
|
||||
case solidity::Instruction::RETURNDATASIZE:
|
||||
instr = "returndatasize";
|
||||
break;
|
||||
case solidity::Instruction::RETURNDATACOPY:
|
||||
instr = "returndatacopy";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!instr.empty())
|
||||
static set<solidity::Instruction> futureInstructions{
|
||||
solidity::Instruction::CREATE2,
|
||||
solidity::Instruction::RETURNDATACOPY,
|
||||
solidity::Instruction::RETURNDATASIZE,
|
||||
solidity::Instruction::STATICCALL
|
||||
};
|
||||
if (futureInstructions.count(_instr))
|
||||
m_errorReporter.warning(
|
||||
_location,
|
||||
"The \"" + instr + "\" instruction is only available after " +
|
||||
"The \"" +
|
||||
boost::to_lower_copy(instructionInfo(_instr).name)
|
||||
+ "\" instruction is only available after " +
|
||||
"the Metropolis hard fork. Before that it acts as an invalid instruction."
|
||||
);
|
||||
}
|
||||
|
@ -562,6 +562,16 @@ BOOST_AUTO_TEST_CASE(returndatacopy_functional)
|
||||
BOOST_CHECK(successAssemble("{ returndatacopy(0, 32, 64) }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(staticcall)
|
||||
{
|
||||
BOOST_CHECK(successAssemble("{ pop(staticcall(10000, 0x123, 64, 0x10, 128, 0x10)) }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(create2)
|
||||
{
|
||||
BOOST_CHECK(successAssemble("{ pop(create2(10, 0x123, 32, 64)) }"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user