You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all sick proposal 👏👏👏, just thought I would suggest some gas optimizations.
These custom errors aren't really needed, and increase gas since an unnecessary conditional check is needed to throw the error. In both transfer and transferFrom the checked arithmetic would throw a revert regardless of the conditional. The same applies to the InsufficientPermission check within transferFrom.
/// @dev Thrown when owner balance for id is insufficient./// @param owner The address of the owner./// @param id The id of the token.error InsufficientBalance(addressowner, uint256id);
/// @dev Thrown when spender allowance for id is insufficient./// @param spender The address of the spender./// @param id The id of the token.error InsufficientPermission(addressspender, uint256id);
/// @notice Transfers an amount of an id from the caller to a receiver./// @param receiver The address of the receiver./// @param id The id of the token./// @param amount The amount of the token.function transfer(addressreceiver, uint256id, uint256amount) public {
if (balanceOf[msg.sender][id] < amount) revertInsufficientBalance(msg.sender, id);
balanceOf[msg.sender][id] -= amount;
balanceOf[receiver][id] += amount;
emitTransfer(msg.sender, receiver, id, amount);
}
You can also use unchecked when modifying the receivers balance since totalSupply cannot exceed 2**256-1. Checkout transmissions/solmate/tokens/ERC20.sol for reference.
The text was updated successfully, but these errors were encountered:
so the reference implementation is meant more for readability and making the specification explicit. so tradeoffs were made in favor of readability over gas efficiency.
would you mind moving the optimized implementation to the alt/ directory? it can take the name of ERC6909Optimized.sol. from there we can make further optimizations and stray further from readability.
First of all sick proposal 👏👏👏, just thought I would suggest some gas optimizations.
transfer
andtransferFrom
the checked arithmetic would throw a revert regardless of the conditional. The same applies to theInsufficientPermission
check withintransferFrom
.unchecked
when modifying the receivers balance sincetotalSupply
cannot exceed 2**256-1. Checkouttransmissions/solmate/tokens/ERC20.sol
for reference.The text was updated successfully, but these errors were encountered: