This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
/
OpCode.cs
466 lines (449 loc) · 15.8 KB
/
OpCode.cs
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
namespace Neo.VM
{
public enum OpCode : byte
{
// Constants
/// <summary>
/// An empty array of bytes is pushed onto the stack.
/// </summary>
PUSH0 = 0x00,
PUSHF = PUSH0,
/// <summary>
/// 0x01-0x4B The next opcode bytes is data to be pushed onto the stack
/// </summary>
PUSHBYTES1 = 0x01,
PUSHBYTES75 = 0x4B,
/// <summary>
/// The next byte contains the number of bytes to be pushed onto the stack.
/// </summary>
PUSHDATA1 = 0x4C,
/// <summary>
/// The next two bytes contain the number of bytes to be pushed onto the stack.
/// </summary>
PUSHDATA2 = 0x4D,
/// <summary>
/// The next four bytes contain the number of bytes to be pushed onto the stack.
/// </summary>
PUSHDATA4 = 0x4E,
/// <summary>
/// The number -1 is pushed onto the stack.
/// </summary>
PUSHM1 = 0x4F,
/// <summary>
/// The number 1 is pushed onto the stack.
/// </summary>
PUSH1 = 0x51,
PUSHT = PUSH1,
/// <summary>
/// The number 2 is pushed onto the stack.
/// </summary>
PUSH2 = 0x52,
/// <summary>
/// The number 3 is pushed onto the stack.
/// </summary>
PUSH3 = 0x53,
/// <summary>
/// The number 4 is pushed onto the stack.
/// </summary>
PUSH4 = 0x54,
/// <summary>
/// The number 5 is pushed onto the stack.
/// </summary>
PUSH5 = 0x55,
/// <summary>
/// The number 6 is pushed onto the stack.
/// </summary>
PUSH6 = 0x56,
/// <summary>
/// The number 7 is pushed onto the stack.
/// </summary>
PUSH7 = 0x57,
/// <summary>
/// The number 8 is pushed onto the stack.
/// </summary>
PUSH8 = 0x58,
/// <summary>
/// The number 9 is pushed onto the stack.
/// </summary>
PUSH9 = 0x59,
/// <summary>
/// The number 10 is pushed onto the stack.
/// </summary>
PUSH10 = 0x5A,
/// <summary>
/// The number 11 is pushed onto the stack.
/// </summary>
PUSH11 = 0x5B,
/// <summary>
/// The number 12 is pushed onto the stack.
/// </summary>
PUSH12 = 0x5C,
/// <summary>
/// The number 13 is pushed onto the stack.
/// </summary>
PUSH13 = 0x5D,
/// <summary>
/// The number 14 is pushed onto the stack.
/// </summary>
PUSH14 = 0x5E,
/// <summary>
/// The number 15 is pushed onto the stack.
/// </summary>
PUSH15 = 0x5F,
/// <summary>
/// The number 16 is pushed onto the stack.
/// </summary>
PUSH16 = 0x60,
// Flow control
/// <summary>
/// Does nothing.
/// </summary>
NOP = 0x61,
/// <summary>
/// Reads a 2-byte value n and a jump is performed to relative position n-3.
/// </summary>
JMP = 0x62,
/// <summary>
/// A boolean value b is taken from main stack and reads a 2-byte value n, if b is True then a jump is performed to relative position n-3.
/// </summary>
JMPIF = 0x63,
/// <summary>
/// A boolean value b is taken from main stack and reads a 2-byte value n, if b is False then a jump is performed to relative position n-3.
/// </summary>
JMPIFNOT = 0x64,
/// <summary>
/// Current context is copied to the invocation stack. Reads a 2-byte value n and a jump is performed to relative position n-3.
/// </summary>
CALL = 0x65,
/// <summary>
/// Stops the execution if invocation stack is empty.
/// </summary>
RET = 0x66,
/// <summary>
/// Reads a scripthash and executes the corresponding contract.
/// </summary>
APPCALL = 0x67,
/// <summary>
/// Reads a string and executes the corresponding operation.
/// </summary>
SYSCALL = 0x68,
/// <summary>
/// Reads a scripthash and executes the corresponding contract. Disposes the top item on invocation stack.
/// </summary>
TAILCALL = 0x69,
// Stack
/// <summary>
/// Duplicates the item on top of alt stack and put it on top of main stack.
/// </summary>
DUPFROMALTSTACK = 0x6A,
/// <summary>
/// Puts the input onto the top of the alt stack. Removes it from the main stack.
/// </summary>
TOALTSTACK = 0x6B,
/// <summary>
/// Puts the input onto the top of the main stack. Removes it from the alt stack.
/// </summary>
FROMALTSTACK = 0x6C,
/// <summary>
/// The item n back in the main stack is removed.
/// </summary>
XDROP = 0x6D,
/// <summary>
/// The item n back in the main stack in swapped with top stack item.
/// </summary>
XSWAP = 0x72,
/// <summary>
/// The item on top of the main stack is copied and inserted to the position n in the main stack.
/// </summary>
XTUCK = 0x73,
/// <summary>
/// Puts the number of stack items onto the stack.
/// </summary>
DEPTH = 0x74,
/// <summary>
/// Removes the top stack item.
/// </summary>
DROP = 0x75,
/// <summary>
/// Duplicates the top stack item.
/// </summary>
DUP = 0x76,
/// <summary>
/// Removes the second-to-top stack item.
/// </summary>
NIP = 0x77,
/// <summary>
/// Copies the second-to-top stack item to the top.
/// </summary>
OVER = 0x78,
/// <summary>
/// The item n back in the stack is copied to the top.
/// </summary>
PICK = 0x79,
/// <summary>
/// The item n back in the stack is moved to the top.
/// </summary>
ROLL = 0x7A,
/// <summary>
/// The top three items on the stack are rotated to the left.
/// </summary>
ROT = 0x7B,
/// <summary>
/// The top two items on the stack are swapped.
/// </summary>
SWAP = 0x7C,
/// <summary>
/// The item at the top of the stack is copied and inserted before the second-to-top item.
/// </summary>
TUCK = 0x7D,
// Splice
/// <summary>
/// Concatenates two strings.
/// </summary>
CAT = 0x7E,
/// <summary>
/// Returns a section of a string.
/// </summary>
SUBSTR = 0x7F,
/// <summary>
/// Keeps only characters left of the specified point in a string.
/// </summary>
LEFT = 0x80,
/// <summary>
/// Keeps only characters right of the specified point in a string.
/// </summary>
RIGHT = 0x81,
/// <summary>
/// Returns the length of the input string.
/// </summary>
SIZE = 0x82,
// Bitwise logic
/// <summary>
/// Flips all of the bits in the input.
/// </summary>
INVERT = 0x83,
/// <summary>
/// Boolean and between each bit in the inputs.
/// </summary>
AND = 0x84,
/// <summary>
/// Boolean or between each bit in the inputs.
/// </summary>
OR = 0x85,
/// <summary>
/// Boolean exclusive or between each bit in the inputs.
/// </summary>
XOR = 0x86,
/// <summary>
/// Returns 1 if the inputs are exactly equal, 0 otherwise.
/// </summary>
EQUAL = 0x87,
//OP_EQUALVERIFY = 0x88, // Same as OP_EQUAL, but runs OP_VERIFY afterward.
//OP_RESERVED1 = 0x89, // Transaction is invalid unless occuring in an unexecuted OP_IF branch
//OP_RESERVED2 = 0x8A, // Transaction is invalid unless occuring in an unexecuted OP_IF branch
// Arithmetic
// Note: Arithmetic inputs are limited to signed 32-bit integers, but may overflow their output.
/// <summary>
/// 1 is added to the input.
/// </summary>
INC = 0x8B,
/// <summary>
/// 1 is subtracted from the input.
/// </summary>
DEC = 0x8C,
/// <summary>
/// Puts the sign of top stack item on top of the main stack. If value is negative, put -1; if positive, put 1; if value is zero, put 0.
/// </summary>
SIGN = 0x8D,
/// <summary>
/// The sign of the input is flipped.
/// </summary>
NEGATE = 0x8F,
/// <summary>
/// The input is made positive.
/// </summary>
ABS = 0x90,
/// <summary>
/// If the input is 0 or 1, it is flipped. Otherwise the output will be 0.
/// </summary>
NOT = 0x91,
/// <summary>
/// Returns 0 if the input is 0. 1 otherwise.
/// </summary>
NZ = 0x92,
/// <summary>
/// a is added to b.
/// </summary>
ADD = 0x93,
/// <summary>
/// b is subtracted from a.
/// </summary>
SUB = 0x94,
/// <summary>
/// a is multiplied by b.
/// </summary>
MUL = 0x95,
/// <summary>
/// a is divided by b.
/// </summary>
DIV = 0x96,
/// <summary>
/// Returns the remainder after dividing a by b.
/// </summary>
MOD = 0x97,
/// <summary>
/// Shifts a left b bits, preserving sign.
/// </summary>
SHL = 0x98,
/// <summary>
/// Shifts a right b bits, preserving sign.
/// </summary>
SHR = 0x99,
/// <summary>
/// If both a and b are not 0, the output is 1. Otherwise 0.
/// </summary>
BOOLAND = 0x9A,
/// <summary>
/// If a or b is not 0, the output is 1. Otherwise 0.
/// </summary>
BOOLOR = 0x9B,
/// <summary>
/// Returns 1 if the numbers are equal, 0 otherwise.
/// </summary>
NUMEQUAL = 0x9C,
/// <summary>
/// Returns 1 if the numbers are not equal, 0 otherwise.
/// </summary>
NUMNOTEQUAL = 0x9E,
/// <summary>
/// Returns 1 if a is less than b, 0 otherwise.
/// </summary>
LT = 0x9F,
/// <summary>
/// Returns 1 if a is greater than b, 0 otherwise.
/// </summary>
GT = 0xA0,
/// <summary>
/// Returns 1 if a is less than or equal to b, 0 otherwise.
/// </summary>
LTE = 0xA1,
/// <summary>
/// Returns 1 if a is greater than or equal to b, 0 otherwise.
/// </summary>
GTE = 0xA2,
/// <summary>
/// Returns the smaller of a and b.
/// </summary>
MIN = 0xA3,
/// <summary>
/// Returns the larger of a and b.
/// </summary>
MAX = 0xA4,
/// <summary>
/// Returns 1 if x is within the specified range (left-inclusive), 0 otherwise.
/// </summary>
WITHIN = 0xA5,
// Crypto
//RIPEMD160 = 0xA6, // The input is hashed using RIPEMD-160.
/// <summary>
/// The input is hashed using SHA-1.
/// </summary>
SHA1 = 0xA7,
/// <summary>
/// The input is hashed using SHA-256.
/// </summary>
SHA256 = 0xA8,
/// <summary>
/// The input is hashed using Hash160: first with SHA-256 and then with RIPEMD-160.
/// </summary>
HASH160 = 0xA9,
/// <summary>
/// The input is hashed using Hash256: twice with SHA-256.
/// </summary>
HASH256 = 0xAA,
/// <summary>
/// The publickey and signature are taken from main stack. Verifies if transaction was signed by given publickey and a boolean output is put on top of the main stack.
/// </summary>
CHECKSIG = 0xAC,
/// <summary>
/// The publickey, signature and message are taken from main stack. Verifies if given message was signed by given publickey and a boolean output is put on top of the main stack.
/// </summary>
VERIFY = 0xAD,
/// <summary>
/// A set of n public keys (an array or value n followed by n pubkeys) is validated against a set of m signatures (an array or value m followed by m signatures). Verify transaction as multisig and a boolean output is put on top of the main stack.
/// </summary>
CHECKMULTISIG = 0xAE,
// Array
/// <summary>
/// An array is removed from top of the main stack. Its size is put on top of the main stack.
/// </summary>
ARRAYSIZE = 0xC0,
/// <summary>
/// A value n is taken from top of main stack. The next n items on main stack are removed, put inside n-sized array and this array is put on top of the main stack.
/// </summary>
PACK = 0xC1,
/// <summary>
/// An array is removed from top of the main stack. Its elements are put on top of the main stack (in reverse order) and the array size is also put on main stack.
/// </summary>
UNPACK = 0xC2,
/// <summary>
/// An input index n (or key) and an array (or map) are taken from main stack. Element array[n] (or map[n]) is put on top of the main stack.
/// </summary>
PICKITEM = 0xC3,
/// <summary>
/// A value v, index n (or key) and an array (or map) are taken from main stack. Attribution array[n]=v (or map[n]=v) is performed.
/// </summary>
SETITEM = 0xC4,
/// <summary>
///用作引用類型 en: A value n is taken from top of main stack. A zero-filled array type with size n is put on top of the main stack.
/// </summary>
NEWARRAY = 0xC5,
/// <summary>
///用作值類型 en: A value n is taken from top of main stack. A zero-filled struct type with size n is put on top of the main stack.
/// </summary>
NEWSTRUCT = 0xC6,
/// <summary>
/// A Map is created and put on top of the main stack.
/// </summary>
NEWMAP = 0xC7,
/// <summary>
/// The item on top of main stack is removed and appended to the second item on top of the main stack.
/// </summary>
APPEND = 0xC8,
/// <summary>
/// An array is removed from the top of the main stack and its elements are reversed.
/// </summary>
REVERSE = 0xC9,
/// <summary>
/// An input index n (or key) and an array (or map) are removed from the top of the main stack. Element array[n] (or map[n]) is removed.
/// </summary>
REMOVE = 0xCA,
/// <summary>
/// An input index n (or key) and an array (or map) are removed from the top of the main stack. Puts True on top of main stack if array[n] (or map[n]) exist, and False otherwise.
/// </summary>
HASKEY = 0xCB,
/// <summary>
/// A map is taken from top of the main stack. The keys of this map are put on top of the main stack.
/// </summary>
KEYS = 0xCC,
/// <summary>
/// A map is taken from top of the main stack. The values of this map are put on top of the main stack.
/// </summary>
VALUES = 0xCD,
// Stack isolation
CALL_I = 0xE0,
CALL_E = 0xE1,
CALL_ED = 0xE2,
CALL_ET = 0xE3,
CALL_EDT = 0xE4,
// Exceptions
/// <summary>
/// Halts the execution of the vm by setting VMState.FAULT.
/// </summary>
THROW = 0xF0,
/// <summary>
/// Removes top stack item n, and halts the execution of the vm by setting VMState.FAULT only if n is False.
/// </summary>
THROWIFNOT = 0xF1
}
}