Omniscia 0xPhase Audit

IDB Code Style Findings

IDB Code Style Findings

IDB-01C: Multiple Top-Level Declarations

TypeSeverityLocation
Code StyleIDB.sol:L8, L172

Description:

The referenced file contains multiple top-level declarations that decrease the legibility of the codebase.

Example:

db/IDB.sol
8interface IDB {
9 struct Set {
10 bool exists;
11 EnumerableSet.Bytes32Set list;
12 }
13
14 enum OpcodeType {
15 VALUE,
16 LENGTH,
17 CONTAINS,
18 INVERSE,
19 ADD,
20 SUB,
21 MUL,
22 DIV,
23 EQ,
24 GT,
25 LT,
26 NEQ,
27 GTE,
28 LTE,
29 AND,
30 OR,
31 NAND
32 }
33
34 struct Opcode {
35 OpcodeType opcode;
36 bytes data;
37 }
38
39 struct ValueOpcode {
40 uint256 value;
41 }
42
43 struct ContainsOpcode {
44 bytes32[] keys;
45 }
46
47 struct InverseOpcode {
48 Opcode value;
49 }
50
51 struct ArithmeticOperatorOpcode {
52 Opcode[] values;
53 }
54
55 struct ComparatorOpcode {
56 Opcode a;
57 Opcode b;
58 }
59
60 struct GateOpcode {
61 Opcode[] values;
62 }
63
64 /// @notice Adds a key value pair
65 /// @param key The key to add
66 /// @param value The value to add
67 function add(bytes32 key, bytes32 value) external;
68
69 /// @notice Adds a key value pair
70 /// @param key The key to add
71 /// @param value The value to add
72 function add(bytes32 key, address value) external;
73
74 /// @notice Sets a key value pair
75 /// @param key The key to set
76 /// @param value The value to set
77 function set(bytes32 key, bytes32 value) external;
78
79 /// @notice Sets a key value pair
80 /// @param key The key to set
81 /// @param value The value to set
82 function set(bytes32 key, address value) external;
83
84 /// @notice Adds a list of keys with a value pairs
85 /// @param keys The keys to add
86 /// @param value The value to add
87 function add(bytes32[] memory keys, bytes32 value) external;
88
89 /// @notice Adds a list of keys with a value pairs
90 /// @param keys The keys to add
91 /// @param value The value to add
92 function add(bytes32[] memory keys, address value) external;
93
94 /// @notice Adds a key with a list of value pairs
95 /// @param key The key to add
96 /// @param values The values to add
97 function add(bytes32 key, bytes32[] memory values) external;
98
99 /// @notice Adds a key with a list of value pairs
100 /// @param key The key to add
101 /// @param values The values to add
102 function add(bytes32 key, address[] memory values) external;
103
104 /// @notice Removes all pairs with the key and the key itself
105 /// @param key The key to remove
106 function removeKey(bytes32 key) external;
107
108 /// @notice Removes all pairs with the value and the value itself
109 /// @param value The value to remove
110 function removeValue(bytes32 value) external;
111
112 /// @notice Removes a pair
113 /// @param key The key to remove
114 /// @param value The value to remove
115 function removePair(bytes32 key, bytes32 value) external;
116
117 /// @notice Executes an opcode and its descendants against every value in the DB. It is effectively a custom VM, being able to do complex computation against all values in the DB
118 /// @dev digest() is not meant to be used on-chain due to the high gas cost
119 /// @param opcode The opcode to execute
120 /// @return result The execution result for every value
121 function digest(
122 Opcode memory opcode
123 ) external view returns (bytes32[] memory result);
124
125 /// @notice Gets the first value with the key
126 /// @param key The key of the pair
127 /// @return The bytes32 representation of the value
128 function getValueB32(bytes32 key) external view returns (bytes32);
129
130 /// @notice Gets the first value with the key
131 /// @param key The key of the pair
132 /// @return The bytes32 representation of the value
133 function getValue(string memory key) external view returns (bytes32);
134
135 /// @notice Gets the first value with the key
136 /// @param key The key of the pair
137 /// @return The address representation of the value
138 function getAddressB32(bytes32 key) external view returns (address);
139
140 /// @notice Gets the first value with the key
141 /// @param key The key of the pair
142 /// @return The address representation of the value
143 function getAddress(string memory key) external view returns (address);
144
145 /// @notice Gets the values with the key
146 /// @param key The key of the pairs
147 /// @return arr bytes32 representations of the values
148 function getValues(bytes32 key) external view returns (bytes32[] memory arr);
149
150 /// @notice Gets the keys with the value
151 /// @param value The bytes32 value of the pairs
152 /// @return arr The keys of the pairs
153 function getKeys(bytes32 value) external view returns (bytes32[] memory arr);
154
155 /// @notice Checks if the DB contains the key
156 /// @param key The key to check against
157 /// @return If the key exists
158 function hasKey(bytes32 key) external view returns (bool);
159
160 /// @notice Checks if the DB contains the value
161 /// @param value The value to check against
162 /// @return If the value exists
163 function hasValue(bytes32 value) external view returns (bool);
164
165 /// @notice Checks if the DB contains the pair
166 /// @param key The key of the pair
167 /// @param value The value of the pair
168 /// @return If the pair exists
169 function hasPair(bytes32 key, bytes32 value) external view returns (bool);
170}
171
172abstract contract DBV1Storage is ProxyOwnable, IDB {

Recommendation:

We advise all highlighted top-level declarations to be split into their respective code files, avoiding unnecessary imports as well as increasing the legibility of the codebase.

Alleviation (3dd3d7bf0c2693b2f9c23bacedfa420393f7ea84):

The DBV1Storage implementation was split to its dedicated file, rendering this exhibit applied in full.