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

DVM STORE function allows to store 2712 bytes of data, space relates to key length #141

Open
Alumn0 opened this issue Sep 17, 2023 · 2 comments

Comments

@Alumn0
Copy link

Alumn0 commented Sep 17, 2023

Dero Simulator Version: 3.5.3-140.DEROHE.STARGATE+13062023

If a smart contract calls STORE(k,v) the maximum length for "value" depends on the length of "key".
The maximum length for "key" appears to be not sanitized and can be 2044 bytes.
If the key length is 2044 bytes, there is only 1 byte space for the value.
If the key length is 1192 byte, there is 1520 byte space for value.

This way it is possible to store approximately 1192+1520 = 2712 byte per key / value pair.

Exceeding the 2044 bytes key limit causes this error continously:

17/09 02:40:02  DEBUG   CORE.blid_ba85765bc9c9c1bc129172b120424f5c9ff7aab5ac4730fffd43107ad9a7dd99      Chain extended  {"new height": 9}
17/09 02:40:02  DEBUG   CORE    reading block snapshot  {"blid": "f4da9d463d43cafe432dd61351c1577720aa201e7a3e92dedbf478db95a6136b", "record_version": 9}
DEROSIM HE: 8/8 [0/0] P 0 TXp 2:0 NW 1 H/s  TESTNET> >> interpreting line [STORE ( k , v )]   err:'<nil>'
interpreting line [RETURN 0]   err:'<nil>'
17/09 02:40:02  ERROR   CORE    Recovered while adding new block        {"blid": "ba85765bc9c9c1bc129172b120424f5c9ff7aab5ac4730fffd43107ad9a7dd99", "r": "invalid value size", "rVerbose": "invalid value size:\n    github.com/deroproject/graviton.(*leaf).loadfullleaffromstore\n        github.com/deroproject/graviton/node_leaf.go:165", "stack": "goroutine 205 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x65\ngithub.com/deroproject/derohe/blockchain.(*Blockchain).Add_Complete_Block.func1()\n\tgithub.com/deroproject/derohe/blockchain/blockchain.go:411 +0x105\npanic({0xab9fc0, 0xc00055d200})\n\truntime/panic.go:890 +0x263\ngithub.com/deroproject/derohe/blockchain.(*Blockchain).Add_Complete_Block(0xc0005b0000, 0xc000276300)\n\tgithub.com/deroproject/derohe/blockchain/blockchain.go:1014 +0x59f4\ngithub.com/deroproject/derohe/blockchain.(*Blockchain).Accept_new_block(0xc0005b0000, 0x9afff74a19e33801?, {0xc0005a0ac0, 0x30, 0x40})\n\tgithub.com/deroproject/derohe/blockchain/miner_block.go:562 +0x1a25\nmain.Mine_block_single(0xc139b7a088970040?, {0x0, 0x0, 0x0, 0xc000516020, {0x0, 0x0, 0x0}})\n\tgithub.com/deroproject/derohe/cmd/simulator/simulator.go:113 +0x27a\nmain.mine_block_auto(0xc0005b0000?, {0x0, 0x0, 0x0, 0xc000516020, {0x0, 0x0, 0x0}})\n\tgithub.com/deroproject/derohe/cmd/simulator/simulator.go:590 +0x447\ncreated by main.main\n\tgithub.com/deroproject/derohe/cmd/simulator/simulator.go:216 +0x10d5\n"}
17/09 02:40:02  ERROR   CORE    Block rejected by chain {"BLID": "ba85765bc9c9c1bc129172b120424f5c9ff7aab5ac4730fffd43107ad9a7dd99", "bl": "02020000018aa102605f09010000020138e3194af7ff9a0dda87a3687b5befc90ece57942798c39fc7473cf5f7eb2e00
000000000000000000000000000000000000000000000000000000000000000001f4da9d463d43cafe432dd61351c1577720aa201e7a3e92dedbf478db95a6136b0a4155450000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d3000000000976e90ccd64c07a3085120e4155450000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d30000000031cf512d9605173492def2f04155450000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d300000000ad2f4c6c122506108bdd0bc54155460000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d300000000f1d36206e16ac61fe83a2dd34155460000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d300000000991565fb14596315bd3299eb4155460000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d30000000010e8ddb4eb8a002dacd287df4155460000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d300000000c807fc88896f64149e09cc8c4155460000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d3000000005fe73b38e2ff35be927a448c4155460000000009f4da9d460000000029d9b2ffdde86565adefc2f1d4f6d4d3000000005357a7f56e585b799111a6447160600000000009f4da9d460000000024ea8a54a2ded470292c1b2e5ee264af000000004d0e3f6e4c4b220896a519b001cbcea69230a9bc160a6caa0bdb09aad8186ad8a96e0a4894ce97c81dd79f4f20", "stack": "Z29yb3V0aW5lIDIwNSBbcnVubmluZ106CnJ1bnRpbWUvZGVidWcuU3RhY2soKQoJcnVudGltZS9kZWJ1Zy9zdGFjay5nbzoyNCArMHg2NQpnaXRodWIuY29tL2Rlcm9wcm9qZWN0L2Rlcm9oZS9ibG9ja2NoYWluLigqQmxvY2tjaGFpbikuQWRkX0NvbXBsZXRlX0Jsb2NrLmZ1bmMxKCkKCWdpdGh1Yi5jb20vZGVyb3Byb2plY3QvZGVyb2hlL2Jsb2NrY2hhaW4vYmxvY2tjaGFpbi5nbzo0NTkgKzB4NjdkCnBhbmljKHsweGFiOWZjMCwgMHhjMDAwNTVkMjAwfSkKCXJ1bnRpbWUvcGFuaWMuZ286ODkwICsweDI2MwpnaXRodWIuY29tL2Rlcm9wcm9qZWN0L2Rlcm9oZS9ibG9ja2NoYWluLigqQmxvY2tjaGFpbikuQWRkX0NvbXBsZXRlX0Jsb2NrKDB4YzAwMDViMDAwMCwgMHhjMDAwMjc2MzAwKQoJZ2l0aHViLmNvbS9kZXJvcHJvamVjdC9kZXJvaGUvYmxvY2tjaGFpbi9ibG9ja2NoYWluLmdvOjEwMTQgKzB4NTlmNApnaXRodWIuY29tL2Rlcm9wcm9qZWN0L2Rlcm9oZS9ibG9ja2NoYWluLigqQmxvY2tjaGFpbikuQWNjZXB0X25ld19ibG9jaygweGMwMDA1YjAwMDAsIDB4OWFmZmY3NGExOWUzMzgwMT8sIHsweGMwMDA1YTBhYzAsIDB4MzAsIDB4NDB9KQoJZ2l0aHViLmNvbS9kZXJvcHJvamVjdC9kZXJvaGUvYmxvY2tjaGFpbi9taW5lcl9ibG9jay5nbzo1NjIgKzB4MWEyNQptYWluLk1pbmVfYmxvY2tfc2luZ2xlKDB4YzEzOWI3YTA4ODk3MDA0MD8sIHsweDAsIDB4MCwgMHgwLCAweGMwMDA1MTYwMjAsIHsweDAsIDB4MCwgMHgwfX0pCglnaXRodWIuY29tL2Rlcm9wcm9qZWN0L2Rlcm9oZS9jbWQvc2ltdWxhdG9yL3NpbXVsYXRvci5nbzoxMTMgKzB4MjdhCm1haW4ubWluZV9ibG9ja19hdXRvKDB4YzAwMDViMDAwMD8sIHsweDAsIDB4MCwgMHgwLCAweGMwMDA1MTYwMjAsIHsweDAsIDB4MCwgMHgwfX0pCglnaXRodWIuY29tL2Rlcm9wcm9qZWN0L2Rlcm9oZS9jbWQvc2ltdWxhdG9yL3NpbXVsYXRvci5nbzo1OTAgKzB4NDQ3CmNyZWF0ZWQgYnkgbWFpbi5tYWluCglnaXRodWIuY29tL2Rlcm9wcm9qZWN0L2Rlcm9oZS9jbWQvc2ltdWxhdG9yL3NpbXVsYXRvci5nbzoyMTYgKzB4MTBkNQo=", "error": "Panic Occurred, keep cool"}
17/09 02:40:02  ERROR   CORE    Block rejected by chain {"BLID": "ba85765bc9c9c1bc129172b120424f5c9ff7aab5ac4730fffd43107ad9a7dd99", "error": "Panic Occurred, keep cool"}
17/09 02:40:02  ERROR   derod   err while accepting block template      {"error": "Panic Occurred, keep cool"}
@Alumn0
Copy link
Author

Alumn0 commented Sep 27, 2023

A grant from the Secret Discord Server allowed me to conduct mainnet testing to confirm the simulator results.
The tests performed focus on examining the storage gas limit (20000)

SCID: a13398928c49cc14abae4e4a499e38246468b64d493831a045c9ce01ac400aa0
Tests performed: 18

The results show that mainnet and the simulator produce the same results:

  1. If the payload is stored as is, a limit of <400 bytes occurs (Test #1)
  2. If the payload is hexdecoded prior to storing it, about 6600 bytes can be stored (Test #4)
  3. If the payload is sent with invalid hex encoding, but the encoding gets "fixed" by the SC, about 6600 bytes can be stored. (Test #6)
  4. Loading hexencoded values from keys and hexdecode them prior to storing, does not yield the same effect as in point 2. (Test #11)
  5. If the key to store the payload is excessively long, approx. keylength+325 bytes can be stored (Test #18)
  6. The tests suggest that also the error from my previous comment would occur on mainnet.

Request SC details from derod (adjust ip:port):
curl -X POST http://127.0.0.1:20200/json_rpc -H 'content-type: application/json' -d '{"jsonrpc": "2.0","id": "1","method": "DERO.GetSC","params": {"scid": "a13398928c49cc14abae4e4a499e38246468b64d493831a045c9ce01ac400aa0","code": true,"variables": true}}' | jq

To accomplish the same testing conditions between the simulator and mainnet and to exclude human error, a php script was developed which executes the tests.
The script accepts these paramaters to interact with the SC: [test_number] [wallet ip] [port] [scid] [data_length] [encoding] [key_label]

The php script: call-mainnet-store-test-function.php
the smart contract: mainnet-store-test.bas
and the test protocol: protocol_1156286726650732687_20230927.txt
can be found in the attached file mainnet-store-tests.tar.gz

@Slixe
Copy link
Contributor

Slixe commented Nov 12, 2023

Keys size aren't counted in Gas storage also, that would be a good improvements too. (only values are)

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

No branches or pull requests

2 participants