Skip to content

feat: remove x/authz dependency from precompiles #62

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

Open
wants to merge 45 commits into
base: main
Choose a base branch
from

Conversation

cloudgray
Copy link

Description

Removal of x/authz dependency on precompiles

  • Remove authzKeeper dependency from common Precompile struct
  • For staking and ics20 precompile
    • remove authorization methods (Approve, Revoke, IncreaseAllowance, DecreaseAllowance, Allowance) and its usage.
  • For erc20 precompile
    • Add Allowance state CRUD methods in x/erc20 module
    • Use added Allowance state of x/erc20 module instead of Grant state of x/authz module for authorization methods (Approve, Revoke, IncreaseAllowance, DecreaseAllowance, Allowance)

Closes: #47


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

Reviewers Checklist

All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.

I have...

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

@cloudgray cloudgray changed the title feat: remove authz dependency from precompiles except for erc20 feat: remove authz dependency from precompiles Apr 9, 2025
@cloudgray cloudgray changed the title feat: remove authz dependency from precompiles feat: remove x/authz dependency from precompiles Apr 9, 2025
Copy link
Contributor

@zsystm zsystm left a comment

Choose a reason for hiding this comment

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

Looks good to me so far — the authz removal seems to be handled well.

I had one question while reviewing the test code, which I left as a comment.

Also, this is not directly related to the scope of your PR, but I noticed that some of the existing test cases don’t validate balance changes. For example, after a delete, there’s no assertion checking whether the delegator’s balance was reduced accordingly. Since the precompiled contract involves complex state transitions, I think it would be valuable to add more thorough state validation to ensure the transitions happen as expected.

This can probably be addressed in a separate PR, so just leaving this here for reference. I opened an issue to track it.

cloudgray and others added 9 commits April 21, 2025 13:35
* feat(x/erc20): add allowance state

* test(x/erc20): add unit test for Allowance

* fix(x/erc20): add deleteAllowances method and modify genesis validation

* fix(x/erc20): validation of SetAllowance/GetAllowance and InitGenesis

* test(x/erc20) add test cases for UnsafeSetAllowance

* chore: fix lint
@zsystm zsystm marked this pull request as ready for review April 22, 2025 13:09
@zsystm zsystm requested a review from dongsam April 22, 2025 13:10
Copy link
Member

@dongsam dongsam left a comment

Choose a reason for hiding this comment

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

I haven’t gone through everything yet, but from what I’ve seen so far in app.go and the ics20 precompile section, it looks good

I’ll continue the review when I have more time.

@@ -0,0 +1,164 @@
package keeper
Copy link
Member

Choose a reason for hiding this comment

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

This comment is related to a change that wasn't mentioned in the review of the previous PR (#90), so I'm leaving it here.

With the addition of the allowance state to the ERC20 module, a state-breaking change has occurred.
However, it looks like the consensus version is still set to 4

There seem to be two possible options to address this:

  1. Increment the consensus version to 5 — to maintain continuity with the version history used in evmos/os.
  2. Reset the consensus version to 1 — since we're starting fresh with cosmos/evm, setting it to the initial version (1) could also make sense.

If this isn't the appropriate PR to make a decision on this, I’d appreciate it if we could continue the discussion in a separate issue.

c.c @cloudgray @zsystm @vladjdk

Copy link
Author

Choose a reason for hiding this comment

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

I missed modifying consensus version of x/erc20 module. 🙏

I think consensus version should be 5 in this PR.

And resetting the consensus version to 1 is something that applies to other modules as well, so I think it should be handled in a separate issue. Because x/vm module and x/feemarket module also have consensus version from evmos/os [x/evm: 8] [x/feemarket: 5]

c.c @dongsam @zsystm @vladjdk

Copy link
Member

Choose a reason for hiding this comment

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

Let's open a new issue for this yes

Copy link
Author

@cloudgray cloudgray Apr 30, 2025

Choose a reason for hiding this comment

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

@dudong2 dudong2 self-requested a review April 28, 2025 07:44
@dudong2
Copy link

dudong2 commented Apr 28, 2025

In the cosmos-evm context, naming convention is interfaces.go, not expected_keepers.go.
It's not critical, but I think it would be better to change it for consistency

@@ -27,7 +27,7 @@ import (
)

// consensusVersion defines the current x/erc20 module consensus version.
const consensusVersion = 4
const consensusVersion = 5
Copy link

Choose a reason for hiding this comment

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

I think this work doesn't cause breaking changes, so you don't need to increment the consensus version.
Or, if this work cause breaking changes, you need to serve the migration code.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I'll lower consensus version to before modification and open issue.

Copy link
Author

Choose a reason for hiding this comment

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

applied in efc0ec0

Copy link

Choose a reason for hiding this comment

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

I tested node starting and didn't cause breaking changes. test steps are below

1. start node with main branch
2. stop the node and build node on the `feat/remove-authz-from-precompiles` branch
3. start the node 
4. no breaking changes.

if you agree with this test, you don't need to open the issues.

Copy link
Author

Choose a reason for hiding this comment

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

I agree.

I think we should only open issue on whether initialize consensusVersion of x/modules to 1 or use current consensusVersion increased by evmos/evmos repo.

return k.setAllowance(ctx, erc20, owner, spender, common.Big0, false)
}

func (k Keeper) setAllowance(
Copy link

Choose a reason for hiding this comment

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

In my opinion, the setAllowance function should be defined purely as a function to set to store, and the other check logic should be left out as outer functions.

SetAllowance()
    - check token pair
    - call UnsafeSetAllowance

UnsafeSetAllowance
    - check owner, spender, value, ...
    - call setAllowance

setAllowance
    - set allowance to store

i think this architecture looks so good to me.

Copy link
Author

@cloudgray cloudgray Apr 29, 2025

Choose a reason for hiding this comment

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

@dudong2 I mostly agree with your opinion.

But there is one problem.
If I check token pair external from UnsafeSetAllowance, checking existence of token pair in InitGenesis becomes difficult.

So, my proposal is as below.

  1. SetAllowance calls SetAllowanceWithValidation with arg allowDisabledTokenPair == false
  2. SetAllowanceWithValidation takes part of all validation and if allowDisabledTokenPair == true, it ignores TokenPair.Enabled == false and call setAllowance.
  3. setAllowance only take part of setting store.
SetAllowance()
    - call SetAllowanceWithValidation()

SetAllowanceWithValidation()
    - check token pair
    - **check enabled/disabled tokenPair (optionally)**
    - check owner, spender, value, ...
    - call setAllowance()

setAllowance()
    - if value == nil, delete Allowance
    - set allowance to store

Copy link
Author

Choose a reason for hiding this comment

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

applied in c39ffaa

If you think the change is inappropriate, I'll modify again.

Copy link

Choose a reason for hiding this comment

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

ok. Then I think below architecture is better.

SetAllowance()
    - check token pair with enabled
    - call setAllowance

UnsafeSetAllowance()
    - check token pair w/o enabled
    - call setAllowance

setAllowance()
    - set allowance to store

Copy link
Author

Choose a reason for hiding this comment

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

In your new design, I think check owner, spender, value, ... is omitted.
I think you mean check owner, spender, value, ... is performed in setAllowance().
Is it right?

Copy link
Author

Choose a reason for hiding this comment

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

I modified as below for reducing logic redundancy. (aacfc4c)

SetAllowance()
    - call setAllowance w/o allowDisabledTokenPair

DeleteAllowance()
    - call setAllowance w/ allowDisabledTokenPair

UnsafeSetAllowance()
    - call setAllowance w/ allowDisabledTokenPair

setAllowance()
    - check token pair exists and enabled
    - check owner, spender, value, ...
    - set allowance to store

@cloudgray
Copy link
Author

In the cosmos-evm context, naming convention is interfaces.go, not expected_keepers.go. It's not critical, but I think it would be better to change it for consistency

applied in dc225a2

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.

[EPIC] Removal of x/authz dependency on precompiles
5 participants