Security Audit
June 26th, 2023
Version 1.0.0
Presented by 0xMacro
This document includes the results of the security audit for Citadel's smart contract code as found in the section titled ‘Source Code’. The security audit was performed by the Macro security team from June 26, 2023 to June 30, 2023.
The purpose of this audit is to review the source code of certain Citadel Solidity contracts, and provide feedback on the design, architecture, and quality of the source code with an emphasis on validating the correctness and security of the software in its entirety.
Disclaimer: While Macro’s review is comprehensive and has surfaced some changes that should be made to the source code, this audit should not solely be relied upon for security, as no single audit is guaranteed to catch all possible bugs.
The following is an aggregation of issues found by the Macro Audit team:
Severity | Count | Acknowledged | Won't Do | Addressed |
---|---|---|---|---|
Low | 2 | - | - | 2 |
Code Quality | 5 | - | - | 5 |
Gas Optimization | 1 | - | - | 1 |
Citadel was quick to respond to these issues.
Our understanding of the specification was based on the following sources:
The following source code was reviewed during the audit:
9ebe18a32355596febc46931c16ab601eaff9a7a
71531ab6d239a90dc019f1177648da6949dc2ab7
271e65eda4e8bd8eb299baf2f27899aafa9b8f1f
3c473bba216968f00b7e214526cd01cc6590a7ea
26a29f397a2ddbff662630e4005a69cd8ebf054c
Specific changes (PR#19) to add alternate auth system
./src/
Contract | SHA256 |
---|---|
src/auth/dc/DelegateCashStrategy.sol |
|
src/auth/dc/IDelegationRegistry.sol |
|
src/auth/self/SelfAuthStrategy.sol |
|
src/auth/session/ISessionStrategy.sol |
|
src/auth/session/IWMATIC.sol |
|
src/auth/session/SessionStrategy.sol |
|
src/auth/session/WMATIC.sol |
|
src/auth/AuthCompatible.sol |
|
src/auth/AuthManager.sol |
|
src/auth/BaseAuthCompatible.sol |
|
src/auth/IAuthManager.sol |
|
src/auth/IAuthStrategy.sol |
|
src/game/access/AccessControlFacet.sol |
|
src/game/access/AccessControlPrivileged.sol |
|
src/game/auth/AuthFacet.sol |
|
src/game/auth/AuthPrivileged.sol |
|
src/game/auth/IAuth.sol |
|
src/game/common/CommonPrivileged.sol |
|
src/game/glue/GlueFacet.sol |
|
src/game/upgrades/UpgradesPrivileged.sol |
|
src/game/GameInit.sol |
|
src/game/IGame.sol |
|
Specific changes (PR#20) use separate contracts for the ship token and genesis sale
./src/
Contract | SHA256 |
---|---|
src/ships/genesis/DutchAuctionSale.sol |
|
src/ships/ERC721C.sol |
|
src/ships/IERC721C.sol |
|
src/ships/IMetadataLib.sol |
|
src/ships/IShips.sol |
|
src/ships/MetadataLib.sol |
|
src/ships/Ships.sol |
|
src/ships/ShipsMock.sol |
|
Specific changes (PR#21) to add setContractURI to ships to reduce the necessity for upgrades
./src/
Contract | SHA256 |
---|---|
src/ships/Ships.sol |
|
Specific changes (PR#23) to make existing events more normalized, add some missing events that may be useful
./src/
Contract | SHA256 |
---|---|
src/auth/AuthManager.sol |
|
src/auth/IAuthManager.sol |
|
src/game/belts/BeltsPrivileged.sol |
|
src/game/belts/IBelts.sol |
|
src/game/common/CommonPrivileged.sol |
|
src/game/common/ICommon.sol |
|
src/game/glue/GlueFacet.sol |
|
src/game/glue/IGlue.sol |
|
src/game/outposts/IOutposts.sol |
|
src/game/rewards/IRewards.sol |
|
src/game/rewards/RewardsPrivileged.sol |
|
src/game/travel/ITravel.sol |
|
src/game/travel/TravelPrivileged.sol |
|
src/game/upgrades/IUpgrades.sol |
|
src/game/upgrades/UpgradesPrivileged.sol |
|
src/governance/CitadelGovernor.sol |
|
src/ships/genesis/DutchAuctionSale.sol |
|
Specific changes (PR#24) to fix audit report findings
./src/
Contract | SHA256 |
---|---|
src/base/util/IStructs.sol |
|
src/game/belts/BeltsPrivileged.sol |
|
src/game/rewards/RewardsPrivileged.sol |
|
src/game/travel/ITravel.sol |
|
src/game/travel/TravelFacet.sol |
|
src/game/travel/TravelPrivileged.sol |
|
src/game/upgrades/UpgradesPrivileged.sol |
|
Click on an issue to jump to it, or scroll down to see them all.
We quantify issues in three parts:
This third part – the severity level – is a summary of how much consideration the client should give to fixing the issue. We assign severity according to the table of guidelines below:
Severity | Description |
---|---|
(C-x) Critical |
We recommend the client must fix the issue, no matter what, because not fixing would mean significant funds/assets WILL be lost. |
(H-x) High |
We recommend the client must address the issue, no matter what, because not fixing would be very bad, or some funds/assets will be lost, or the code’s behavior is against the provided spec. |
(M-x) Medium |
We recommend the client to seriously consider fixing the issue, as the implications of not fixing the issue are severe enough to impact the project significantly, albiet not in an existential manner. |
(L-x) Low |
The risk is small, unlikely, or may not relevant to the project in a meaningful way. Whether or not the project wants to develop a fix is up to the goals and needs of the project. |
(Q-x) Code Quality |
The issue identified does not pose any obvious risk, but fixing could improve overall code quality, on-chain composability, developer ergonomics, or even certain aspects of protocol design. |
(I-x) Informational |
Warnings and things to keep in mind when operating the protocol. No immediate action required. |
(G-x) Gas Optimizations |
The presented optimization suggestion would save an amount of gas significant enough, in our opinion, to be worth the development cost of implementing it. |
The SessionStrategy:endSession()
emits SessionEnded
event with delegate
and vault
arguments in an incorrect order.
emit SessionEnded(delegate, _session.account, remaining);
In emission, a delegate
is 1st and the vault
is the 2nd argument. However, in the event declaration vault
is 1st and delegate
is 2nd argument.
event SessionEnded(address vault, address delegate, uint256 fundingReturned);
Remediations to Consider:
In SessionStrategy.sol
's, all endSession()
calls with zero allowance won’t emit the corresponding SessionEnded
event.
**if** (remaining == 0) **return**;
...
emit SessionEnded(delegate, _session.account, remaining);
remaining
could be zero if:
delegate
spends all the allowed wrapped MATIC.delegate
did not have any registered session.Remediations to Consider:
If no targets/calldatas parameters are sent into the sendCalls function call, the transaction will still succeed and emit CallsSent event, even if no calls were executed. Consider checking whether at least one function input (targets.length and calldatas.length) is provided.
BeltPublished
event should have beltId
indexed.CallsSent
event should have strategy
, vault
, delegate
indexed.SessionStarted
and SessionEnded
events should have vault
and delegate
indexed.Natspec comments missing for strategy param in CallsSent
event declaration in IAuthManager
Missing Natspec comments on state variables in the interface ISessionStrategy
In ISessionStrategy.sol
the following structs do not have any natspec comments. Consider adding natspec comments so it’s clear what these structs are meant to track.
struct TargetPair {
address target;
bytes4 selector;
}
struct Session {
address account;
uint32 endTime;
}
Typo in the IAuthStrategy.isAllowed()
Natspec comment
@notice
tag, where vault
is typed as value
Missing Natspec for IERC721C:addressInfoOf()
function.
Missing Natspec comments for safeMintBatch()
in the interface IShips
.
In SessionStrategy, startSession() will approve and deposit the difference between the msg.value and the input parameter sessionGasFunding. However, if only the sessionGasFunding value was provided in the call, the logic will still execute the external calls to the wrapped MATIC contract will zero values. To avoid unnecessary external calls, consider only calling the wrapped external contract if msg.value - sessionGasFunding > 0.
In DutchAuctionSale:initialization() function, there is no call to __ReentrancyGuard_init(). While this does not affect system operation, when inheriting from upgradable contracts such asReentrancyGuardUpgradeable, consider calling appropriate initializers to set their corresponding state.
In DelegateCashRegistry
, isAllowed()
has following implementation:
function isAllowed(
address delegate,
address vault,
address[] memory targets,
bytes[] memory
) external view returns (bool) {
for (uint256 i = 0; i < targets.length; i++) {
if (
!delegationRegistry.checkDelegateForContract(
delegate,
vault,
targets[i]
)
) return false;
}
return true;
}
Since the result of the call doesn’t depend on the calldata but only on the address of the target contract, due to batching use case, it is probable that many targets will be the same contract address. In that case, an external call for each is unnecessary and can be avoided with function-level caching.
Macro makes no warranties, either express, implied, statutory, or otherwise, with respect to the services or deliverables provided in this report, and Macro specifically disclaims all implied warranties of merchantability, fitness for a particular purpose, noninfringement and those arising from a course of dealing, usage or trade with respect thereto, and all such warranties are hereby excluded to the fullest extent permitted by law.
Macro will not be liable for any lost profits, business, contracts, revenue, goodwill, production, anticipated savings, loss of data, or costs of procurement of substitute goods or services or for any claim or demand by any other party. In no event will Macro be liable for consequential, incidental, special, indirect, or exemplary damages arising out of this agreement or any work statement, however caused and (to the fullest extent permitted by law) under any theory of liability (including negligence), even if Macro has been advised of the possibility of such damages.
The scope of this report and review is limited to a review of only the code presented by the Citadel team and only the source code Macro notes as being within the scope of Macro’s review within this report. This report does not include an audit of the deployment scripts used to deploy the Solidity contracts in the repository corresponding to this audit. Specifically, for the avoidance of doubt, this report does not constitute investment advice, is not intended to be relied upon as investment advice, is not an endorsement of this project or team, and it is not a guarantee as to the absolute security of the project. In this report you may through hypertext or other computer links, gain access to websites operated by persons other than Macro. Such hyperlinks are provided for your reference and convenience only, and are the exclusive responsibility of such websites’ owners. You agree that Macro is not responsible for the content or operation of such websites, and that Macro shall have no liability to your or any other person or entity for the use of third party websites. Macro assumes no responsibility for the use of third party software and shall have no liability whatsoever to any person or entity for the accuracy or completeness of any outcome generated by such software.