Security Audit
February 14, 2023
Version 1.0.0
Presented by 0xMacro
This document includes the results of the security audit for Nori's smart contract code as found in the section titled ‘Source Code’. The security audit was performed by the Macro security team from January 9, 2022 to January 13, 2022.
The purpose of this audit is to review the source code of certain Nori 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 |
---|---|---|---|---|
Medium | 1 | - | - | 1 |
Low | 2 | - | - | 2 |
Code Quality | 4 | - | - | 4 |
Informational | 1 | - | - | - |
Nori 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:
eadef34ee4f9fc55753559e3d845f4453befe773
Specifically, we audited the following contracts within this repository:
Source Code | SHA256 |
---|---|
contracts/Certificate.sol |
|
contracts/Errors.sol |
|
contracts/ICertificate.sol |
|
contracts/IMarket.sol |
|
contracts/IRemoval.sol |
|
contracts/IRestrictedNORI.sol |
|
contracts/Market.sol |
|
contracts/Removal.sol |
|
contracts/RestrictedNORI.sol |
|
Note: This document contains an audit solely of the Solidity contracts listed above. Specifically, the audit pertains only to the contracts themselves, and does not pertain to any other programs or scripts, including deployment scripts.
Click on an issue to jump to it, or scroll down to see them all.
Certificate
is missing accounting to indicate current backing of Removals
purchasingToken.transferFrom()
return value is not checked
_fulfillOrder()
and _fulfillOrderWithoutFee()
could be combined
Math
library for uint256
instead of the upgradable version.
purchasingTokenAddress
and priceMultiple
_permit()
function can have functionality extended
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. |
Market.sol currently allows for RestrictedNORI
to fail to be minted for a supplier if their address is not ERC1155 compatible during the Removal purchasing workflow (see the try catch block in the fulfillOrderXXX()
functions). Nori’s plan is to allow for suppliers to have the failed-to-be-minted RestrictedNORI minted to a different address for the suppliers.
This plan isn’t currently achievable with the code as written. RestrictedNORI.sol doesn’t allow for RestrictedNORI to be minted to an arbitrary address as the mint()
function on line 451 pulls the receiver for the mint from the removalID
's encoding:
address supplierAddress = RemovalIdLib.supplierAddress({
removalId: removalId
});
super._mint({to: supplierAddress, id: projectId, amount: amount, data: ""});
Remediations to Consider:
Adding a function to RestrictedNORI.sol with a parameter for the mint receiver.
Note: we’d also like to recommend that this function only be able to mint the amount of RestrictedNORI which corresponds to the amount of RestrictedNORI which failed to be minted in the Market.sol workflow. This could be achieved by recording in RestrictedNORI.sol the amount of RestrictedNORI that should’ve been minted during the catch of the try-catch blocks. This would promote safer accounting and prevent Nori from accidentally minting too-much RestrictedNORI for a supplier.
Ensuring that suppliers are aware that they should use addresses which are able to handle ERC1155 tokens.
Certificate
is missing accounting to indicate current backing of Removals
Nori’s Certificate contract is intended to show that the Certificate-NFTs are backed by Removals. Currently, there isn’t a way to easily validate on-chain that the Certificate contract is properly backed.
For example, after release events occur which release Removals that were backing the Certificates, it’s hard to show that the Certificate contract is no longer properly backed. This will make it harder to show in the future, once replacement logic is written, that the Certificate contract and its Certificate-NFTs are once again properly backed.
Remediations to consider:
purchasingToken.transferFrom()
return value is not checked
There is no guarantee that the IERC20WithPermit _purchasingToken
will inherit OZ’s ERC20 which reverts
on failure to transfer. The transfer could be unsuccessful and return false, and the recipient will still be minted a Certificate token even though the removal was not successfully purchased.
Checking return values is a good practice to prevent unforeseeable situations, like USDC upgrading their contracts to an implementation which returns false instead of reverting.
Remediations to Consider:
_purchasingToken.transferFrom()
so that suppliers are guaranteed to receive their earned tokens and the recipient is not minted a Certificate token that is unearned._fulfillOrder()
and _fulfillOrderWithoutFee()
could be combined
The only difference between the two functions is the following in the without-fee variant on lines 1326-1330:
_purchasingToken.transferFrom({
from: from,
to: _noriFeeWallet,
amount: this.calculateNoriFee(removalAmounts[i])
});
Remediations to consider:
certificateAmount
instead of on the individual supplier removal amounts. This would allow the _fulfillOrder()
logic to be re-used.Math
library for uint256
instead of the upgradable version.
Remediations to consider:
MathUpgradeable
library instead.purchasingTokenAddress
and priceMultiple
In Certificate.sol, there are 2 functions that are missing comments regarding purchasingTokenAddress
and priceMultiple
:
_receieveRemovalBatch()
recipient
, certificateAmount
, removalsIds
, removalAmounts
, purchasingTokenAddress
, and priceMultiple
as parameters. However, there are missing Natspec @param
tags for purchasingTokenAddress
and priceMultiple
.onERC1155BatchReceived()
data
as a parameter which encodes recipient
, certificateAmount
, purchasingTokenAddress
, and priceMultiple
. However, the Natspec comment does not mention the purchasingTokenAddress
or priceMultiple
, and instead states: @param data The bytes that encode the certificate's recipient address and total amount.
Remediations to consider:
purchasingTokenAddress
and priceMultiple
.RestrictedNORI.sol’s documentation states:
It is possible to create more than one schedule per owner address and also to transfer full or partial restricted balances between addresses.
However, restricted Nori token transfers are disabled as of this update.
Remediation to Consider:
_permit()
function can have functionality extended
Currently, Market.sol’s _permit()
function requires that the transaction initiator also be the signer of the signed message:
_purchasingToken.permit({
owner: _msgSender(),
spender: address(this),
value: amount,
deadline: deadline,
v: v,
r: r,
s: s
});
This design is slightly different from the typical use cases of signed messages. Many projects allow signed messages to be submitted by accounts other than the message signer to enable other parties to (1) pay for gas costs and (2) allow for other custom business logic.
Nori could use this pattern to enable things like allowing other parties to fund buyers’ gas costs or enabling other accounts besides the MARKET_ADMIN_ROLE
to fund the no-fee swap endpoints.
Note, that if this approach is introduced, it should be communicated to users that if they sign messages with the Market contract as the spender of the purchasing tokens, that the user is giving permission for a purchase to be made with the amount of permitted token in Market.sol.
We took your advice!
commits: 0b859b4f5712525a02decb9ee05bdcc6a628f056, a8a17a90801531f64379f56428b08c28adf32a29
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 Nori 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.