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

fix: improve error message for conflicting methods IDs #3134

Merged
merged 5 commits into from
Nov 10, 2022

Conversation

trocher
Copy link
Contributor

@trocher trocher commented Oct 28, 2022

What I did

Fix #3133

How I did it

I modified collision_str in validate_unique_method_ids so that we look for the collision ID in lists of IDs instead of looking for it in lists of function signature

How to verify it

Trying to compile the following contract will now output the name of the functions having a collision:

@external
def OwnerTransferV7b711143(a : uint256) : 
    pass
@external
def withdraw(a : uint256):
    pass

Commit message

fix: improve error message for conflicting methods IDs

Description for the changelog

Improve error message for conflicting methods IDs

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2022

Codecov Report

Merging #3134 (39d4c55) into master (b13595f) will decrease coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3134      +/-   ##
==========================================
- Coverage   88.49%   88.39%   -0.11%     
==========================================
  Files          95       95              
  Lines       10760    10761       +1     
  Branches     2266     2266              
==========================================
- Hits         9522     9512      -10     
- Misses        796      806      +10     
- Partials      442      443       +1     
Impacted Files Coverage Δ
vyper/semantics/validation/utils.py 91.80% <100.00%> (+0.03%) ⬆️
vyper/codegen/arithmetic.py 79.48% <0.00%> (-5.13%) ⬇️
vyper/ast/nodes.py 93.05% <0.00%> (-0.17%) ⬇️
vyper/builtin_functions/functions.py 90.37% <0.00%> (-0.17%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@charles-cooper
Copy link
Member

interesting -- i think we should output the full function signatures (including the arguments), and also the colliding method id. ex.

Methods produce colliding method ID `0x2e1a7d4d`: OwnerTransferV7b711143(uint256), withdraw(uint256)

- the 4-byte selector
- their full signature
@trocher
Copy link
Contributor Author

trocher commented Oct 31, 2022

Made the changes you mentioned, one can verify that functions with default arguments are handled correctly with the following contract:

@external
def OwnerTransferV7b711143(a: uint256) : 
    pass
@external
def withdraw(a: uint256, b: uint256 = 0):
    pass
@external
def foo(a: uint256):
    pass

x for i in functions for x in i.method_ids.keys() if i.method_ids[x] == collision
)
raise StructureException(
f"Methods produce colliding method ID `{hex(collision)}`: {collision_str}"
Copy link
Member

Choose a reason for hiding this comment

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

hex(collision) might produce a badly formatted method ID if collision requires fewer than 4 bytes (e.g. collision == 1).

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

awesome, nice work. thanks!

@charles-cooper charles-cooper enabled auto-merge (squash) November 8, 2022 19:19
auto-merge was automatically disabled November 8, 2022 20:23

Head branch was pushed to by a user without write access

@trocher
Copy link
Contributor Author

trocher commented Nov 8, 2022

Forgot to run mypy, sorry for that!

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.

StructureException's message wrongly formatted
4 participants