Platform: Code4rena
Start Date: 28/09/2023
End Date: 04/10/2023
Period: 6 days
Status: Completed
Pot Size: $36,500 USDC
Participants: 115
Reporter: PaperParachute
Judge: 0xDjango
Id: 290
League: ETH
Testerbot | 1/115 | $10,783.76 | 5 | 3 | 0 | 1 | 1 | Grade B | 0 | 0 |
0xDetermination | 2/115 | $1,161.45 | 6 | 3 | 0 | 1 | 0 | Grade A | 0 | Grade B |
Brenzee | 3/115 | $983.50 | 3 | 2 | 0 | 0 | 0 | Grade B | 0 | 0 |
ether_sky | 4/115 | $859.90 | 3 | 2 | 0 | 0 | 0 | Grade B | 0 | 0 |
SpicyMeatball | 5/115 | $855.53 | 2 | 2 | 0 | 0 | 0 | 0 | 0 | 0 |
Breeje | 6/115 | $853.09 | 4 | 1 | 0 | 1 | 0 | Grade B | 0 | Grade A |
tapir | 7/115 | $814.28 | 3 | 2 | 0 | 1 | 0 | 0 | 0 | 0 |
santipu_ | 8/115 | $786.38 | 3 | 2 | 0 | 0 | 0 | Grade B | 0 | 0 |
0xTheC0der | 9/115 | $719.26 | 2 | 1 | 0 | 0 | 0 | Grade A | 0 | 0 |
sces60107 | 10/115 | $689.32 | 2 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
Auditor per page
Automated findings output for the audit can be found here within 24 hours of audit opening.
Note for C4 wardens: Anything included in the automated findings output is considered a publicly known issue and is ineligible for awards.
Owners and admins will be the Normal timelock contract, that is part of the Governance protocol.
Regarding authorization, we'll use the AccessControlManager
(ACM) deployed at https://bscscan.com/address/0x4788629abc6cfca10f9f969efdeaa1cf70c23555
In this ACM, only 0x939bd8d64c0a9583a7dcea9933f7b21697ab6396 (Normal timelock) has the DEFAULT_ADMIN_ROLE. And this contract is a Timelock contract use during the Venus Improvement Proposals.
There are two other Timelock contracts to execute VIP's with a shorter delay:
calculateAPR()
Does Not Update OracleThe function _calculateUserAPR()
does not update the oracle for the input market or xvsToken. Thus the oracle will not update the pivot oracle price before calculating a users capital for their score.
We assume that prices will be updated often during other operations. It’s a view function, therefore, we consider the security risk to be lower. Finally, the update in the Resilient Oracle only affects the TWAP oracle, and the Resilient Oracle has mechanisms to revert the transaction if the data is too old
According to the logic of function accrueInterest()
, it is possible that some rewards will not be collected by any user. If rewards are currently being issued, but no user has a positive score, then no user can collect these rewards. Even so, all currently unreleased funds issued can be sent from both PrimeLiquidityProvider
and ProtocolShareReserve
to the Prime
contract by anyone. Since no user is privy to these funds, they will become stuck in the contract.
Prime tokens will be issued at the same time (same transaction) the Prime contracts are enabled, so the described scenario will not happen.
The FixedMath0x.sol implements the natural logarithm approximating the result with a Taylor series. Known issues:
e
(e^-32
, e^-16
, etc.), are not as precise as they could be.-63.875
, but the true minimum that can be reached is approximately -88.Venus Protocol is excited to announce Venus Prime, a revolutionary incentive program aimed to bolster user engagement and growth within the protocol. An integral part of Venus Tokenomics v3.1, Venus Prime aims to enhance rewards and promote $XVS staking, focusing on markets including USDT, USDC, BTC and ETH.
Venus Prime's uniqueness lies in its self-sustaining rewards system, instead of external sources, rewards are derived from the protocol's revenue, fostering a sustainable and ever-growing program.
Eligible $XVS holders will receive a unique, non-transferable Soulbound Token, which boosts rewards across selected markets.
Main contracts in the scope of the contest:
Prime. Soulbound token that will allow holders to accrue rewards, generated with part of the income of some markets in the Venus Protocol. Regular users have to stake 1,000 XVS at least during 90 days to be eligible for a Prime token, that users will be able to claim as soon as they satisfy the constraint. After claiming their Prime token, the rewards start to be accrued and Prime holders will be able to claim them when they want.
Libs Scores, FixedMath and FixedMath0x. Used in the calculations needed to accrue rewards for Prime holders.
PrimeLiquidityProvider. The second source of tokens for the Prime program (the first one are the Venus markets) will be this contract: PrimeLiquidityProvider
. It will allow to define a fixed amount of tokens to be distributed uniformly to the Prime holders for a period of time.
Integration with other contracts in the Venus Protocol:
accrueInterestAndUpdateScore
.xvsUpdated
is invoked, to review the requirements of Prime holders.Review this document for a more detailed and technical explanation of Venus Prime.
Anything not listed in the table above is out of scope, specifically:
Blockchains where this code will be deployed: BNB Chain, Ethereum mainnet, Arbitrum, Polygon zkEVM, opBNB.
- If you have a public code repo, please share it here: https://github.com/VenusProtocol/venus-protocol/tree/sbt - How many contracts are in scope?: 7 - Total SLoC for these contracts?: 1039 - How many external imports are there?: 7 - How many separate interfaces and struct definitions are there for the contracts within scope?: 10 - Does most of your code generally use composition or inheritance?: Composition - How many external calls?: 20 - What is the overall line coverage percentage provided by your tests?: 96% - Is this an upgrade of an existing system?: True; Venus Prime is a new token claimable by users who satisfy some constraints in terms of XVS staked (we'll upgrade the XVSVault implementation) and interactions with the markets (we'll upgrade the Comptroller implementation of the Venus Core pool) - Check all that apply (e.g. timelock, NFT, AMM, ERC20, rollups, etc.): Non ERC-20 Token - Is there a need to understand a separate part of the codebase / get context in order to audit this part of the protocol?: Yes - Please describe required context: ProtocolSharedReserve (PSR) contract (https://github.com/VenusProtocol/protocol-reserve/tree/develop/contracts/ProtocolReserve) is one of the contracts that will distribute funds to the Venus Prime tokens. Funds are sent to the PSR contract in an automatic way from the Venus markets, and part of these funds are sent to the Venus Prime tokens on demand. In Comptroller (specifically in the [PolicyFacet](https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Comptroller/Diamond/facets/PolicyFacet.sol)), after executing any operation that could impact the Prime score or interest, we accrue the interest and update the score for the prime user by calling `accrueInterestAndUpdateScore`. In the [XVSVault](https://github.com/code-423n4/2023-09-venus/blob/main/contracts/XVSVault/XVSVault.sol), after depositing or requesting a withdrawal, the function `xvsUpdated` is invoked, to review the requirements of Prime holders. - Does it use an oracle?: Yes; https://github.com/VenusProtocol/oracle - Under the hood this is an extra layer on top of Chainlink, Binance oracle, Pyth network and TWAP oracle, allowing the comparison of values returned to decide if they are valid or not - Describe any novel or unique curve logic or mathematical models your code uses: Not novel, but the Venus Prime boosts yields based on the Cobb-Douglas function, inspired by the Goldfinch rewards mechanism - Is this either a fork of or an alternate implementation of another project?: False - Does it use a side-chain?: False - Describe any specific areas you would like addressed: Please try to break the accounting (the rewards allocated to each user based on their behaviour)
To run venus, pull the repository from GitHub and install its dependencies. You will need yarn or npm installed.
git clone https://github.com/code-423n4/2023-09-venus cd 2023-09-venus yarn install # or `npm install`
Contract tests are defined under the tests directory. To run the tests run:
yarn test # for the full repository
npx hardhat test tests/hardhat/Prime/*.ts tests/hardhat/integration/index.ts # only for the Prime contracts
FORK_MAINNET=true
and BSC_ARCHIVE_NODE_URL
in the .env
file.REPORT_GAS=true
.To run code coverage, run:
yarn coverage # for the full repository
npx hardhat coverage --testfiles "tests/hardhat/Prime/*.ts" # only for the Prime contracts
To lint the code, run:
yarn lint
To format the code, run:
yarn prettier