From 6c583c8e322e79e331cb95d044fdee77a2d179b7 Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 19 May 2020 09:27:53 +0700 Subject: [PATCH] block witness: add more tests contain invalid data --- stateless/fixtures/bad_address.json | 17 ++++++ stateless/fixtures/bad_balance.json | 17 ++++++ stateless/fixtures/bad_code.json | 26 +++++++++ stateless/fixtures/bad_code_len.json | 26 +++++++++ stateless/fixtures/bad_nonce.json | 17 ++++++ .../fixtures/code_len_exceed_eip170.json | 26 +++++++++ stateless/fixtures/invalid_account_type.json | 18 ++++++ stateless/fixtures/invalid_code_len.json | 29 ++++++++++ stateless/fixtures/invalid_code_len2.json | 29 ++++++++++ stateless/fixtures/invalid_code_type.json | 29 ++++++++++ stateless/fixtures/invalid_hash_type.json | 29 ++++++++++ stateless/fixtures/invalid_metadata.json | 17 ++++++ stateless/fixtures/invalid_node_type.json | 17 ++++++ .../fixtures/invalid_storage_hash_type.json | 29 ++++++++++ stateless/fixtures/invalid_version.json | 17 ++++++ .../valid_account_type_invalid_data.json | 18 ++++++ .../valid_code_type_invalid_data.json | 29 ++++++++++ .../fixtures/valid_hash_type_bad_data.json | 29 ++++++++++ .../valid_node_type_invalid_data.json | 18 ++++++ stateless/test_witness_json.nim | 57 ++++++++++++------- stateless/tree_from_witness.nim | 4 +- 21 files changed, 477 insertions(+), 21 deletions(-) create mode 100644 stateless/fixtures/bad_address.json create mode 100644 stateless/fixtures/bad_balance.json create mode 100644 stateless/fixtures/bad_code.json create mode 100644 stateless/fixtures/bad_code_len.json create mode 100644 stateless/fixtures/bad_nonce.json create mode 100644 stateless/fixtures/code_len_exceed_eip170.json create mode 100644 stateless/fixtures/invalid_account_type.json create mode 100644 stateless/fixtures/invalid_code_len.json create mode 100644 stateless/fixtures/invalid_code_len2.json create mode 100644 stateless/fixtures/invalid_code_type.json create mode 100644 stateless/fixtures/invalid_hash_type.json create mode 100644 stateless/fixtures/invalid_metadata.json create mode 100644 stateless/fixtures/invalid_node_type.json create mode 100644 stateless/fixtures/invalid_storage_hash_type.json create mode 100644 stateless/fixtures/invalid_version.json create mode 100644 stateless/fixtures/valid_account_type_invalid_data.json create mode 100644 stateless/fixtures/valid_code_type_invalid_data.json create mode 100644 stateless/fixtures/valid_hash_type_bad_data.json create mode 100644 stateless/fixtures/valid_node_type_invalid_data.json diff --git a/stateless/fixtures/bad_address.json b/stateless/fixtures/bad_address.json new file mode 100644 index 000000000..71caa9466 --- /dev/null +++ b/stateless/fixtures/bad_address.json @@ -0,0 +1,17 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "address": "0xAA0e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/bad_balance.json b/stateless/fixtures/bad_balance.json new file mode 100644 index 000000000..33c452afc --- /dev/null +++ b/stateless/fixtures/bad_balance.json @@ -0,0 +1,17 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8ef8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/bad_code.json b/stateless/fixtures/bad_code.json new file mode 100644 index 000000000..9f91e5c78 --- /dev/null +++ b/stateless/fixtures/bad_code.json @@ -0,0 +1,26 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x3ef071a43e07a7a209d4a67f9edd05477e8e3ac30af64656cfe784961fd2433a", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x720ef0ee74f1b3b8252eb3270d484b223f775810", + "balance": "0xb3c2cee7e2cb9289c8cdd1d9b99ff0e7829fdce2f5afd2fca6a2ff9f9bf8e38493d09bc403", + "nonce": "0xad83abd1899ad9ee56", + "codeType": "0x00", + "codeLen": "0x3d", + "code": "0xefda93a915fe9ac8998e195a5fe0bb85a2474e676551e8978cba5b5ea3af0dc90606fd0e6d4f07b0262ada94b579676f51e4226b2dc456be061e99", + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x3ef071a43e07a7a209d4a67f9edd05477e8e3ac30af64656cfe784961fd2433a" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/bad_code_len.json b/stateless/fixtures/bad_code_len.json new file mode 100644 index 000000000..c0c63b3da --- /dev/null +++ b/stateless/fixtures/bad_code_len.json @@ -0,0 +1,26 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x3ef071a43e07a7a209d4a67f9edd05477e8e3ac30af64656cfe784961fd2433a", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x720ef0ee74f1b3b8252eb3270d484b223f775810", + "balance": "0xb3c2cee7e2cb9289c8cdd1d9b99ff0e7829fdce2f5afd2fca6a2ff9f9bf8e38493d09bc403", + "nonce": "0xad83abd1899ad9ee56", + "codeType": "0x00", + "codeLen": "0xee56", + "code": "0x09ddefda93a915fe9ac8998e195a5fe0bb85a2474e676551e8978cba5b5ea3af0dc90606fd0e6d4f07b0262ada94b579676f51e4226b2dc456be061e99", + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x3ef071a43e07a7a209d4a67f9edd05477e8e3ac30af64656cfe784961fd2433a" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/bad_nonce.json b/stateless/fixtures/bad_nonce.json new file mode 100644 index 000000000..ebc416015 --- /dev/null +++ b/stateless/fixtures/bad_nonce.json @@ -0,0 +1,17 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xEEe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/code_len_exceed_eip170.json b/stateless/fixtures/code_len_exceed_eip170.json new file mode 100644 index 000000000..03c278947 --- /dev/null +++ b/stateless/fixtures/code_len_exceed_eip170.json @@ -0,0 +1,26 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x3ef071a43e07a7a209d4a67f9edd05477e8e3ac30af64656cfe784961fd2433a", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x720ef0ee74f1b3b8252eb3270d484b223f775810", + "balance": "0xb3c2cee7e2cb9289c8cdd1d9b99ff0e7829fdce2f5afd2fca6a2ff9f9bf8e38493d09bc403", + "nonce": "0xad83abd1899ad9ee56", + "codeType": "0x00", + "codeLen": "0xad9ee56", + "code": "0x09ddefda93a915fe9ac8998e195a5fe0bb85a2474e676551e8978cba5b5ea3af0dc90606fd0e6d4f07b0262ada94b579676f51e4226b2dc456be061e99", + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x3ef071a43e07a7a209d4a67f9edd05477e8e3ac30af64656cfe784961fd2433a" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_account_type.json b/stateless/fixtures/invalid_account_type.json new file mode 100644 index 000000000..c4ec914e6 --- /dev/null +++ b/stateless/fixtures/invalid_account_type.json @@ -0,0 +1,18 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "accountTypeSub": "0x07", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_code_len.json b/stateless/fixtures/invalid_code_len.json new file mode 100644 index 000000000..aae928c14 --- /dev/null +++ b/stateless/fixtures/invalid_code_len.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x01", + "codeLen": "0xa3e99cc2e5e5e5d6ce01", + "codeHash": { + "nodeType": "0x03", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_code_len2.json b/stateless/fixtures/invalid_code_len2.json new file mode 100644 index 000000000..1cd3d091b --- /dev/null +++ b/stateless/fixtures/invalid_code_len2.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x01", + "codeLen": "0xcc2e5e5e5d6ce01", + "codeHash": { + "nodeType": "0x03", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_code_type.json b/stateless/fixtures/invalid_code_type.json new file mode 100644 index 000000000..c44a45eee --- /dev/null +++ b/stateless/fixtures/invalid_code_type.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x07", + "codeLen": "0x5e", + "codeHash": { + "nodeType": "0x03", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_hash_type.json b/stateless/fixtures/invalid_hash_type.json new file mode 100644 index 000000000..305f1ec40 --- /dev/null +++ b/stateless/fixtures/invalid_hash_type.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x01", + "codeLen": "0x5e", + "codeHash": { + "nodeType": "0x04", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_metadata.json b/stateless/fixtures/invalid_metadata.json new file mode 100644 index 000000000..aca266c5c --- /dev/null +++ b/stateless/fixtures/invalid_metadata.json @@ -0,0 +1,17 @@ +{ + "version": "0x01", + "metadata": "0x01", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_node_type.json b/stateless/fixtures/invalid_node_type.json new file mode 100644 index 000000000..402a918bd --- /dev/null +++ b/stateless/fixtures/invalid_node_type.json @@ -0,0 +1,17 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x06", + "accountType": "0x00", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_storage_hash_type.json b/stateless/fixtures/invalid_storage_hash_type.json new file mode 100644 index 000000000..e50cbf4ba --- /dev/null +++ b/stateless/fixtures/invalid_storage_hash_type.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x01", + "codeLen": "0x5e", + "codeHash": { + "nodeType": "0x03", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x04", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/invalid_version.json b/stateless/fixtures/invalid_version.json new file mode 100644 index 000000000..234193ae1 --- /dev/null +++ b/stateless/fixtures/invalid_version.json @@ -0,0 +1,17 @@ +{ + "version": "0x02", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/valid_account_type_invalid_data.json b/stateless/fixtures/valid_account_type_invalid_data.json new file mode 100644 index 000000000..504292dbd --- /dev/null +++ b/stateless/fixtures/valid_account_type_invalid_data.json @@ -0,0 +1,18 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x00", + "accountTypeSub": "0x01", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/valid_code_type_invalid_data.json b/stateless/fixtures/valid_code_type_invalid_data.json new file mode 100644 index 000000000..8101dd428 --- /dev/null +++ b/stateless/fixtures/valid_code_type_invalid_data.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x02", + "codeLen": "0x5e", + "codeHash": { + "nodeType": "0x03", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/valid_hash_type_bad_data.json b/stateless/fixtures/valid_hash_type_bad_data.json new file mode 100644 index 000000000..0453b49d0 --- /dev/null +++ b/stateless/fixtures/valid_hash_type_bad_data.json @@ -0,0 +1,29 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "accountType": "0x01", + "address": "0x205aea15c1e739b4acdae0cc3b57c34f55907a73", + "balance": "0x8ca589e2e38294c9899abddfbbe887c9bbc5d296eda1f59b8180d8d88883c88d9a86bdba06", + "nonce": "0xa3e99cc2e5e5e5d6ce01", + "codeType": "0x01", + "codeLen": "0x5e", + "codeHash": { + "nodeType": "0x02", + "data": "0x8dd74346f58c605477239378ca66f42e8a75b9cc8aea3287ad30c8a5932a92da" + }, + "storage": [ + { + "nodeType": "0x03", + "data": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } + ], + "debugDepth": "0x00", + "debugHash": "0x12d52947c2ec748f833d7d13d78ffac0594834a5e6d8e4e32831f4717eefc64d" + } + ] +} \ No newline at end of file diff --git a/stateless/fixtures/valid_node_type_invalid_data.json b/stateless/fixtures/valid_node_type_invalid_data.json new file mode 100644 index 000000000..0aa007d40 --- /dev/null +++ b/stateless/fixtures/valid_node_type_invalid_data.json @@ -0,0 +1,18 @@ +{ + "version": "0x01", + "metadata": "0x00", + "rootHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4", + "error": true, + "tree": [ + { + "nodeType": "0x02", + "nodeTypeSub": "0x00", + "accountType": "0x00", + "address": "0x080e7dabd304f1acd44786d3ac613a5f2ff66b77", + "balance": "0x8cf8c7f1f3ffad95bce2f996d7e1f5a6d9aa96efce9ccba59789dcd6dce3969cc99bc9c50e", + "nonce": "0xe3f483f981dee9db5e", + "debugDepth": "0x00", + "debugHash": "0x5b6f632c9fe4ab50cc0f4d09b38235a3a6afbe85048af44bae35297795a932f4" + } + ] +} \ No newline at end of file diff --git a/stateless/test_witness_json.nim b/stateless/test_witness_json.nim index 2b758bf8c..63d80440d 100644 --- a/stateless/test_witness_json.nim +++ b/stateless/test_witness_json.nim @@ -28,18 +28,28 @@ proc processExtensionNode(t: var Tester, x: JsonNode) = t.write(x["nibblesLen"]) t.write(x["nibbles"]) -proc processHashNode(t: var Tester, x: JsonNode) = - t.write(x["data"]) - proc processNode(t: var Tester, x: JsonNode, storageMode: bool = false) +proc writeSub(t: var Tester, x: JsonNode, name: string): string = + let subName = name & "Sub" + let nodeType = x[name].getStr() + if subName in x: + let subType = x[subName].getStr() + t.write(subType) + else: + t.write(nodeType) + result = nodeType + +proc processHashNode(t: var Tester, x: JsonNode) = + discard t.writeSub(x, "nodeType") + t.write(x["data"]) + proc processStorage(t: var Tester, tree: JsonNode) = for x in tree: t.processNode(x, true) proc processByteCode(t: var Tester, x: JsonNode) = - let codeType = x["codeType"].getStr() - t.write(codeType) + let codeType = t.writeSub(x, "codeType") case codeType of "0x00": let codeLen = x["codeLen"].getStr() @@ -48,14 +58,12 @@ proc processByteCode(t: var Tester, x: JsonNode) = t.write(x["code"]) of "0x01": t.write(x["codeLen"]) - t.write("0x03") t.processHashNode(x["codeHash"]) else: - doAssert(false, "wrong bytecode type") + raise newException(ParsingError, "wrong bytecode type") proc processAccountNode(t: var Tester, x: JsonNode) = - let accountType = x["accountType"].getStr() - t.write(accountType) + let accountType = t.writeSub(x, "accountType") t.write(x["address"]) t.write(x["balance"]) t.write(x["nonce"]) @@ -67,15 +75,14 @@ proc processAccountNode(t: var Tester, x: JsonNode) = t.processByteCode(x) t.processStorage(x["storage"]) else: - doAssert(false, "wrong account type") + raise newException(ParsingError, "wrong account type") proc processStorageLeafNode(t: var Tester, x: JsonNode) = t.write(x["key"]) t.write(x["value"]) proc processNode(t: var Tester, x: JsonNode, storageMode: bool = false) = - let nodeType = x["nodeType"].getStr() - t.write(nodeType) + let nodeType = t.writeSub(x, "nodeType") case nodeType of "0x00": t.processBranchNode(x) of "0x01": t.processExtensionNode(x) @@ -84,9 +91,10 @@ proc processNode(t: var Tester, x: JsonNode, storageMode: bool = false) = t.processStorageLeafNode(x) else: t.processAccountNode(x) - of "0x03": t.processHashNode(x) + of "0x03": + t.write(x["data"]) else: - doAssert(false, "wrong node type") + raise newException(ParsingError, "wrong node type") proc parseRootHash(x: string): KeccakHash = result.data = hexToByteArray[32](x) @@ -98,8 +106,11 @@ proc parseTester(t: var Tester, n: JsonNode) = t.write(n["metadata"]) let tree = n["tree"] - for x in tree: - t.processNode(x) + try: + for x in tree: + t.processNode(x) + except ParsingError: + check t.error == true proc parseTester(filename: string): Tester = let n = parseFile(filename) @@ -109,9 +120,17 @@ proc runTest(filePath, fileName: string) = test fileName: let t = parseTester(filePath) var db = newMemoryDB() - var tb = initTreeBuilder(t.output, db, {wfEIP170}) - let root = tb.buildTree() - check root == t.rootHash + try: + var tb = initTreeBuilder(t.output, db, {wfEIP170}) + let root = tb.buildTree() + if t.error: + check root != t.rootHash + else: + check root == t.rootHash + check t.error == false + except ParsingError, ContractCodeError: + debugEcho "Error detected ", getCurrentExceptionMsg() + check t.error == true proc witnessJsonMain*() = for x in walkDirRec("stateless" / "fixtures"): diff --git a/stateless/tree_from_witness.nim b/stateless/tree_from_witness.nim index f0f09f33c..d0ba39070 100644 --- a/stateless/tree_from_witness.nim +++ b/stateless/tree_from_witness.nim @@ -99,13 +99,13 @@ proc safeReadByte(t: var TreeBuilder): byte = if t.readable: result = t.readByte() else: - raise newException(IOError, "Cannot read byte from input stream") + raise newException(ParsingError, "Cannot read byte from input stream") proc safeReadU32(t: var TreeBuilder): uint32 = if t.readable(4): result = fromBytesBE(uint32, t.read(4)) else: - raise newException(IOError, "Cannot read U32 from input stream") + raise newException(ParsingError, "Cannot read U32 from input stream") template safeReadEnum(t: var TreeBuilder, T: type): untyped = let typ = t.safeReadByte.int