Repository navigation
Expand file tree
/
Copy pathYulEvmoneInterface.cpp
More file actions
98 lines (87 loc) · 2.72 KB
/
Copy pathYulEvmoneInterface.cpp
File metadata and controls
98 lines (87 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#include <test/tools/ossfuzz/YulEvmoneInterface.h>
#include <libyul/Exceptions.h>
using namespace solidity;
using namespace solidity::test::fuzzer;
using namespace solidity::yul;
bytes YulAssembler::assemble()
{
if (
!m_stack.parseAndAnalyze("source", m_yulProgram) ||
!m_stack.parserResult()->code ||
!m_stack.parserResult()->analysisInfo ||
langutil::Error::containsErrors(m_stack.errors())
)
yulAssert(false, "Yul program could not be parsed successfully.");
if (m_optimiseYul)
m_stack.optimize();
return m_stack.assemble(AssemblyStack::Machine::EVM).bytecode->bytecode;
}
evmc::result YulEvmoneUtility::deployCode(bytes const& _input, EVMHost& _host)
{
// Zero initialize all message fields
evmc_message msg = {};
// Gas available (value of type int64_t) is set to its maximum value
msg.gas = std::numeric_limits<int64_t>::max();
solAssert(
_input.size() <= 0xffff,
"Deployed byte code is larger than the permissible 65535 bytes."
);
uint8_t inputSizeHigher = static_cast<uint8_t>(_input.size() >> 8);
uint8_t inputSizeLower = _input.size() & 0xff;
/*
* CODESIZE
* PUSH0 0xc
* PUSH0 0x0
* CODECOPY
* PUSH1 <INPUTSIZE>
* PUSH0 0x0
* RETURN
*/
bytes deployCode = bytes{
0x38, 0x60, 0x0c, 0x60, 0x00, 0x39, 0x61,
inputSizeHigher, inputSizeLower,
0x60, 0x00, 0xf3
} + _input;
msg.input_data = deployCode.data();
msg.input_size = deployCode.size();
msg.kind = EVMC_CREATE;
return _host.call(msg);
}
evmc_message YulEvmoneUtility::callMessage(evmc_address _address)
{
evmc_message call = {};
call.gas = std::numeric_limits<int64_t>::max();
call.destination = _address;
call.kind = EVMC_CALL;
return call;
}
bool YulEvmoneUtility::seriousCallError(evmc_status_code _code)
{
if (_code == EVMC_OUT_OF_GAS)
return true;
else if (_code == EVMC_STACK_OVERFLOW)
return true;
else if (_code == EVMC_STACK_UNDERFLOW)
return true;
else if (_code == EVMC_INTERNAL_ERROR)
return true;
else if (_code == EVMC_UNDEFINED_INSTRUCTION)
return true;
else if (_code == EVMC_INVALID_MEMORY_ACCESS)
return true;
else
return false;
}