Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeArena] - [G-06/N-12] : Require messages shorten to fit in 32 bytes #48

Merged
merged 1 commit into from
Dec 2, 2021

Conversation

adrien-supizet
Copy link
Contributor

@adrien-supizet adrien-supizet commented Dec 2, 2021

I found that there is no advantage to using less than 32 bytes for a require reason, but using more will cost an extra 32 at once.

I've looked at 3 options:

  1. shorten all the require messages to make them fit in 32 bytes
  2. use codes to describe errors, and have an index in the doc / or comments in natspec
  3. use CustomError

-> I've chosen option 1. By using initials instead of contract names, and rewriting some messages, the data now fit in 32 bytes.

  • 1 vs 2: Error messages are explicit enough, we can add documentation or natspec comments if needed but there is no point to name an error FS004 like we mentioned as this will take as much gas as naming it with an explicit name
  • 1 vs 3: Using CustomError is more gas efficient, as we can use codes to make the string fit in 4 bytes. Although this require us to declare every single error possible in the code, and add conditions to throw the errors. IMO the code becomes less readable.

Issues =>

@adrien-supizet adrien-supizet added the To review Let people know this PR is ready for a review label Dec 2, 2021
@maximebrugel maximebrugel changed the title require messages shorten to fit in 32 bytes [CodeArena] - Issue 14 : Require messages shorten to fit in 32 bytes Dec 2, 2021
@@ -60,7 +60,7 @@ abstract contract MixinOperatorResolver {
/// @return The operator address
function requireAndGetAddress(bytes32 name) internal view returns (address) {
address _foundAddress = addressCache[name];
require(_foundAddress != address(0), string(abi.encodePacked("Missing operator : ", name)));
require(_foundAddress != address(0), string(abi.encodePacked("MOR: Missing operator : ", name)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe MOR: MISSING_OPERATOR ?

@@ -50,15 +50,15 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
/// @dev Reverts the transaction if the caller is not the token owner
/// @param _nftId The NFT Id
modifier onlyTokenOwner(uint256 _nftId) {
require(nestedAsset.ownerOf(_nftId) == _msgSender(), "NestedFactory: Not the token owner");
require(nestedAsset.ownerOf(_nftId) == _msgSender(), "NF: CALLER_IS_NOT_THE_OWNER");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the _IS_ and _THE_=> NF: CALLER_NOT_OWNER

_;
}

/// @dev Reverts the transaction if the nft is locked (hold by design).
/// The block.timestamp must be greater than NFT record lock timestamp
/// @param _nftId The NFT Id
modifier isUnlocked(uint256 _nftId) {
require(block.timestamp > nestedRecords.getLockTimestamp(_nftId), "NestedFactory: The NFT is currently locked");
require(block.timestamp > nestedRecords.getLockTimestamp(_nftId), "NF: NFT_IS_LOCKED");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove _IS_ => NF: LOCKED_NFT

@maximebrugel maximebrugel added Fix and merge Minor changes required and removed To review Let people know this PR is ready for a review labels Dec 2, 2021
@adrien-supizet adrien-supizet merged commit 48a2c66 into codearena Dec 2, 2021
@adrien-supizet adrien-supizet deleted the codearena-14 branch December 2, 2021 13:58
@maximebrugel maximebrugel changed the title [CodeArena] - Issue 14 : Require messages shorten to fit in 32 bytes [CodeArena] - [G-06] : Require messages shorten to fit in 32 bytes Dec 8, 2021
@maximebrugel maximebrugel changed the title [CodeArena] - [G-06] : Require messages shorten to fit in 32 bytes [CodeArena] - [G-06/N-12] : Require messages shorten to fit in 32 bytes Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix and merge Minor changes required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants