Line data Source code
1 : /**
2 : * The MIT License (MIT)
3 : *
4 : * Copyright (c) 2021 RSK Labs Ltd
5 : *
6 : * Permission is hereby granted, free of charge, to any person obtaining a copy
7 : * of this software and associated documentation files (the "Software"), to
8 : * deal in the Software without restriction, including without limitation the
9 : * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 : * sell copies of the Software, and to permit persons to whom the Software is
11 : * furnished to do so, subject to the following conditions:
12 : *
13 : * The above copyright notice and this permission notice shall be included in
14 : * all copies or substantial portions of the Software.
15 : *
16 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 : * IN THE SOFTWARE.
23 : */
24 :
25 : #include "bc_err.h"
26 :
27 : #if defined(HSM_PLATFORM_X86) || defined(HSM_PLATFORM_SGX)
28 :
29 : #if defined(DEBUG_BUILD) || defined(ENCLAVE_LOGS)
30 :
31 : #include "hal/log.h"
32 :
33 : static struct err_entry {
34 : err_code_t errcode;
35 : char errmsg[128];
36 : } err_table[] = {
37 : {UNKNOWN, "Unknown error"},
38 : {PROT_INVALID, "Invalid or unexpected message"},
39 : {RLP_INVALID, "Invalid RLP"},
40 : {BLOCK_TOO_OLD, "Block too old"},
41 : {BLOCK_TOO_SHORT, "Block too short"},
42 : {PARENT_HASH_INVALID, "Invalid parent hash"},
43 : {RECEIPT_ROOT_INVALID, "Invalid receipt root"},
44 : {BLOCK_NUM_INVALID, "Block number > 4 bytes"},
45 : {BLOCK_DIFF_INVALID, "Block difficulty zero or > 32 bytes"},
46 : {UMM_ROOT_INVALID, "Invalid UMM root"},
47 : {BTC_HEADER_INVALID, "Invalid BTC merge mining header"},
48 : {MERKLE_PROOF_INVALID, "Invalid Merkle proof"},
49 : {BTC_CB_TXN_INVALID, "Invalid coinbase transaction"},
50 : {MM_RLP_LEN_MISMATCH, "Merge mining RLP lengths don't match"},
51 : {BTC_DIFF_MISMATCH, "BTC merge mining header doesn't match block diff"},
52 : {MERKLE_PROOF_MISMATCH, "Merkle proof doesn't match merkle root"},
53 : {MM_HASH_MISMATCH, "Merge mining hashes don't match"},
54 : {MERKLE_PROOF_OVERFLOW, "Merkle proof exceeds maximum size"},
55 : {CB_TXN_OVERFLOW, "Coinbase transaction exceeds maximum size"},
56 : {BUFFER_OVERFLOW, "Work area buffer overflow"},
57 :
58 : {CHAIN_MISMATCH, "Block is not parent of previous block"},
59 : {TOTAL_DIFF_OVERFLOW, "Total difficulty overflow"},
60 :
61 : {ANCESTOR_TIP_MISMATCH, "Ancestor tip mismatch"},
62 : {CB_TXN_HASH_MISMATCH, "Coinbase transaction hash mismatch"},
63 :
64 : {BROTHERS_TOO_MANY, "Too many brothers"},
65 : {BROTHER_PARENT_MISMATCH, "Brother parent hash mismatch"},
66 : {BROTHER_SAME_AS_BLOCK, "Brother cannot be same as block"},
67 : {BROTHER_ORDER_INVALID, "Invalid ordering of brothers"},
68 : };
69 :
70 : void show_error(err_code_t errcode) {
71 : char *msg = err_table[0].errmsg;
72 : for (unsigned int i = 1; i < sizeof(err_table) / sizeof(struct err_entry);
73 : i++) {
74 : if (err_table[i].errcode == errcode) {
75 : msg = err_table[i].errmsg;
76 : break;
77 : }
78 : }
79 : LOG("*** ERROR: %s\n", msg);
80 : }
81 :
82 : #else // DEBUG_BUILD || ENCLAVE_LOGS
83 8 : void show_error(err_code_t errcode) {
84 : (void)errcode;
85 8 : }
86 : #endif // DEBUG_BUILD || ENCLAVE_LOGS
87 :
88 : #else
89 : void show_error(err_code_t errcode) {
90 : }
91 : #endif
|