Merge pull request #507 from status-im/fuzz

block witness: add more tests contain invalid data
This commit is contained in:
andri lim 2020-05-19 11:31:27 +07:00 committed by GitHub
commit 47295c7f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 477 additions and 21 deletions

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"
}
]
}

View File

@ -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"):

View File

@ -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