Omniscia 0xPhase Audit
IDB Code Style Findings
IDB Code Style Findings
IDB-01C: Multiple Top-Level Declarations
Type | Severity | Location |
---|---|---|
Code Style | IDB.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 NAND32 }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 pair65 /// @param key The key to add66 /// @param value The value to add67 function add(bytes32 key, bytes32 value) external;68
69 /// @notice Adds a key value pair70 /// @param key The key to add71 /// @param value The value to add72 function add(bytes32 key, address value) external;73
74 /// @notice Sets a key value pair75 /// @param key The key to set76 /// @param value The value to set77 function set(bytes32 key, bytes32 value) external;78
79 /// @notice Sets a key value pair80 /// @param key The key to set81 /// @param value The value to set82 function set(bytes32 key, address value) external;83
84 /// @notice Adds a list of keys with a value pairs85 /// @param keys The keys to add86 /// @param value The value to add87 function add(bytes32[] memory keys, bytes32 value) external;88
89 /// @notice Adds a list of keys with a value pairs90 /// @param keys The keys to add91 /// @param value The value to add92 function add(bytes32[] memory keys, address value) external;93
94 /// @notice Adds a key with a list of value pairs95 /// @param key The key to add96 /// @param values The values to add97 function add(bytes32 key, bytes32[] memory values) external;98
99 /// @notice Adds a key with a list of value pairs100 /// @param key The key to add101 /// @param values The values to add102 function add(bytes32 key, address[] memory values) external;103
104 /// @notice Removes all pairs with the key and the key itself105 /// @param key The key to remove106 function removeKey(bytes32 key) external;107
108 /// @notice Removes all pairs with the value and the value itself109 /// @param value The value to remove110 function removeValue(bytes32 value) external;111
112 /// @notice Removes a pair113 /// @param key The key to remove114 /// @param value The value to remove115 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 DB118 /// @dev digest() is not meant to be used on-chain due to the high gas cost119 /// @param opcode The opcode to execute120 /// @return result The execution result for every value121 function digest(122 Opcode memory opcode123 ) external view returns (bytes32[] memory result);124
125 /// @notice Gets the first value with the key126 /// @param key The key of the pair127 /// @return The bytes32 representation of the value128 function getValueB32(bytes32 key) external view returns (bytes32);129
130 /// @notice Gets the first value with the key131 /// @param key The key of the pair132 /// @return The bytes32 representation of the value133 function getValue(string memory key) external view returns (bytes32);134
135 /// @notice Gets the first value with the key136 /// @param key The key of the pair137 /// @return The address representation of the value138 function getAddressB32(bytes32 key) external view returns (address);139
140 /// @notice Gets the first value with the key141 /// @param key The key of the pair142 /// @return The address representation of the value143 function getAddress(string memory key) external view returns (address);144
145 /// @notice Gets the values with the key146 /// @param key The key of the pairs147 /// @return arr bytes32 representations of the values148 function getValues(bytes32 key) external view returns (bytes32[] memory arr);149
150 /// @notice Gets the keys with the value151 /// @param value The bytes32 value of the pairs152 /// @return arr The keys of the pairs153 function getKeys(bytes32 value) external view returns (bytes32[] memory arr);154
155 /// @notice Checks if the DB contains the key156 /// @param key The key to check against157 /// @return If the key exists158 function hasKey(bytes32 key) external view returns (bool);159
160 /// @notice Checks if the DB contains the value161 /// @param value The value to check against162 /// @return If the value exists163 function hasValue(bytes32 value) external view returns (bool);164
165 /// @notice Checks if the DB contains the pair166 /// @param key The key of the pair167 /// @param value The value of the pair168 /// @return If the pair exists169 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.