Omniscia DAFI Protocol Audit

BscBridgeOptimized Code Style Findings

BscBridgeOptimized Code Style Findings

BBO-01C: Inexistent Error Message

TypeSeverityLocation
Code StyleInformationalBscBridgeOptimized.sol:L179

Description:

The linked require check has no error message explicitly defined.

Example:

contracts/BscBridgeOptimized.sol
179require(sig.length == 65);

Recommendation:

We advise it to be set so to aid in the validation of the require's condition as well as the legibility of the codebase.

Alleviation:

A proper error message was introduced for the linked require instance.

BBO-02C: Redundant keccak256 Re-Execution

TypeSeverityLocation
Gas OptimizationInformationalBscBridgeOptimized.sol:L128, L138, L139, L146

Description:

The linked statements perform the keccak256 operation on the same payload multiple times redundantly.

Example:

contracts/BscBridgeOptimized.sol
123function mintTokens(
124 bytes32 messageHash,
125 bytes calldata message,
126 bytes[] calldata claimedSig
127) external {
128 if (txStore[keccak256(message)] == true) revert DoubleClaimDetected();
129 if (message.length <= 32) revert InvalidMessage();
130 (
131 uint256 amount,
132 uint256 _nonce,
133 uint32 chainID,
134 address to
135 ) = abi.decode(message, (uint256, uint256, uint32, address));
136
137 if (chainID !=block.chainid) revert InvalidChainID(chainID,uint32(block.chainid));
138 if (messageHash != prefixed(keccak256(message)))
139 revert HashMismatched(messageHash, prefixed(keccak256(message)));
140 //signature check
141 if (signaturesVerifier(claimedSig, messageHash) == true)
142 _mintTokens(amount,
143 _nonce,
144 chainID,
145 to,
146 keccak256(message));
147}

Recommendation:

We advise the operation to be performed once, stored in-memory and consequently utilized to optimize the code.

Alleviation:

The code has been optimized according to our recommendation caching the keccak256(message) operation.

BBO-03C: Suboptimal Conditionals

TypeSeverityLocation
Gas OptimizationInformationalBscBridgeOptimized.sol:L82, L104

Description:

The linked conditionals negate a comparator and as such can be optimized by moving the negation to the comparator itself (i.e. !(a > 0) becomes (a <= 0) or (a == 0) if a is guaranteed to be positive).

Example:

contracts/BscBridgeOptimized.sol
104if (!(amount > 0)) revert ZeroAmount();

Recommendation:

We advise this to be done so to simplify the code and optimize its gas cost.

Alleviation:

The code was optimized only for the last linked instance thereby partially alleviating this exhibit.

BBO-04C: Variable Mutability Specifiers

TypeSeverityLocation
Gas OptimizationInformationalBscBridgeOptimized.sol:L36, L37, L54, L55

Description:

The linked variables are assigned to only once during the contract's constructor.

Example:

contracts/BscBridgeOptimized.sol
44constructor(
45 address[] memory _validators,
46 address _BSCTOKEN,
47 address _owner,
48 uint256 _multiSigThreshold
49) {
50 if (_multiSigThreshold < 2)
51 revert ThresholdNotMet(_multiSigThreshold, 2);
52
53 threshold = _multiSigThreshold;
54 BSCTOKEN = _BSCTOKEN;
55 owner = _owner;
56 for (uint256 i = 0; i < _validators.length; i++) {
57 validators[_validators[i]] = true;
58 }
59}

Recommendation:

We advise them to be set as immutable greatly optimizing the codebase.

Alleviation:

Both linked variables were properly set as immutable optimizing the codebase.