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

optimize _beforeTokenTransfer #19

Open
code423n4 opened this issue Aug 22, 2021 · 0 comments
Open

optimize _beforeTokenTransfer #19

code423n4 opened this issue Aug 22, 2021 · 0 comments

Comments

@code423n4
Copy link
Contributor

Handle

gpersoon

Vulnerability details

Impact

The function _beforeTokenTransfer of RCNftHubL2 can be optimized for gas. This will save the users gas on all future NFT transfers.
See Recommended Mitigation Steps for a suggestion.

Proof of Concept

//https://github.com/code-423n4/2021-08-realitycards/blob/main/contracts/nfthubs/RCNftHubL2.sol#L204
function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override(ERC721Enumerable, ERC721) {
super._beforeTokenTransfer(from, to, tokenId);

    if ( msgSender() != address(factory) &&  msgSender() != marketTracker[tokenId] ) {
        IRCMarket market = IRCMarket(marketTracker[tokenId]);
        require(market.state() == IRCMarket.States.WITHDRAW || market.state() == IRCMarket.States.LOCKED, "Incorrect state" );
    }
}

Tools Used

Recommended Mitigation Steps

Use something like the following code:
IRCMarket market = IRCMarket(marketTracker[tokenId]);
if (msgSender() != address(factory) && msgSender() != address(market)) {
IRCMarket.States mstate=market.state();
require(mstate == IRCMarket.States.WITHDRAW || mstate == IRCMarket.States.LOCKED,"Incorrect state");
}
}

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Aug 22, 2021
code423n4 added a commit that referenced this issue Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants