GithubHelp home page GithubHelp logo

Comments (8)

cygaar avatar cygaar commented on July 4, 2024 3

Agree with @ahbanavi here, implementing contracts should handle reentrancy. We want to stick as close as possible to the original ERC721 implementation

from erc721a.

cygaar avatar cygaar commented on July 4, 2024 3

Hmm that's a good point, however I think we want to err on the safe side and not make any assumptions on this: "In most cases, if a contract can receive one token, it can receive all". If the community feels strongly about only checking onERC721Received at the end of the batch we can revisit this. Feel free to open a separate issue for that so we can close this one out @jpegdigital

from erc721a.

ahbanavi avatar ahbanavi commented on July 4, 2024 2

I think the implementing contracts should handle reentrancy, as many contracts (like Azuki) block minting from other contracts in the first place and therefore there's no reentrancy problem (correct me if I'm wrong).
So a warning in _safeMint specs or in the docs I think is enough, and we should keep ERC721A implementation close to the original.

from erc721a.

jpegdigital avatar jpegdigital commented on July 4, 2024

In terms of solutions/alternatives, I've been thinking of three options for my project:

  1. Remove _safeMint() all together as handing off control to another contract is risky in this 2022 minting environment.
  2. Call _checkOnERC721Received() only once for the final token (ensures state is fully updated). Or maybe creating a new _checkOnERC721ReceivedBatch standard.
  3. Ignore and advise implementing contracts to use reentrancy blockers.

from erc721a.

Vectorized avatar Vectorized commented on July 4, 2024

Good points. Looks like balance and the number minted can become inconsistent.

Perhaps a simple check like this could help:

uint256 startTokenId = _currentIndex;
...
for (uint256 i; i < quantity; i++) {
       ...
}
// Prevents reentrancy
if (safe && _currentIndex != startTokenId) revert();
_currentIndex = updatedIndex;

The compiler could optimize it away if safe is always false, but otherwise the gas overhead should be minimal.

from erc721a.

jpegdigital avatar jpegdigital commented on July 4, 2024

What do y'all think about calling _checkOnERC721Received() only once then at the end of the batch? It could be called with start tokenId (or end) and pass the quantity via the _data parameter?

Thoughts on why this would be appropriate:

  1. Ensures contract state is consistent before handing off control.
  2. EIP-721 states The ERC721 smart contract calls this function on the recipient after a transfer which could be interpreted to be called just once during a batch.
  3. Main purpose of safe functions is to ensure receiving contracts can handle NFTs and won't be permanently lost. In most cases, if a contract can receive one token, it can receive all.

from erc721a.

kyokosdream avatar kyokosdream commented on July 4, 2024

We followed @cygaar suggestion and added OZ re-entrancy guard to applicable functions in our contract which implements ERC721A. I agree that this should not be included in ERC721A. ERC721A is designed to add a batch minting API to ERC721 and remove unnecessary gas consumption caused by ERC721Enumerable.

EDIT: I've learned more about the difference between _safeMint and _mint and am swapping our calls from the former to the latter and will wait for the #131 pull to be merged.

from erc721a.

Vectorized avatar Vectorized commented on July 4, 2024

Fixed in #131 . Can be closed.

from erc721a.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.