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

GAS price for Bytes operation is too cheap: cost 37 mins with 20GAS #2723

Closed
dusmart opened this issue May 7, 2022 · 12 comments · Fixed by neo-project/neo-vm#471
Closed

Comments

@dusmart
Copy link

dusmart commented May 7, 2022

The newbuffer will allocate lots of memory and charge only 0.00000256 GAS.

There are also some other opcode's performance with 20 GAS for reference.

Opcode time POC
newbuffer 0:37:19 VwEAAsDzXgF3AAIAABAAiEVvAJ13AG8AJfL///9JQA==
cat 0:08:40 VwEAAv//DwCIEYgCWYHyB3cAS0uLRW8AnXcAbwAl9f///0lA
left 0:03:00 VwEAAgAAEACIAlmB8gd3AEoCAAAQAI1FbwCddwBvACXx////SUA=
right 0:03:27 VwEAAgAAEACIAlmB8gd3AEoCAAAQAI5FbwCddwBvACXx////SUA=
reversen 0:01:57 VwEAAfgHdwAMKGFhYWJiYmJiYmJiYmNjY2NjY2NkZGRkZGRkZWVlZWVlZWZmZmZmZmZvAJ13AG8AJc////8CwPNeAXcAAfgHVW8AnXcAbwAl9f///0lA
substr 0:01:49 VwEAAgAAEACIAlmB8gd3AEoQAgAAEACMRW8AnXcAbwAl8P///0lA
newarray 0:01:29 VwEAAlkNeU93AAH4B8NFbwCddwBvACX0////QA==
newstruct 0:01:18 VwEAAlkNeU93AAH4B8ZFbwCddwBvACX0////QA==
roll 0:00:26 VwEAAfgHdwAMKGFhYWJiYmJiYmJiYmNjY2NjY2NkZGRkZGRkZWVlZWVlZWZmZmZmZmZvAJ13AG8AJc////8CwPNeAXcAAfcHUm8AnXcAbwAl9f///0lA
xdrop 0:00:26 VwEAAfgHdwAMKGFhYWJiYmJiYmJiYmNjY2NjY2NkZGRkZGRkZWVlZWVlZWZmZmZmZmZvAJ13AG8AJc////8CwPNeAXcAAfcHSEpvAJ13AG8AJfT///9JQA==
memcpy 0:00:10 VwEAAgAAEACIAgAAEACIAlmB8gd3AEsQEk0QAgAAEACJbwCddwBvACXu////SUA=
unpack 0:00:06 VwIAAfIDw3cBAlkNeU93AG8BwUlvAJ13AG8AJfX///9A
GetScriptContainer 0:01:46 QS1RCDBFIvo=

source code in Tanya

@dusmart
Copy link
Author

dusmart commented May 7, 2022

They're all tested in testnet5 node in such a command.

time curl http://seed5t5.neo.org:20332 -d '{ "jsonrpc": "2.0", "id": 1, "method": "invokescript", "params": ["'${R}'"] }'| json_pp

@dusmart
Copy link
Author

dusmart commented May 7, 2022

As mentioned in paper Attacking Resource Metering in EVM, charge the repeated call more expensively is a long-term idea for preventing DoS.

Details can be seen in An Adaptive Gas Cost Mechanism for Ethereum to Defend Against Under-Priced DoS Attacks.

I agree with neo-project/neo-vm#458 by @Liaojinghui in some extents.

Totally Agree With #2724 !!!!!! Only one more concern is that maybe the parameters should be tested carefully so that no normal dAPP is blocked.

@roman-khimov
Copy link
Contributor

20 GAS limit, old Core i7-8565U laptop, NeoGo:

unpack       8,491s
memcpy      14,452s
xdrop       24,287s
roll        22,844s
newstruct 1m16,028s
newarray  1m15,404s
substr      51,809s
reversen  1m11,647s
right       52,515s
left        53,186s
cat         36,936s
newbuffer 4m43,047s

@superboyiii
Copy link
Member

superboyiii commented May 7, 2022

20 GAS limit, i7-10875H Laptop, 48G Mem, C# neo-cli, find some interesting result (based on postman):
Before restart PC:

1st invoke 2nd 3rd
newbuffer 4m28s 2m40s 2m51s
cat 2m56s

After restart PC:

1st invoke 2nd 3rd
newbuffer 39m+ 29m54s 30m38s
cat 2m49s 1m34s 1m12s

I've run my PC for more than 3 days, including many tasks with .NET(building, running cli...). You could see the result before restart and after restart differ a lot. And another result can be seen that the first result for invoking a certain script is always the slowest, then the second and the third will not differ a lot.
I guess will it be something related to Memory distribution on .NET or neo-cli? @roman-khimov @shargon @devhawk

@erikzhang
Copy link
Member

[OpCode.NEWBUFFER] = 1 << 8,

The price of NEWBUFFER is 1 << 8 == 256, which means it's priced at 256 compute units, not 0.00000256GAS. The actual price is the compute units multiplied by the price factor, which defaults to 30 and is now set to 3.

Therefore, according to the number of cycles in your poc 23000000, the final actual price is 1766.4GAS (factor 30), or 176.64GAS (factor 3). And the time consumed is 0:37:19, which is 2239 seconds. Tested on my machine it will be faster than this.

To sum up, this price is basically reasonable and does not need to be adjusted.

@dusmart
Copy link
Author

dusmart commented May 20, 2022

Therefore, according to the number of cycles in your poc 23000000, the final actual price is 1766.4GAS (factor 30), or 176.64GAS (factor 3). And the time consumed is 0:37:19, which is 2239 seconds.

The 23000000 in POC is not the real iteration number. It just want to consume all 20GAS which is the default limit. Real number will be 20_0000_0000 / 256 / 3 in this case.

@erikzhang
Copy link
Member

We can discuss it in neo-project/neo-vm#471.

@roman-khimov
Copy link
Contributor

Can we get an updated table after the neo-project/neo-vm#471 merge?

@dusmart
Copy link
Author

dusmart commented May 23, 2022

I'd like to update it when the seed nodes get updated.
The seed node's performence differs from personal computer.
There will be a huge difference in the results.

@erikzhang
Copy link
Member

I'd like to update it when the seed nodes get updated.

DO NOT attack seed nodes. Any testing should be done in the local environment.

@dusmart
Copy link
Author

dusmart commented May 24, 2022

I'd like to update it when the seed nodes get updated.

DO NOT attack seed nodes. Any testing should be done in the local environment.

kkkkkkkk, sorry for that, won't do DoS on seed node anymore

@roman-khimov
Copy link
Contributor

Just for the record, same Core i7-8565U/16GB machine as #2723 (comment), NEWBUFFER script:

$ ./bin/neo-go --version
NeoGo
Version: 0.102.1-pre-36-g460362ab
GoVersion: go1.21.2
$ time curl -sd '{ "jsonrpc": "2.0", "id": 5, "method": "invokescript", "params": ["VwEAAsDzXgF3AAIAABAAiEVvAJ13AG8AJfL///9JQA=="] }' localhost:20331
{"id":5,"jsonrpc":"2.0","result":{"state":"FAULT","gasconsumed":"2000005980","script":"VwEAAsDzXgF3AAIAABAAiEVvAJ13AG8AJfL///9JQA==","stack":[{"type":"Integer","value":"1048576"}],"exception":"at instruction 15 (NEWBUFFER): gas limit is exceeded","notifications":[]}}

real    0m36,396s
user    0m0,004s
sys     0m0,004s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants