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

imp(erc20): adjust erc20 authorizations handling #2012

Merged
merged 26 commits into from Nov 9, 2023

Conversation

MalteHerrmann
Copy link
Contributor

@MalteHerrmann MalteHerrmann commented Nov 7, 2023

Description

This PR adjusts the way the ERC20 precompile handles the authorizations. Most notably, it's now possible to extend pre-existing send authorizations with different denominations instead of having them overwritten with always just one denom. Additionally, over and underflows are checked for approvals & increasing/decreasing allowances.


Closes ENG-2289

Copy link

linear bot commented Nov 7, 2023

ENG-2289 Rework authorization handling

Context

Currently, the authorization mechanism is implemented in a way that only approvals for one token denomination are handled. The discussion around this was held on PR #2005.

Expected

Adjust the authorization handling to allow approvals for multiple denominations.

  • Approve multiple denominations without overwriting prior approvals in other denoms
  • Increase/Decrease Allowance should not overwrite other denom approvals
  • When deleting an allowance only the one of the given denom should be deleted, not all.

@MalteHerrmann MalteHerrmann marked this pull request as ready for review November 7, 2023 15:38
@MalteHerrmann MalteHerrmann requested a review from a team as a code owner November 7, 2023 15:38
@MalteHerrmann MalteHerrmann requested review from 0xstepit and GAtom22 and removed request for a team November 7, 2023 15:38
precompiles/erc20/approve.go Outdated Show resolved Hide resolved
precompiles/erc20/approve.go Show resolved Hide resolved
Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Merging #2012 (103107b) into main (5d35eb3) will decrease coverage by 0.03%.
The diff coverage is 79.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2012      +/-   ##
==========================================
- Coverage   69.89%   69.87%   -0.03%     
==========================================
  Files         334      334              
  Lines       24909    24946      +37     
==========================================
+ Hits        17411    17431      +20     
- Misses       6599     6611      +12     
- Partials      899      904       +5     
Files Coverage Δ
precompiles/erc20/types.go 100.00% <100.00%> (ø)
precompiles/erc20/query.go 8.49% <66.66%> (ø)
precompiles/erc20/approve.go 76.08% <78.68%> (-6.39%) ⬇️

precompiles/erc20/approve.go Outdated Show resolved Hide resolved
precompiles/erc20/approve.go Outdated Show resolved Hide resolved
precompiles/erc20/approve.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Vvaradinov Vvaradinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, consider using SafeSub in some places to avoid the panic.

precompiles/erc20/approve.go Outdated Show resolved Hide resolved
precompiles/erc20/approve.go Outdated Show resolved Hide resolved
@MalteHerrmann
Copy link
Contributor Author

MalteHerrmann commented Nov 8, 2023

Setting to draft to work on the uint256 overflow behavior.

@MalteHerrmann MalteHerrmann marked this pull request as draft November 8, 2023 10:35
@MalteHerrmann MalteHerrmann marked this pull request as ready for review November 8, 2023 11:36
Copy link
Contributor

@Vvaradinov Vvaradinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work @MalteHerrmann

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a few lines need to be covered too

precompiles/erc20/approve.go Show resolved Hide resolved
precompiles/erc20/approve.go Show resolved Hide resolved
precompiles/erc20/approve.go Show resolved Hide resolved
Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

precompiles/erc20/approve.go Outdated Show resolved Hide resolved
@MalteHerrmann MalteHerrmann enabled auto-merge (squash) November 9, 2023 12:16
@MalteHerrmann MalteHerrmann merged commit 53345a1 into main Nov 9, 2023
33 checks passed
@MalteHerrmann MalteHerrmann deleted the malte/adjust-erc20-authorizations branch November 9, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants