Nibbl contest - defsec's results

NFT fractionalization protocol with guaranteed liquidity and price based buyout.

General Information

Platform: Code4rena

Start Date: 21/06/2022

Pot Size: $30,000 USDC

Total HM: 12

Participants: 96

Period: 3 days

Judge: HardlyDifficult

Total Solo HM: 5

Id: 140

League: ETH

Nibbl

Findings Distribution

Researcher Performance

Rank: 26/96

Findings: 2

Award: $60.10

🌟 Selected for report: 0

🚀 Solo Findings: 0

ISSUE LIST

C4-001: Missing events for only functions that change critical parameters - Non Critical
C4-002 : Critical changes should use two-step procedure - Non Critical
C4-003 : Pragma Version - Non Critical
C4-004 : Missing zero-address check in the setter functions and initiliazers - Low
C4-005 : Front-runnable Initializers - LOW
C4-006 : Direct usage of ecrecover allows signature malleability - LOW
C4-007 : Add disableInitializers to Prevent Front-running - LOW
C4-008 : Low level calls with solidity version 0.8.14 can result in optimiser bug. - LOW
C4-009 : Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom - Non-critical

ISSUES

C4-001 : Missing events for only functions that change critical parameters

Impact - Non critical

The afunctions that change critical parameters should emit events. Events allow capturing the changed parameters so that off-chain tools/interfaces can register such changes with timelocks that allow users to evaluate them and consider if they would like to engage/exit based on how they perceive the changes as affecting the trustworthiness of the protocol or profitability of the implemented financial services. The alternative of directly querying on-chain contract state for such changes is not considered practical for most users/usages.

Missing events and timelocks do not promote transparency and if such changes immediately affect users’ perception of fairness or trustworthiness, they could exit the protocol causing a reduction in liquidity which could negatively impact protocol TVL and reputation.

Proof of Concept

  1. Navigate to the following contract.
https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L485 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L158 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L140

See similar High-severity H03 finding OpenZeppelin’s Audit of Audius (https://blog.openzeppelin.com/audius-contracts-audit/#high) and Medium-severity M01 finding OpenZeppelin’s Audit of UMA Phase 4 (https://blog.openzeppelin.com/uma-audit-phase-4/)

Tools Used

None

Add events to all functions that change critical parameters.

C4-002 : Critical changes should use two-step procedure

Impact - NON CRITICAL

The critical procedures should be two step process.

Proof of Concept

  1. Navigate to the following contract.
https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L485

Tools Used

Code Review

Lack of two-step procedure for critical operations leaves them error-prone. Consider adding two step procedure on the critical functions.

C4-003 : # Pragma Version

Impact

In the contracts, floating pragmas should not be used. Contracts should be deployed with the same compiler version and flags that they have been tested with thoroughly. Locking the pragma helps to ensure that contracts do not accidentally get deployed using, for example, an outdated compiler version that might introduce bugs that affect the contract system negatively.

## Proof of Concept

https://swcregistry.io/docs/SWC-103

All Contracts

Tools Used

Manual code review

Lock the pragma version: delete pragma solidity 0.8.10 in favor of pragma solidity 0.8.10.

C4-004 : # Missing zero-address check in the setter functions and initiliazers

Impact

Missing checks for zero-addresses may lead to infunctional protocol, if the variable addresses are updated incorrectly.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L485 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L173 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L38 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L123

Tools Used

Code Review

Consider adding zero-address checks in the discussed constructors: require(newAddr != address(0));.

C4-005 : Front-runnable Initializers

Impact - LOW

All contract initializers were missing access controls, allowing any user to initialize the contract. By front-running the contract deployers to initialize the contract, the incorrect parameters may be supplied, leaving the contract needing to be redeployed.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L173 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/Basket.sol#L23 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L38
  1. initialize functions does not have access control. They are vulnerable to front-running.

Tools Used

Manual Code Review

While the code that can be run in contract constructors is limited, setting the owner in the contract's constructor to the msg.sender and adding the onlyOwner modifier to all initializers would be a sufficient level of access control.

C4-006 : Direct usage of ecrecover allows signature malleability

Impact

The permit function of NibblVault calls the Solidity ecrecover function directly to verify the given signatures. However, the ecrecover EVM opcode allows malleable (non-unique) signatures and thus is susceptible to replay attacks.

Although a replay attack seems not possible here since the nonce is increased each time, ensuring the signatures are not malleable is considered a best practice (and so is checking _signer != address(0), where address(0) means an invalid signature).

Proof of Concept

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L552

https://swcregistry.io/docs/SWC-117

https://swcregistry.io/docs/SWC-121

Tools Used

Code Review

Use the recover function from OpenZeppelin's ECDSA library for signature verification.

C4-007 : Add disableInitializers to Prevent Front-running

Impact

Defining initial values for variables when declaring them in a contract like in the code below does not work for upgradeable contracts.

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L173

Refer to explanation below:

https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#avoid-initial-values-in-field-declarations

Also, one should not leave the implementation contract uninitialized. None of the implementation contracts in the code base contains the code recommended by OpenZeppelin below, or an empty constructor with the initializer modifier.

Proof of Concept

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L173

Tools Used

Code Review

/// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); }

Refer to the link below:

https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializing_the_implementation_contract

C4-008 : Low level calls with solidity version 0.8.14 can result in optimiser bug.

Impact

The protocol is using low level calls with solidity version 0.8.14 which can result in optimizer bug.

https://medium.com/certora/overly-optimistic-optimizer-certora-bug-disclosure-2101e3f7994d

Proof of Concept

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L3

Tools Used

Code Review

Consider upgrading to solidity 0.8.15.

C4-009 : Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom

Impact - LOW

Impact

It is good to add a require() statement that checks the return value of token transfers or to use something like OpenZeppelin’s safeTransfer/safeTransferFrom unless one is sure the given token reverts in case of a failure. Failure to do so will cause silent failures of transfers and affect token accounting in contract.

Reference: This similar medium-severity finding from Consensys Diligence Audit of Fei Protocol: https://consensys.net/diligence/audits/2021/01/fei-protocol/#unchecked-return-value-for-iweth-transfer-call

Proof of Concept

  1. Navigate to the following contract.

  2. transfer/transferFrom functions are used instead of safe transfer/transferFrom on the following contracts.

contracts/Basket.sol::54 => IERC721(_token).transferFrom(address(this), _to, _tokenId); contracts/Basket.sol::80 => _to.transfer(address(this).balance); contracts/Basket.sol::87 => IERC20(_token).transfer(msg.sender, IERC20(_token).balanceOf(address(this))); contracts/Basket.sol::94 => IERC20(_tokens[i]).transfer(msg.sender, IERC20(_tokens[i]).balanceOf(address(this))); contracts/NibblVault.sol::517 => IERC20(_asset).transfer(_to, IERC20(_asset).balanceOf(address(this))); contracts/NibblVault.sol::526 => IERC20(_assets[i]).transfer(_to, IERC20(_assets[i]).balanceOf(address(this)));

Tools Used

Code Review

Consider using safeTransfer/safeTransferFrom or require() consistently.

#0 - HardlyDifficult

2022-07-04T15:49:58Z

A number of best practices highlighted here.

[S]: Suggested optimation, save a decent amount of gas without compromising readability;

[M]: Minor optimation, the amount of gas saved is minor, change when you see fit;

[N]: Non-preferred, the amount of gas saved is at cost of readability, only apply when gas saving is a top priority.

ISSUE LIST

C4-001: Revert String Size Optimization [S]
C4-002 : Adding unchecked directive can save gas [S]
C4-003 : Check if amount > 0 before token transfer can save gas [S]
C4-004 : There is no need to assign default values to variables [S]
C4-005 : Using operator && used more gas [S]
C4-006 : Non-strict inequalities are cheaper than strict ones [M]
C4-007 : Use Custom Errors instead of Revert Strings to save Gas [S]
C4-008 : Use Shift Right/Left instead of Division/Multiplication if possible [S]
C4-009 : Cache array length in for loops can save gas [S]
C4-010 : State Variables that can be changed to immutable [S]
C4-011 : Use calldata instead of memory for function parameters [M]
C4-012 : ++i is more gas efficient than i++ in loops forwarding
C4-013 : > 0 can be replaced with != 0 for gas optimization
C4-014 : Keccak functions in constants waste gas [M]
C4-015 : Free gas savings for using solidity 0.8.10+ [S]

C4-001: Revert String Size Optimization

Impact

Shortening revert strings to fit in 32 bytes will decrease deploy time gas and will decrease runtime gas when the revert condition has been met.

Revert strings that are longer than 32 bytes require at least one additional mstore, along with additional overhead for computing memory offset, etc.

Proof of Concept

Revert strings > 32 bytes are here:

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L141 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L149 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVaultFactory.sol#L166

Tools Used

Manual Review

Shorten the revert strings to fit in 32 bytes. That will affect gas optimization.

C4-002 : Adding unchecked directive can save gas

Impact

For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.

Proof of Concept

contracts/Basket.sol::43 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::70 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::93 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/NibblVault.sol::506 => for (uint256 i = 0; i < _assetAddresses.length; i++) { contracts/NibblVault.sol::525 => for (uint256 i = 0; i < _assets.length; i++) { contracts/NibblVault.sol::547 => for (uint256 i = 0; i < _assets.length; i++) {

Tools Used

None

Consider applying unchecked arithmetic where overflow/underflow is not possible. Example can be seen from below.

Unchecked{i++};

C4-003 : Check if amount > 0 before token transfer can save gas

Impact

Since _amount can be 0. Checking if (_amount != 0) before the transfer can potentially save an external call and the unnecessary gas cost of a 0 token transfer.

Proof of Concept

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L517 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L526 https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L569

All Contracts

Tools Used

None

Consider checking amount != 0.

C4-004 : There is no need to assign default values to variables

Impact - Gas Optimization

Boolean is default initialized to false. There is no need assign false to variable.

Proof of Concept

contracts/Bancor/BancorFormula.sol::285 => uint256 res = 0; contracts/Bancor/BancorFormula.sol::312 => uint8 res = 0; contracts/Bancor/BancorFormula.sol::369 => uint256 res = 0; contracts/Bancor/BancorFormula.sol::419 => uint256 res = 0; contracts/Bancor/BancorFormula.sol::460 => uint256 res = 0; contracts/Basket.sol::43 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::70 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::93 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/NibblVault.sol::506 => for (uint256 i = 0; i < _assetAddresses.length; i++) { contracts/NibblVault.sol::525 => for (uint256 i = 0; i < _assets.length; i++) { contracts/NibblVault.sol::547 => for (uint256 i = 0; i < _assets.length; i++) {

Tools Used

Code Review

bool x = false costs more gas than bool x without having any different functionality.

C4-005 : Using operator && used more gas

Impact

Using double require instead of operator && can save more gas.

Proof of Concept

  1. Navigate to the following contracts.
./contracts/Bancor/BancorFormula.sol:188: require(_supply > 0 && _connectorBalance > 0 && _connectorWeight > 0 && _connectorWeight <= MAX_WEIGHT); ./contracts/Bancor/BancorFormula.sol:219: require(_supply > 0 && _connectorBalance > 0 && _connectorWeight > 0 && _connectorWeight <= MAX_WEIGHT && _sellAmount <= _supply); ./contracts/NibblVaultFactory.sol:107: require(basketUpdateTime != 0 && block.timestamp >= basketUpdateTime, "NibblVaultFactory: UPDATE_TIME has not passed"); ./contracts/NibblVaultFactory.sol:131: require(feeToUpdateTime != 0 && block.timestamp >= feeToUpdateTime, "NibblVaultFactory: UPDATE_TIME has not passed"); ./contracts/NibblVaultFactory.sol:149: require(feeAdminUpdateTime != 0 && block.timestamp >= feeAdminUpdateTime, "NibblVaultFactory: UPDATE_TIME has not passed"); ./contracts/NibblVaultFactory.sol:166: require(vaultUpdateTime != 0 && block.timestamp >= vaultUpdateTime, "NibblVaultFactory: UPDATE_TIME has not passed");

Tools Used

Code Review

Example

using &&: function check(uint x)public view{ require(x == 0 && x < 1 ); } // gas cost 21630 using double require: require(x == 0 ); require( x < 1); } } // gas cost 21622

C4-006 : Non-strict inequalities are cheaper than strict ones

Impact

Strict inequalities add a check of non equality which costs around 3 gas.

Proof of Concept

contracts/NibblVault.sol::227 => if(_adminFeeAmt > 0) { contracts/NibblVault.sol::243 => if(_adminFeeAmt > 0) {

Tools Used

Code Review

Use >= or <= instead of > and < when possible.

C4-007 : Use Custom Errors instead of Revert Strings to save Gas

Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met)

Source Custom Errors in Solidity:

Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.

Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).

Instances include:

All require Statements

Tools Used

Code Review

Recommended to replace revert strings with custom errors.

C4-008 : Use Shift Right/Left instead of Division/Multiplication if possible

Impact

A division/multiplication by any number x being a power of 2 can be calculated by shifting log2(x) to the right/left.

While the DIV opcode uses 5 gas, the SHR opcode only uses 3 gas. Furthermore, Solidity's division operation also includes a division-by-0 prevention which is bypassed using shifting.

Proof of Concept

Contracts

contracts/Bancor/BancorFormula.sol::344 => uint8 mid = (lo + hi) / 2;

Tools Used

None

A division/multiplication by any number x being a power of 2 can be calculated by shifting log2(x) to the right/left.

C4-009 : Cache array length in for loops can save gas

Impact

Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.

Caching the array length in the stack saves around 3 gas per iteration.

Proof of Concept

  1. Navigate to the following smart contract line.
contracts/Basket.sol::43 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::70 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::93 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/NibblVault.sol::506 => for (uint256 i = 0; i < _assetAddresses.length; i++) { contracts/NibblVault.sol::525 => for (uint256 i = 0; i < _assets.length; i++) { contracts/NibblVault.sol::547 => for (uint256 i = 0; i < _assets.length; i++) {

Tools Used

None

Consider to cache array length.

C4-010 : State Variables that can be changed to immutable

Impact

Solidity 0.6.5 introduced immutable as a major feature. It allows setting contract-level variables at construction time which gets stored in code rather than storage.

Consider the following generic example:

contract C { /// The owner is set during contruction time, and never changed afterwards. address public owner = msg.sender; }

In the above example, each call to the function owner() reads from storage, using a sload. After EIP-2929, this costs 2100 gas cold or 100 gas warm. However, the following snippet is more gas efficient:

contract C { /// The owner is set during contruction time, and never changed afterwards. address public immutable owner = msg.sender; }

In the above example, each storage read of the owner state variable is replaced by the instruction push32 value, where value is set during contract construction time. Unlike the last example, this costs only 3 gas.

Code Location

https://github.com/NibblNFT/nibbl-smartcontracts/blob/master/contracts/NibblVault.sol#L60

Tools Used

None

Consider using immutable variable.

C4-011 : Use calldata instead of memory for function parameters

Impact

In some cases, having function arguments in calldata instead of memory is more optimal.

Consider the following generic example:

contract C { function add(uint[] memory arr) external returns (uint sum) { uint length = arr.length; for (uint i = 0; i < arr.length; i++) { sum += arr[i]; } } }

In the above example, the dynamic array arr has the storage location memory. When the function gets called externally, the array values are kept in calldata and copied to memory during ABI decoding (using the opcode calldataload and mstore). And during the for loop, arr[i] accesses the value in memory using a mload. However, for the above example this is inefficient. Consider the following snippet instead:

contract C { function add(uint[] calldata arr) external returns (uint sum) { uint length = arr.length; for (uint i = 0; i < arr.length; i++) { sum += arr[i]; } } }

In the above snippet, instead of going via memory, the value is directly read from calldata using calldataload. That is, there are no intermediate memory operations that carries this value.

Gas savings: In the former example, the ABI decoding begins with copying value from calldata to memory in a for loop. Each iteration would cost at least 60 gas. In the latter example, this can be completely avoided. This will also reduce the number of instructions and therefore reduces the deploy time cost of the contract.

In short, use calldata instead of memory if the function argument is only read.

Note that in older Solidity versions, changing some function arguments from memory to calldata may cause "unimplemented feature error". This can be avoided by using a newer (0.8.*) Solidity compiler.

Proof of Concept

  1. Navigate to the following smart contract line.
./contracts/Basket.sol:41: function withdrawMultipleERC721(address[] memory _tokens, uint256[] memory _tokenId, address _to) external override { ./contracts/Basket.sol:68: function withdrawMultipleERC1155(address[] memory _tokens, uint256[] memory _tokenIds, address _to) external override { ./contracts/Basket.sol:91: function withdrawMultipleERC20(address[] memory _tokens) external override { ./contracts/Basket.sol:99: function onERC721Received(address, address from, uint256 id, bytes memory) external override returns(bytes4) { ./contracts/Basket.sol:104: function onERC1155Received(address, address from, uint256 id, uint256 amount, bytes memory) external virtual override returns (bytes4) { ./contracts/Basket.sol:109: function onERC1155BatchReceived(address, address from, uint256[] memory ids, uint256[] memory amounts, bytes memory) external virtual override returns (bytes4) {

Tools Used

None

Some parameters in examples given above are later hashed. It may be beneficial for those parameters to be in memory rather than calldata.

C4-012 : ++i is more gas efficient than i++ in loops forwarding

Impact

++i is more gas efficient than i++ in loops forwarding.

Proof of Concept

  1. Navigate to the following contracts.
contracts/Basket.sol::43 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::70 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/Basket.sol::93 => for (uint256 i = 0; i < _tokens.length; i++) { contracts/NibblVault.sol::506 => for (uint256 i = 0; i < _assetAddresses.length; i++) { contracts/NibblVault.sol::525 => for (uint256 i = 0; i < _assets.length; i++) { contracts/NibblVault.sol::547 => for (uint256 i = 0; i < _assets.length; i++) {

Tools Used

Code Review

It is recommend to use unchecked{++i} and change i declaration to uint256.

C4-013 : > 0 can be replaced with != 0 for gas optimization

Impact

!= 0 is a cheaper operation compared to > 0, when dealing with uint.

Proof of Concept

  1. Navigate to the following contract sections.
contracts/NibblVault.sol::227 => if(_adminFeeAmt > 0) { contracts/NibblVault.sol::243 => if(_adminFeeAmt > 0) {

Tools Used

None

Consider to replace > 0 with != 0 for gas optimization.

C4-014 : Keccak functions in constants waste gas

Impact

The contracts assigns two constants to the result of a keccak operation, which results in gas waste since the expression is computed each time the constant is accessed.

See this issue for more context: ethereum/solidity#9232 (https://github.com/ethereum/solidity/issues/9232)

Proof of Concept

contracts/NibblVault.sol::51 => bytes32 private constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); contracts/NibblVault.sol::562 => bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)); contracts/NibblVaultFactory.sol::50 => _proxyVault = payable(new ProxyVault{salt: keccak256(abi.encodePacked(_curator, _assetAddress, _assetTokenID, _initialSupply, _initialTokenPrice))}(payable(address(this)))); contracts/NibblVaultFactory.sol::70 => bytes32 newsalt = keccak256(abi.encodePacked(_curator, _assetAddress, _assetTokenID, _initialSupply, _initialTokenPrice)); contracts/NibblVaultFactory.sol::72 => bytes32 _hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), newsalt, keccak256(code))); contracts/NibblVaultFactory.sol::81 => address payable _basketAddress = payable(new ProxyBasket{salt: keccak256(abi.encodePacked(_curator, _mix))}(basketImplementation)); contracts/NibblVaultFactory.sol::89 => bytes32 newsalt = keccak256(abi.encodePacked(_curator, _mix)); contracts/NibblVaultFactory.sol::91 => bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), newsalt, keccak256(code))); contracts/Utilities/AccessControlMechanism.sol::12 => bytes32 public constant FEE_ROLE = keccak256("FEE_ROLE"); contracts/Utilities/AccessControlMechanism.sol::13 => bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); contracts/Utilities/AccessControlMechanism.sol::14 => bytes32 public constant IMPLEMENTER_ROLE = keccak256("IMPLEMENTER_ROLE"); contracts/Utilities/EIP712Base.sol::7 => bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256( contracts/Utilities/EIP712Base.sol::16 => domainSeperator = keccak256( contracts/Utilities/EIP712Base.sol::19 => keccak256(bytes(name)), contracts/Utilities/EIP712Base.sol::20 => keccak256(bytes(version)), contracts/Utilities/EIP712Base.sol::46 => keccak256(

Tools Used

None

Replace the constant directive with immutable, or assign the already hashed value to the constants.

C4-015 : Free gas savings for using solidity 0.8.10+

Impact

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks are available for free.

Proof of Concept

All Contracts

Solidity 0.8.10 has a useful change which reduced gas costs of external calls which expect a return value: https://blog.soliditylang.org/2021/11/09/solidity-0.8.10-release-announcement/

Solidity 0.8.13 has some improvements too but not well tested.

Code Generator: Skip existence check for external contract if return data is expected. In this case, the ABI decoder will revert if the contract does not exist

All Contracts

Tools Used

None

Consider to upgrade pragma to at least 0.8.10.

#0 - mundhrakeshav

2022-06-26T09:34:15Z

#2, #3, #6, #8, #9,

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter