Platform: Code4rena
Start Date: 05/09/2023
End Date: 11/09/2023
Period: 6 days
Status: Completed
Pot Size: $50,000 USDC
Participants: 16
Reporter: liveactionllama
Judge: GalloDaSballo
Id: 284
League: ETH
ladboy233 | 1/16 | $17,158.88 | 2 | 0 | 0 | 1 | 1 | Grade B | 0 | 0 |
d4r3d3v1l | 2/16 | $17,118.75 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
DadeKuma | 3/16 | $1,118.51 | 2 | 0 | 0 | 0 | 0 | Grade A | 0 | Grade A |
pfapostol | 4/16 | $927.61 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | Grade A |
Sathish9098 | 5/16 | $586.41 | 1 | 0 | 0 | 0 | 0 | 0 | Grade A | 0 |
Baki | 6/16 | $451.09 | 1 | 0 | 0 | 0 | 0 | 0 | - | 0 |
p0wd3r | 7/16 | $311.51 | 1 | 0 | 0 | 0 | 0 | Grade A | 0 | 0 |
Banditx0x | 8/16 | $216.92 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | Grade B |
m4ttm | 9/16 | $216.92 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | Grade B |
sces60107 | 10/16 | $40.13 | 1 | 0 | 0 | 0 | 0 | Grade B | 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.
This contest covers two key pieces:
The delegate registry is a standalone singleton database that aggregates onchain programmable access control. Users can link cold wallets to hot wallets, or specify individual token rights to delegate to other wallets. This separation of asset utility from the asset owner is a powerful primitive that enables the delegate marketplace. The delegate marketplace lets users wrap delegation rights into ERC721 tokens that can then be traded or transferred in the same way as any other NFT. The primary use-case here is utility rentals with zero counterparty risk, zero liquidation risk, zero overcollateralization requirements, and an order of magnitude greater capital efficiency.
v1 of the delegate registry has been live across many EVM chains since September 2022. While v1 is not in scope, auditors are encouraged to review its usage patterns at https://etherscan.io/address/0x00000000000076a84fef008cdabe6409d2fe638b. A frontend interface across all deployed chains and testnets can be used at https://delegate.xyz. The v2 registry is similar to v1, although with expanded support for fungible token amounts, cleaner enumeration methods, multicall transaction batching, gas efficiency improvements, and the introduction of subdelegation rights. Documentation for v1 can be found at https://docs.delegate.xyz.
The delegate marketplace consists of three core contracts: the DelegateToken, the PrincipalToken, and the CreateOfferer. Users will deposit a token, such as a bored ape NFT, into smart contract escrow using the DelegateToken.sol::create() function. They will receive back two ERC721s: a bored ape DelegateToken, and a bored ape PrincipalToken. The holder of the DelegateToken will receive delegate rights for the duration of the escrow. The holder of the PrincipalToken will have the right to redeem the bored ape from escrow at conclusion of the chosen timeframe. Users can choose to transfer or sell neither, one, or both of these. The CreateOfferer is a Seaport Contract Offerer that enables gasless listing of DelegateTokens which have not been created yet. If a buyer fulfills the gasless listing, then the desired token will be atomically escrowed and a DelegateToken created.
Contract | SLOC | Purpose | Libraries used |
---|---|---|---|
lib/delegate-registry/src/DelegateRegistry.sol | 364 | v2 of the delegate registry | ??? |
lib/delegate-registry/src/libraries/RegistryHashes.sol | 135 | Helper library for registry hash calculation | ??? |
lib/delegate-registry/src/libraries/RegistryStorage.sol | 31 | Helper library for registry storage layout | ??? |
lib/delegate-registry/src/libraries/RegistryOps.sol | 18 | Helper library for branchless boolean ops | ??? |
src/DelegateToken.sol | 288 | Represent delegate rights as a transferrable ERC721 | ??? |
src/PrincipalToken.sol | 43 | Represent the rights to claim the deposited token as a transferrable ERC721 | ??? |
src/CreateOfferer.sol | 171 | Seaport Contract Offerer to enable gasless listings of DTs before they're created | ??? |
src/libraries/CreateOffererLib.sol | 267 | Helper library for CreateOfferer | ??? |
src/libraries/DelegateTokenLib.sol | 90 | Helper library for DelegateToken | ??? |
src/libraries/DelegateTokenRegistryHelpers.sol | 219 | Helper library for Delegate Token registry hitchhiking | ??? |
src/libraries/DelegateTokenStorageHelpers.sol | 125 | Helper library for Delegate Token registry hitchhiking | ??? |
src/libraries/DelegateTokenTransferHelpers.sol | 73 | Helper library for Delegate Token ERC20/721/1155 transfers | ??? |
The following contracts are out of scope:
- If you have a public code repo, please share it here: - How many contracts are in scope?: 12 - Total SLoC for these contracts?: ~1500 - How many external imports are there?: 2 - 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?: ~5 - What is the overall line coverage percentage provided by your tests?: 80% - Is this an upgrade of an existing system?: True - Check all that apply (e.g. timelock, NFT, AMM, ERC20, rollups, etc.): ERC-20 Token, 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?: False - Please describe required context: n/a - Does it use an oracle?: No - Describe any novel or unique curve logic or mathematical models your code uses: None - 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 focus on registry correctness as that intersects with the marketplace
Either clone with --recurse
:
git clone --recurse https://github.com/code-423n4/2023-09-delegate.git
Use one of the following if --recurse
was forgotten:
git submodule update --init --recursive forge install
Be sure to run foundryup
:
foundryup
# Run marketplace tests forge test # Run registry tests cd lib/delegate-registry && forge test && cd ../.. # Run registry gas benchmarks cd lib/delegate-registry && forge test --match-contract GasBenchmark --gas-report > gasbenchmark10mil && forge test --match-contract HashBenchmark --gas-report > hashbenchmark10mil && cd ../..
To run Slither, use the following command:
mv test _test slither . mv _test test