skalenetwork / skale-consensus

Running the very core of SKL network, SKALE BFT consensus is universal, modern, modular, high-performance, asynchronous, provably-secure, agent-based Proof-of-Stake blockchain consensus engine in C++ 17. Includes provably secure embedded Oracle. Used by SKALE elastic blockchains. Easy and flexible enough to implement your own blockchain or smart contract platform. BLS signatures and Binary Asynchronous Consensus are main building blocks.
https://docs.skale.network/technology/consensus-spec
GNU Affero General Public License v3.0
78 stars 32 forks source link

Oracle requests failed if spaces between elements #764

Closed oleksandrSydorenkoJ closed 1 year ago

oleksandrSydorenkoJ commented 1 year ago

Versions: schain:3.16.1-beta.1

Preconditions: Active schain medium type Oracle-demo

Steps to reproduce:

  1. Send the request without spaces between elements in the request's body
            '"cid":<skale chain ID uint>,"uri":"eth://","jsps":["/result"],"encoding":"json","ethApi":"eth_call","params":[{"from":"0x0000000000000000000000000000000000000000","to":"0x07865c6e87b9f70255377e024ace6630c1eaa37f","data":"0x70a082310000000000000000000000002170ed0880ac9a755fd29b2688956bd959f933f8","gas":"0xfffff"},"latest"]',
  2. Check the result
  3. Send the request without spaces between elements in the request's body (example with space between cid and uri)
             '"cid":<skale chain ID unit>, "uri":"eth://","jsps":["/result"],"encoding":"json","ethApi":"eth_call","params":[{"from":"0x0000000000000000000000000000000000000000","to":"0x07865c6e87b9f70255377e024ace6630c1eaa37f","data":"0x70a082310000000000000000000000002170ed0880ac9a755fd29b2688956bd959f933f8","gas":"0xfffff"},"latest"]',
  4. Compare the results

Expected state: Skaled should handle the empty places in the request and trim them.

Actaul state: Oracle request failed with "Invalid oracle spec" error

Logs:

========== Calculating PoW number ==========
PoW number: 6398
========== Sending request to Oracle ==========
Request >>>  {'id': 83, 'jsonrpc': '2.0', 'method': 'oracle_submitRequest', 'params': ['{"cid":123123, "uri":"eth://","jsps":["/result"],"encoding":"json","ethApi":"eth_call","params":[{"from":"0x0000000000000000000000000000000000000000","to":"0x07865c6e87b9f70255377e024ace6630c1eaa37f","data":"0x70a082310000000000000000000000002170ed0880ac9a755fd29b2688956bd959f933f8","gas":"0xfffff"},"latest"],"time":1681496728000,"pow":6398}']}
Response <<<  {'error': {'code': 10, 'data': None, 'message': 'Invalid oracle spec in submitOracleRequest OracleRequestSpec:parseSpec'}, 'id': 83, 'jsonrpc': '2.0'}
Send oracle request failed
kladkogex commented 1 year ago

Will put in the documentation

Not having spaces is good since it speeds up Solidity parses

oleksandrSydorenkoJ commented 1 year ago

Re-checked on schain:3.16.1-beta.2

The problem is on the client side - need to manually remove empty spaces from the string.

========== Calculating PoW number ==========
PoW number: 1621
========== Sending request to Oracle ==========
Request >>>  {'id': 83, 'jsonrpc': '2.0', 'method': 'oracle_submitRequest', 'params': ['{"cid":<CID of skale-chain >, "uri":"eth://","jsps":["/result"],"encoding":"json","ethApi":"eth_call","params":[{"from":"0x0000000000000000000000000000000000000000","to":"0x07865c6e87b9f70255377e024ace6630c1eaa37f","data":"0x70a082310000000000000000000000002170ed0880ac9a755fd29b2688956bd959f933f8","gas":"0xfffff"},"latest"],"time":1681819683000,"pow":1621}']}
Response <<<  {'error': {'code': 33, 'data': None, 'message': 'Invalid oracle spec in submitOracleRequest Oracle check failed: PoW did not verify'}, 'id': 83, 'jsonrpc': '2.0'}