Part of CertiK’s series
CertiK reviewed Venus Protocol (Venus - Multichain Governance) on 26 Feb 2024: 29 findings, 0 critical; 24 marked fixed, 5 open.
Report hosted on skynet.certik.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed |
|---|---|---|---|
| Critical | 0 | 0 | 0 |
| High | 2 | 0 | 0 |
| Medium | 0 | 0 | 1 |
| Low | 3 | 0 | 23 |
The function `execute()` does not follow check-effect-interact and the transactions executed may make external calls allowing for potential reentrancy. In particular, if there is more than one proposal queued, then this can allow a second proposal to be executed in the middle of the execution of another proposal. Considering the proposal executed in the middle of the other proposal can execute privileged actions that may not have been accounted for, this could cause potential harm to the protocol.
In the functions `cancelTransaction()` and `executeTransaction()` the keyword `delete` can be used in place of setting `queuedTransactions[txHash]` to false.
In function `_nonblockingLzReceive()`, the `newProposal.id` value is used as a key in the `proposals` mapping. The `newProposal.id` is the `pId`; the mapping can be set using the `pId` as the key instead.
Function `execute()` allows a message to be executed with a `msg.value` of 0, which may lead to a failed message. Such a message may need to be removed, but cannot be removed via function `fallbackWithdraw()`, due to the requirement that `originalValue_` input is nonzero. As a result, a failed message of this kind may become stuck in `OmnichainProposalSender`.
While the `nonreentrant` modifier and access restriction can prevent reentrancy, we recommend following check-effect-interaction wherever possible as added protection and best practice.
Function `_isEligibleToSend()` is used as a check in function `execute()`. However, if the proposal is not properly executed, it gets stored, and the execution can be retried at a later time. The checks made in `_isEligibleToSend()` are based on a 24-hour window. If the second attempts are made outside the 24 hour window in which the execution was initially tried, then it is possible that the number of proposals exceeds the limit during the retry. Additionally, note that when proposal messages are retried, it may result in two proposals sent during the same `block.timestamp`, a scenario that is supposed to be prevented by function `_isEligibleToSend()`.
The event `SetMaxDailyLimit` should include the chain id to make it easier to track which chain's limit is being updated.
In the function `upsertSignature()` there is the following logic: ```solidity if (active_[i] && signature.length == 0) { functionRegistry[sigHash] = signatures_[i]; emit FunctionRegistryChanged(signatures_[i], active_[i]); } ``` However, if this if-block is executed then necessarily `active_[i]` is true so that the emitted event can use `true` as opposed to reading the value. Similarly in the following logic: ```solidity else if (!active_[i] && signature.length != 0) { delete functionRegistry[sigHash]; emit FunctionRegistryChanged(signatures_[i], active_[i]); } ``` If this if-block is executed then necessarily `active_[i]` is false so that the emitted event can use `false` as opposed to reading the value.
The payload that is sent or stored at `storedExecutionHashes[_pId]` in the `execute()` function includes a second layer of encoding the pId with the initial `payload_`. The parameter comment in functions `retryExecute()` and `fallbackWithdraw()` here makes it seem as if the original `payload_` input in function `execute()` should be used again; this will result in a revert. The comments could either be rewritten to accurately specify the extra layer of encoding, or else this encoding step could be done within the logic to ensure the check will come out correctly when comparing the hashes. The parameter `payload_` in the comments above `estimateFees()`, `retryExecute()` and `fallbackWithdraw()` are also missing the inclusion of the `proposalType` at the end of the encoding.
In general, the counter in a for loop can be incremented or decremented in an unchecked block as it cannot overflow or underflow, saving gas as it will not perform a check for overflow or underflow. Additionally, it saves a small amount of gas to increment an index in a `for` loop from the left instead of from the right side as it performs fewer operations. ### OmnichainGovernanceExecutor.sol - In function `addTimelocks()`, incrementing variable `i` can be incremented in an `unchecked` block. - In function `execute()`, incrementing variable `i` can be incremented in an `unchecked` block. - In function `cancel()`, incrementing variable `i` can be - incremented in an `unchecked` block; - incremented from the left; - implicitly initialized at 0, it does not need to be set to 0 explicitly; - In function `_queue()`, incrementing variable `i` can be incremented in an `unchecked` block. ### OmnichainExecutorOwner.sol - In function `upsertSignature()`, incrementing variable `i` can be - incremented in an `unchecked` block; - incremented from the left;
One or more parameters with `memory` data location are never modified in their functions and those functions are never called internally within the contract. Thus, their data location can be changed to `calldata` to avoid the gas consumption copying from calldata to memory.
The interface `IOmnichainGovernanceExecutor` in `OmnichainExecutorOwner` can be defined in a separate file so that it is easier for future projects to import them and avoid duplication.
The mapping `validChainIds` is used to determine if an input remote chain id is valid. However, the address of the contract on the remote chain to receive messages sent by this contract should only be set if the remote chain is valid. Only `setTrustedRemoteAddress()` is implemented and there is no method such as `setTrustedRemote()` that can set set it to the default empty path. Thus once set `trustedRemoteLookup[remoteChainId_].length` will always be nonzero. `validChainIds` can then invalidate a remote chain in the event that the remote address was set and it needs to be removed as a valid chain. Alternatively, `validChainIds` can be removed and instead the `setTrustedRemote()` method (see [here](https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/lzApp/LzApp.sol)) can be implemented so that in the event that a remote chain should be invalidated `trustedRemoteLookup[remoteChainId_]` can be set to the empty path and the check ```solidity require(trustedRemote.length != 0, "OmnichainProposalSender: destination chain is not a trusted source"); ``` would always ensure that the remote chain is valid. --- Function `retryExecute()` should include a relevant check based on the above to ensure the input `remoteChainId_` is still allowed at the time of the second attempt.
### BaseOmnichainControllerDest - There are no comments above the function `_isEligibleToReceive()`. ### BaseOmnichainControllerSrc - There are no comments above the function `_isEligibleToSend()`. - There are no comments above the function `_ensureAllowed()`. ### OmnichainProposalSender - In function `execute()` there is a missing natspec comment specifying the access restriction of the function ### OmnichainGovernanceExecutor - There are no comments above the function `_blockingLzReceive()`. - There are no comments above the function `_nonblockingLzReceive()`. - There are no comments above the function `_queue()`. - There are no comments above the function `_queueOrRevertInternal()`. ### OmnichainExecutorOwner - The comments above the `fallback()` function do not mention the access restriction, input, or return value. ### ITimelock - The comments above `executeTransaction()` do not include a description of the return value. ### TimelockV8 - The comments above `setDelay()` do not mention the emitted event or access restriction. - There are no comments above the functions `GRACE_PERIOD()`, MINIMUM_DELAY()`, `MAXIMUM_DELAY()`, or `getBlockTimestamp()`. - The comments above `acceptAdmin()` do not mention the emitted event or access restriction. - The comments above `setPendingAdmin()` do not mention the emitted event or access restriction. - The comments above `queueTransaction()` do not mention the emitted event or access restriction. - The comments above `cancelTransaction()` do not mention the emitted event or access restriction. - The comments above `executeTransaction()` do not mention the emitted event, access restriction, or return value. - The comments above `queueTransaction()` do not mention the emitted event or access restriction.
While it is understood that the in-scope `TimelockV8` contract and `OmnichainProposalSender` work together with the `OmnichainGovernanceExecutor` contract to ensure the proper intended behavior in proposal queuing, execution, and cancellation, the following checks should be added to the `OmnichainGovernanceExecutor` contract in order to ensure correct functioning in the event the timelock contracts are updated through `addTimelocks()`. For instance, if the timelocks are ever updated, in the current `OmnichainGovernanceExecutor` contract, the fact that previously executed `proposals` remained set to `true` in `queued` may potentially allow for the possibility of replaying the execution of a proposal, since there are no checks within the `OmnichainGovernanceExecutor` contract to ensure the proposal has not already been executed or cancelled. Additionally, currently there should be only one source chain providing proposals, so it is assumed that all incoming `pId` values have not previously been set. However, the `OmnichainGovernanceExecutor` contract has a mapping to keep track of limits for multiple source chains (`chainIdToMaxDailyReceiveLimit`). In the event that multiple source chains send proposals, the `pId` method may no longer be unique. Checks are suggested below in order to ensure the `OmnichainGovernanceExecutor` and `TimelockV8` contracts can function properly, independent of one another. ### OmnichainGovernanceExecutor.sol - Function `execute()` is missing a check ensuring that `proposal.executed` is previously false before updating it to true. - Function `execute()` is missing a check ensuring that `proposal.cancelled` is false before executing it. - Function `execute()` should update `queued[proposalId_]` to false as part of the logic. - Function `cancel()` is missing a check ensuring that `proposal.cancelled` is false before executing it. - Function `cancel()` should update `queued[proposalId_]` to false as part of the logic. - Function `_nonblockingLzReceive()` is missing a check ensuring that `proposals[pId]` is not already set before updating it. - Function `_queue()` is missing a check ensuring that `queued[proposalId_]` is false before setting it to true. ### TimelockV8.sol - Function `queueTransaction()` is missing a check ensuring that `queuedTransactions[txHash]` is false before updating it to true. - Function `cancelTransaction()` is missing a check ensuring that `queuedTransactions[txHash]` is true before updating it to false.
Function `retryExecute()` can be called by anyone, because there is a check ensuring the payload entered was one previously attempted at execution, but which failed. In `retryExecute()`, the refund is directed to go to the `msg.sender` currently making the call, even though the account that initially providing the `msg.value` was the account that called function `execute()`. The account attempting `retryExecute()` may not be the original account that called `execute()`, since this function is free to be called by anyone. It is possible that, in the original call to `execute()`, a large `msg.value` was included, with the idea being any difference would be refunded; it is possible that the execution fails for some other reason besides insufficient fees, however. In such a case, someone may watch for such a failure and attempt to call `retryExecute()` with the opportunity to seize the refund, which may be significant. Additionally, a low-level call is made to the refund recipient when sending the refund, and this is done before all logic has been completed by the endpoint. This may pose a system-reentrancy risk.
In the events cited, it may be beneficial for on-chain reference to include the previous value of the updated state variable.
Many of the added files use specific imports, however, some import the entire file.
### BaseOmnichainControllerSrc.sol - The comments above the contract `BaseOmnichainControllerSrc` have an additional "*" before the security-contact. - In the comments above function `setMaxDailyLimit()`, parameter `limit_` is not representing an amount in USD. - In the comments above function `setMaxDailyLimit()`, there is stray notation ")." included at the end of line `@param limit_`. - The comment in function `_isEligibleToSend()` states multiple commands cannot be sent for a `dstChainId_` within a proposal, but this is allowed; it is that multiple proposals cannot be sent within the same `block.timestamp`. ### BaseOmnichainControllerDest.sol - In the comments above function `setMaxDailyReceiveLimit()`, parameter `limit_` is not representing an amount in USD. - in the comments above function `setMaxDailyReceiveLimit()` the parameter `@param chainId_` says it is representing the destination chain ID, but it is actually representing source chain id. ### ITimelock.sol - In each of the comments cited above, the word "signature" is misspelled as "Ssignature."
Function `fallbackWithdraw()` is a privileged function used to remove failed proposals that cannot be executed. The function includes a `payable` casting, even though it must be used to remove proposals and remove the corresponding amount of funds from the contract. If the `_owner` includes a `msg.value` with the call, then this amount could become stuck in the contract, since it does not correspond to a proposal.
The `proposal.proposalType` is already `uint8` type, it is not necessary to cast it explicitly.
Function `fallbackWithdraw()` includes the following check: ```solidity require(address(this).balance >= originalValue_, "OmnichainProposalSender: insufficient native balance"); ``` This check is unnecessary because it is checked that `keccak256(execution) == hash`, meaning that the `originalValue_` included as part of the `hash` construction was sent to the contract but currently has not successfully been transferred out.
The logic contract `OmnichainExecutorOwner` does not protect its initializer function. An attacker can call the initializer and assume ownership of the logic contract, whereby she can perform privileged operations that trick unsuspecting users into believing that she is the owner of the upgradeable contract.
### OmnichainGovernanceExecutor - In the function `execute()`, `proposalTimelocks[uint8(proposal.proposalType)]`, `proposal.targets.length`, and `proposal.eta` can be stored in a temporary variable to avoid being repeatedly read from storage. - In the function `_queue`, `proposal.proposalType` can be stored in a temporary variable to avoid being repeatedly read from storage. - In the function `cancel()`, `proposalTimelocks[proposal.proposalType]`, `proposal.targets.length`, and `proposal.eta` can be stored in a temporary variable to avoid being repeatedly read from storage. - In the function `_queue()`, `proposal.targets.length` and `proposal.proposalType` can be stored in a temporary variable to avoid being repeatedly read from storage.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (7)
1,045 projects reviewed · 1,376 reports · latest May 2025
See CertiK’s auditsSomething wrong on this page? A missing report, a wrong date, a finding that was fixed since. Tell us and we check it against its source.
Tell us