mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Review comments.
This commit is contained in:
parent
5eb155b894
commit
0e471ab811
@ -3,7 +3,6 @@ set(sources
|
|||||||
EVMInstructionInterpreter.cpp
|
EVMInstructionInterpreter.cpp
|
||||||
Interpreter.h
|
Interpreter.h
|
||||||
Interpreter.cpp
|
Interpreter.cpp
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(yulInterpreter ${sources})
|
add_library(yulInterpreter ${sources})
|
||||||
|
@ -50,6 +50,9 @@ u256 exp256(u256 _base, u256 _exponent)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reads 32 bytes from @a _data at position @a _offset bytes while
|
||||||
|
/// interpreting @a _data to be padded with an infinite number of zero
|
||||||
|
/// bytes beyond its end.
|
||||||
u256 readZeroExtended(bytes const& _data, u256 const& _offset)
|
u256 readZeroExtended(bytes const& _data, u256 const& _offset)
|
||||||
{
|
{
|
||||||
if (_offset >= _data.size())
|
if (_offset >= _data.size())
|
||||||
@ -70,6 +73,10 @@ u256 readZeroExtended(bytes const& _data, u256 const& _offset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Copy @a _size bytes of @a _source at offset @a _sourceOffset to
|
||||||
|
/// @a _target at offset @a _targetOffset. Behaves as if @a _source would
|
||||||
|
/// continue with an infinite sequence of zero bytes beyond its end.
|
||||||
|
/// Asserts the target is large enough to hold the copied segment.
|
||||||
void copyZeroExtended(
|
void copyZeroExtended(
|
||||||
bytes& _target, bytes const& _source,
|
bytes& _target, bytes const& _source,
|
||||||
size_t _targetOffset, size_t _sourceOffset, size_t _size
|
size_t _targetOffset, size_t _sourceOffset, size_t _size
|
||||||
@ -137,11 +144,11 @@ u256 EVMInstructionInterpreter::eval(
|
|||||||
case Instruction::XOR:
|
case Instruction::XOR:
|
||||||
return arg[0] ^ arg[1];
|
return arg[0] ^ arg[1];
|
||||||
case Instruction::BYTE:
|
case Instruction::BYTE:
|
||||||
return arg[0] >= 32 ? 0 : (arg[1] >> unsigned(8 * (31 - (arg[0] & 0xff)))) & 0xff;
|
return arg[0] >= 32 ? 0 : (arg[1] >> unsigned(8 * (31 - arg[0]))) & 0xff;
|
||||||
case Instruction::SHL:
|
case Instruction::SHL:
|
||||||
return arg[0] > 255 ? 0 : (arg[1] << unsigned(arg[0] & 0xff));
|
return arg[0] > 255 ? 0 : (arg[1] << unsigned(arg[0]));
|
||||||
case Instruction::SHR:
|
case Instruction::SHR:
|
||||||
return arg[0] > 255 ? 0 : (arg[1] >> unsigned(arg[0] & 0xff));
|
return arg[0] > 255 ? 0 : (arg[1] >> unsigned(arg[0]));
|
||||||
case Instruction::SAR:
|
case Instruction::SAR:
|
||||||
{
|
{
|
||||||
static u256 const hibit = u256(1) << 255;
|
static u256 const hibit = u256(1) << 255;
|
||||||
@ -149,7 +156,7 @@ u256 EVMInstructionInterpreter::eval(
|
|||||||
return arg[1] & hibit ? u256(-1) : 0;
|
return arg[1] & hibit ? u256(-1) : 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned amount = unsigned(arg[0] & 0xff);
|
unsigned amount = unsigned(arg[0]);
|
||||||
u256 v = arg[1] >> amount;
|
u256 v = arg[1] >> amount;
|
||||||
if (arg[1] & hibit)
|
if (arg[1] & hibit)
|
||||||
v |= u256(-1) << (256 - amount);
|
v |= u256(-1) << (256 - amount);
|
||||||
@ -165,7 +172,7 @@ u256 EVMInstructionInterpreter::eval(
|
|||||||
return arg[0];
|
return arg[0];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned testBit = unsigned(arg[0] & 0xff) * 8 + 7;
|
unsigned testBit = unsigned(arg[0]) * 8 + 7;
|
||||||
u256 ret = arg[1];
|
u256 ret = arg[1];
|
||||||
u256 mask = ((u256(1) << testBit) - 1);
|
u256 mask = ((u256(1) << testBit) - 1);
|
||||||
if (boost::multiprecision::bit_test(ret, testBit))
|
if (boost::multiprecision::bit_test(ret, testBit))
|
||||||
|
@ -45,9 +45,9 @@ struct InterpreterState;
|
|||||||
* Interprets EVM instructions based on the current state and logs instructions with
|
* Interprets EVM instructions based on the current state and logs instructions with
|
||||||
* side-effects.
|
* side-effects.
|
||||||
*
|
*
|
||||||
* Since this is mainly meant to be used for testing, it is focused on a single
|
* Since this is mainly meant to be used for differential fuzz testing, it is focused
|
||||||
* contract only, does not do any gas counting and differs from the correct
|
* on a single contract only, does not do any gas counting and differs from the correct
|
||||||
* implementation in the following ways:
|
* implementation in many ways:
|
||||||
*
|
*
|
||||||
* - If memory access to a "large" memory position is performed, a deterministic
|
* - If memory access to a "large" memory position is performed, a deterministic
|
||||||
* value is returned. Data that is stored in a "large" memory position is not
|
* value is returned. Data that is stored in a "large" memory position is not
|
||||||
@ -56,8 +56,9 @@ struct InterpreterState;
|
|||||||
* - Extcodesize returns a deterministic value depending on the address.
|
* - Extcodesize returns a deterministic value depending on the address.
|
||||||
* - Extcodecopy copies a deterministic value depending on the address.
|
* - Extcodecopy copies a deterministic value depending on the address.
|
||||||
* - And many other things
|
* - And many other things
|
||||||
* - TODO
|
|
||||||
*
|
*
|
||||||
|
* The main focus is that the generated execution trace is the same for equivalent executions
|
||||||
|
* and likely to be different for non-eqivalent executions.
|
||||||
*/
|
*/
|
||||||
class EVMInstructionInterpreter
|
class EVMInstructionInterpreter
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user