In the OWPIdentity.sol contract, the internal function _update overrides the ERC1155 _update function. The overriding function includes a require check that uses a logical OR operator to impose restrictions. However, this check is ambiguous and could lead to unnecessary or meaningless logic, making the contract potentially inefficient.
The OWPIdentity::_update function includes the following code:
The require statement checks whether either the from or to address is address(0). While this check might seem reasonable at first glance, it is problematic because it is based on an incorrect assumption. According to the ERC-1155 standard, the _update function is called in scenarios such as minting, transferring, and burning tokens. In none of these operations should both from and to be the zero address (address(0)), meaning the require condition is essentially redundant and not applicable in any valid scenario.
The issue arises due to the short-circuiting behavior in Boolean logic. In computer science, when using a logical OR (||) operator, if the first condition evaluates to true, the second condition is not evaluated at all. This is because the overall expression is already guaranteed to be true once one of the conditions is met. As a result, the second condition is effectively skipped, and control proceeds to the next line of code.
The following is a proof of concept demonstrating the short-circuiting behavior in logical operations. This is a Foundry test, so please make sure you are using Foundry to run it.
Create the test file
Add the following test to any test file of your choice.
Run the Test
Open your terminal and execute the following command to run the test:
Review the Logs
After running the test, you should see output similar to the following in your terminal:
As demonstrated in the log output, short-circuiting behavior is in action. When the first condition in the logical OR (address(1) == address(1)) evaluates to true, the second condition (address(2) == address(2)) is not evaluated. This is a clear example of short-circuiting, which prevents unnecessary computations and ensures that only the first condition's result is used to determine the outcome.
In this case:
The variable isNotShortCircuit is set to true, as expected from the first condition.
The variable intoFalseOfNotShortCircuit remains false, as the second condition is not evaluated.
This demonstrates the short-circuiting phenomenon in action, which is fundamental to understanding how logical operators work in Solidity and most programming languages.
Inefficient Code: The check require(from == address(0) || to == address(0), "OWPIdentity: NFT Not transferrable.") introduces unnecessary logic. It is impossible for both from and to to be address(0) in normal token operations (minting, transferring, burning). The inclusion of this check causes needless gas usage and adds complexity without providing any real security or validation.
Meaningless Event Emissions: If both from and to were somehow set to address(0) (which is not possible in typical use cases), the require statement would allow the function to proceed, leading to a meaningless event emission (either TransferSingle or TransferBatch) that could confuse developers and users, and clutter event logs.
Ambiguity: The logic used in this check is ambiguous and could create confusion for developers reviewing the code, as the condition contradicts the intended flow of ERC-1155 token operations.
Manual Code Review
The require condition should be revised to make it more explicit and logically sound. The intent appears to be to restrict token transfers or operations to only minting (when from == address(0)) or burning (when to == address(0)). Therefore, the require condition should be updated as follows:
This revised condition ensures that:
Tokens can only be minted (when from == address(0) and to != address(0)).
Tokens can only be burned (when to == address(0) and from != address(0)).
Any other transfer scenario will be blocked, preventing unnecessary logic and improving code clarity.
By making this adjustment, the contract will be more efficient, readable, and aligned with the intended ERC-1155 behavior.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.