Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine Opcode/Syscall price #2004

Closed
Qiao-Jin opened this issue Oct 13, 2020 · 0 comments · Fixed by #2020
Closed

Redefine Opcode/Syscall price #2004

Qiao-Jin opened this issue Oct 13, 2020 · 0 comments · Fixed by #2020
Labels
Discussion Initial issue state - proposed but not yet accepted

Comments

@Qiao-Jin
Copy link
Contributor

Qiao-Jin commented Oct 13, 2020

Summary or problem description
As recently there has been several discussions about problems in Opcode/Syscall price definition (#1911, #1877, #1875, #1863, #1855, etc), I did a test upon opcode time costs and the result is as follows.

Opcode Time(microsecond) Price Price / Time
PUSHINT8 0.164 30 182.9268293
PUSHINT256 0.164 120 731.7073171
PUSHA 0.1834 120 654.3075245
PUSHNULL 0.0717 30 418.4100418
PUSHDATA1 0.151 180 1192.05298
PUSHDATA2 0.151 13000 86092.71523
PUSHDATA4 0.151 110000 728476.8212
PUSHM1 0.1631 30 183.9362354
NOP 0.0326 30 920.2453988
JMP 0.05 70 1400
JMP_L 0.0418 70 1674.641148
JMPIF 0.0684 70 1023.391813
JMPIF_L 0.07 70 1000
JMPIFNOT 0.0706 70 991.5014164
JMPIFNOT_L 0.0736 70 951.0869565
JMPEQ 0.1045 70 669.8564593
JMPEQ_L 0.1049 70 667.3021926
JMPNE 0.1074 70 651.7690875
JMPNE_L 0.1062 70 659.13371
CALL 0.0581 22000 378657.4871
CALL_L 0.0562 22000 391459.0747
CALLA 0.2749 22000 80029.10149
ABORT NAN 30 NAN
ASSERT 0.0616 30 487.012987
THROW 0.461 22000 47722.34273
TRY 0.1836 100 544.6623094
ENDTRY 0.053 100 1886.792453
ENDFINALLY 0.461 100 216.9197397
RET 0.0265 0 0
SYSCALL NAN 0 NAN
DEPTH 0.1545 60 388.3495146
DROP 0.061 60 983.6065574
NIP 0.0718 60 835.6545961
XDROP 33.21 400 12.04456489
CLEAR 18 400 22.22222222
DUP 0.0691 60 868.3068017
OVER 0.0749 60 801.0680908
PICK 0.083 60 722.8915663
TUCK 0.0847 60 708.3825266
SWAP 0.0886 60 677.2009029
ROT 0.0885 60 677.9661017
ROLL 0.1193 400 3352.891869
REVERSE3 0.0467 60 1284.796574
REVERSE4 0.049 60 1224.489796
REVERSEN 1.953125 400 204.8
INITSSLOT 3.805 400 105.1248357
INITSLOT 14.4598 800 55.3257998
LDSFLD 0.1064 60 563.9097744
STSFLD 0.1164 60 515.4639175
LDLOC 0.1031 60 581.9592629
STLOC 0.1153 60 520.3816132
LDARG 0.1081 60 555.0416281
STARG 0.1156 60 519.0311419
NEWBUFFER 9 80000 8888.888889
MEMCPY 135.5 80000 590.4059041
CAT 709.5 80000 112.7554616
SUBSTR 696.5 80000 114.8600144
LEFT 690 80000 115.942029
RIGHT 713.5 80000 112.1233357
INVERT 0.2681 100 372.9951511
AND 0.2627 200 761.324705
OR 0.268 200 746.2686567
XOR 0.2669 200 749.3443237
EQUAL(min) 0.11 200 1818.181818
EQUAL(max) 8 200 25
SIGN 0.2304 100 434.0277778
ABS 0.2345 100 426.4392324
NEGATE 0.2024 100 494.0711462
INC 0.2491 100 401.4452027
DEC 0.2477 100 403.7141704
ADD 0.3015 200 663.3499171
SUB 0.2981 200 670.9158001
MUL 0.3189 300 940.7337723
DIV 0.3155 300 950.8716323
MOD 0.2811 300 1067.235859
SHL 1.0208 300 293.8871473
SHR 1.5754 300 190.4278279
NOT 0.0806 100 1240.694789
BOOLAND 0.1065 200 1877.934272
BOOLOR 0.1032 200 1937.984496
NZ 0.0841 100 1189.060642
NUMEQUAL 0.1155 200 1731.601732
NUMNOTEQUAL 0.1133 200 1765.225066
LT 0.1154 200 1733.102253
LE 0.1154 200 1733.102253
GT 0.1185 200 1687.763713
GE 0.115 200 1739.130435
MIN 0.3261 200 613.308801
MAX 0.2834 200 705.716302
WITHIN 0.1428 200 1400.560224
PACK 126.3 7000 55.42359462
UNPACK 54 7000 129.6296296
NEWARRAY0 0.5639 400 709.3456287
NEWARRAY 61.8 15000 242.7184466
NEWARRAY_T 62.8 15000 238.8535032
NEWSTRUCT0 0.5716 400 699.790063
NEWSTRUCT 64 15000 234.375
NEWMAP 0.7854 200 254.6473135
SIZE 0.64 150 234.375
HASKEY 1.3 270000 207692.3077
KEYS 1.0354 500 482.9051574
VALUES 1400 7000 5
PICKITEM 0.8 270000 337500
APPEND 1134 15000 13.22751323
SETITEM 1037 270000 260.3664417
REVERSEITEMS 500 500 1
REMOVE 0.8 500 625
CLEARITEMS 300 400 1.333333333
ISNULL 0.15 60 400
ISTYPE 0.27 60 222.2222222
CONVERT 0.1229 80000 650935.7201

In this test, the time cost of each opcode is got from scenarios where they tend to cost as much time as possible under current limits. Besides, some opcodes which are similiar in functionality are omitted.

From the result we can see, Price / Time factor differs drastically between opcodes. Some differences are because of different RAM cost(i.e. PUSHDATA1 vs PUSHDATA4), some are because of system calls, but still many others are not seemingly reasonable.

Furthermore, we should focus on opcodes whose Price / Time factor is too high or below 100 (these opcodes violate "1 gas per second during Persist" rule defined here and can be used in DoS attacks).

Besides, the price of some SYSCALL (i.e. Vote in #1877) is also not reasonable.

Neo Version

  • Neo 3

Where in the software does this update applies to?

  • VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Initial issue state - proposed but not yet accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant