-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.h
executable file
·279 lines (240 loc) · 6.16 KB
/
functions.h
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#ifndef SOLIDITY_FUNC
#define SOLIDITY_FUNC
#include <klee/klee.h>
#include "types.h"
#include <cstring>
#include <string>
#include <iostream>
#include <sstream>
// #include <x86intrin.h>
//#include <boost/multiprecision/cpp_int.hpp>
// #define unsigned unsigned
// #define int int
//number units
#define wei *1
#define szabo *(10^12)
#define finney *(10^15)
#define ether *(10^18)
//time units
#define seconds *1
#define minutes *60
#define hours minutes*60
#define days hours*24
#define weeks days*7
#define years days*365
// #define unsigned boost::multiprecision::unsigned
int gas_exhausted;
int gas_tobeused;
address blockCoinbase;
// (uint): current block difficulty
unsigned blockDifficulty;
// (uint): current block gaslimit
unsigned blockGaslimit;
// (uint): current block number
unsigned blockNumber = 1000;
// (uint): current block timestamp
unsigned blockTimestamp;
// (bytes): complete calldata
char* msgData;
// (address payable): sender of the message (current call)
address msgSender;
// (uint): number of wei sent with the message
unsigned msgValue;
// (uint): current block timestamp (alias for block.timestamp)
unsigned now;
// (uint): gas price of the transaction
unsigned txGasprice;
// (address payable): sender of the transaction (full call chain)
address txOrigin;
bool approximate(unsigned amount)
{
int retVal;
int balance;
klee_make_symbolic(&balance, sizeof(balance),"balance");
klee_make_symbolic(&gas_tobeused, sizeof(gas_tobeused),"gas_use");
klee_make_symbolic(&gas_exhausted, sizeof(gas_exhausted),"gas_exhausted");
// sender.balance = balance;
if(gas_exhausted)
return false;
else if(gas_tobeused >= 2300)
return false;
// else if(sender.balance <= amount)
// return false;
else
{
// receiver.balance = 0;
klee_make_symbolic(&retVal, sizeof(retVal),"returnValue");
if(retVal > 0)
{
// receiver.balance += amount;
// sender.balance -= amount;
return true;
}
else
return false;
}
return true;
// std::srand(std::time(0));
// int ret_val = rand()%2;
// bool sendVal;
//
// if(ret_val)
// sendVal = true;
// else
// sendVal = false;
}
address::address(){
// balance = 0;
}
address::address(std::string id){
if(id.length() > 0 && id.length() == 42){
for(int i = 0; i < 42; ++i)
addressId[i] = id[i];
}
}
bool address::operator ==(address const &A) const{
if(A.addressId && this->addressId){
if(strncmp(addressId, A.addressId, sizeof(addressId)) == 0)
return true;
}
return false;
}
bool address::operator !=(address const &A) const{
if(A.addressId && this->addressId){
if(strncmp(addressId, A.addressId, sizeof(addressId)) != 0)
return true;
}
return false;
}
bool address::operator <(address const &A) const {
// std::string str1(this->addressId);
// std::string str2(A.addressId);
// if(str1 < str2)
// return true;
// return false;
if(this->addressId && A.addressId)
return (this->balance) < (A.balance);
return false;
}
address& address::operator =(address const &A){
// if(A){
// addressId = new char[42];
// if(A.addressId && sizeof(A.addressId) <= 42){
// strcpy(addressId, A.addressId);
// // addressId[sizeof(addressId) - 1] = 0;
// }
// else
// strcpy(addressId, "0");
if(A.addressId){
strncpy(addressId, A.addressId, sizeof(addressId));
}
balance = A.balance;
return *this;
// }
// return *this;
}
address& address::operator =(std::string id){
// addressId = new char[42];
if(id.length() > 0 && id.length() == 42){
for(int i = 0; i < 42; ++i)
addressId[i] = id[i];
}
return *this;
}
bool address::send(unsigned amount){
if(approximate(amount))
return 1;
else
return 0;
}
bool address::call(std::string amount){
// if(approximate(amount))
// return true;
// else
return false;
}
bool address::staticcall(std::string amount){
// if(approximate(amount))
// return true;
// else
return false;
}
bool address::delegatecall(std::string amount){
// if(approximate(amount))
// return true;
// else
return false;
}
bool address::transfer(unsigned amount){
if(approximate(amount))
return true;
else{
std::cerr << "Exception on transfer";
return false;
}
// return false;
}
std::string getUniqueStr() {
static int n = 1;
std::stringstream os;
os << n++;
return os.str();
}
int suicide(address receiver){
int retVal;
klee_make_symbolic(&retVal, sizeof(retVal),"returnValue");
if(retVal > 0)
return 1;
else
return 0;
}
int selfdestruct(address receiver){
int retVal;
klee_make_symbolic(&retVal, sizeof(retVal),"returnValue");
if(retVal > 0)
return 1;
else
return 0;
}
void revert(){
}
void revert(std::string /*memory */ message){
}
char* blockhash(unsigned blockNo){
if(blockNo == blockNumber)
return NULL;
// else
std::string temp = getUniqueStr();// + std::string(blockNo);
char* hash = strdup(temp.c_str());
return hash;
// return NULL;
}
char* keccak256(/*bytes*/char* memory){
std::string temp = getUniqueStr() + std::string(memory);
char* hash = strdup(temp.c_str());
return hash;
}
char* sha256(/*bytes*/char* memory){
std::string temp = getUniqueStr() + std::string(memory);
char* hash = strdup(temp.c_str());
return hash;
}
char* ripemd160(/*bytes*/char* memory){
std::string temp = getUniqueStr() + std::string(memory);
char* hash = strdup(temp.c_str());
return hash;
}
address ecrecover(/*bytes32*/char* hash, unsigned /*uint8*/ v, char* /*bytes32*/ r, char* /*bytes32*/ s){
return address();
}
unsigned addmod(unsigned x, unsigned y, unsigned k){
if(k != 0)
return (x + y) % k;
return 0; //do the checks
}
unsigned mulmod(unsigned x, unsigned y, unsigned k){
if(k != 0)
return (x + y) % k;
return 0; //do the checks
}
#endif