Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uint256 Implementation Check
Preface
This PR, in reference to #52 , includes test cases that attempt to break the ERC20 implementation (at the time of this writing). It should be understood that inserting overflowing arguments in functions such as
approve()
andincrease_allowance()
will not return an error because of said overflow. Prior to reaching the uint256 arithmetic functions, which include a check on the uint256 values themselves, these values simply overflow. For example: if you attempt to callapprove()
with the arguments2**128 + 2, 0
, the transaction will not revert because the value is interpreted as1, 0
. This does not break the ERC20 implementation because the integers overflow prior to reaching the ERC20 state.Summary
This PR includes three tests that check for potential vulnerabilities regarding overflow in respect to ERC20 functions accepting uint256 arguments from Cairo's Uint256 library.
decrease_allowance()
proves to be the most straight-forward function to check. The function is displayed below for reference.Notice, the
enough_allowance
check occurs aftercurrent_allownace - subtracted_value
. If the ERC20 implementation can be corrupted, this particular spot is the most vulnerable. The test first approvesMAX_AMOUNT
(2**256 - 1), and then proceeds to test whether our implementation will behave in an unsuspecting manner via single felt overflows. This test fails each iteration of overflowing parameters.Further, this PR also includes the same type of test for
transfer()
andtransfer_from()
. Being that their respective function logic has a few more moving parts thandecrease_allowance()
, it seemed apropos to include them. Perhaps, testingdecrease_allowance()
is enough for the sake of brevity.Implementation
--
2^128 - 1, 2^128
--
2^128, 2^128 - 1
--
0, 2^128 + 2
--
2^128 + 2, 0