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

Goal: Warn on invalid method signature assembly #3614

Merged
merged 7 commits into from
Mar 17, 2022

Conversation

jasonpaulos
Copy link
Contributor

@jasonpaulos jasonpaulos commented Feb 11, 2022

Summary

With this PR, the assembler will now warn if an invalid method signature is used as an argument to the method pseudo-op. This is just a warning so the program will still compile, but it should help users be aware of mistakes they might have made.

No urgency to this PR.

Example

test.teal:

#pragma version 6
method "abc"
pop
method "abc(uint64)"
pop
method "abc(uint64)void"
pop
method "abc(blah)void"
pop
int 1
return
$ goal clerk compile test.teal        
warning: 2: Invalid ARC-4 ABI method signature for method op: No parenthesis in method signature: "abc"
warning: 4: Invalid ARC-4 ABI method signature for method op: Error parsing return type: cannot convert the string "" to an ABI type
warning: 8: Invalid ARC-4 ABI method signature for method op: Error parsing argument type at index 0: cannot convert the string "blah" to an ABI type
3 warnings
test.teal: 43KDA5RKR22UG7M53XNVD7N7CYTS6KI7WRAAZL6MNGVUZIOHLKGLO4VYQ4

Test Plan

Unit test added.

ahangsu
ahangsu previously approved these changes Feb 11, 2022
Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jannotti jannotti 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. Let's do something similar for "event" (after spending a little time defining it), and then a bare selector pseudo-op. Once we have those, I think this would becomes an error rather than warning.

Why did you have to suppress printing, rather than separating assembly output from earnings by using stderr?

@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2022

Codecov Report

Merging #3614 (3e1226d) into master (af3b5d3) will decrease coverage by 0.03%.
The diff coverage is 19.23%.

@@            Coverage Diff             @@
##           master    #3614      +/-   ##
==========================================
- Coverage   49.88%   49.84%   -0.04%     
==========================================
  Files         392      392              
  Lines       68685    68713      +28     
==========================================
- Hits        34264    34251      -13     
- Misses      30669    30706      +37     
- Partials     3752     3756       +4     
Impacted Files Coverage Δ
cmd/goal/account.go 12.94% <0.00%> (ø)
cmd/goal/application.go 11.16% <0.00%> (ø)
cmd/goal/clerk.go 9.13% <0.00%> (-0.10%) ⬇️
cmd/goal/commands.go 10.40% <0.00%> (-0.04%) ⬇️
cmd/goal/logging.go 8.92% <0.00%> (ø)
data/abi/abi_encode.go 61.26% <0.00%> (-2.82%) ⬇️
data/abi/abi_type.go 88.62% <100.00%> (ø)
data/transactions/logic/assembler.go 79.96% <100.00%> (+0.05%) ⬆️
cmd/algoh/blockWatcher.go 77.77% <0.00%> (-3.18%) ⬇️
ledger/tracker.go 74.67% <0.00%> (-2.15%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af3b5d3...3e1226d. Read the comment docs.

@jasonpaulos
Copy link
Contributor Author

Originally I just used the same convention for warnings as other places in goal, which is to print to stdout. But I agree this seems odd, so I now changed it so that all warnings go to stderr for goal commands.

This is a little more far reaching than I intended, so I hope it doesn't disrupt anything else.

@ahangsu
Copy link
Contributor

ahangsu commented Feb 22, 2022

Hey folks, I was just reviewing this PR again and was wondering about what JJ previously mentioned:

Let's do something similar for "event" (after spending a little time defining it), and then a bare selector pseudo-op.

What is "event" referring to, does that mean another op/pseudo-op?

@jannotti
Copy link
Contributor

jannotti commented Feb 22, 2022

Hey folks, I was just reviewing this PR again and was wondering about what JJ previously mentioned:

Let's do something similar for "event" (after spending a little time defining it), and then a bare selector pseudo-op.

What is "event" referring to, does that mean another op/pseudo-op?

An "event" in ethereum is a structured message that a contract can emit. Our log opcode is intended to cover this use case (in addition to being a "return value" mechanism). Events have a name, and some associated data. Think of an event like "I have transferred 50 algos from address A to address B". It might be named "transfer" and have three fields of type uint64, address and address. So, my strawman proposal is that an app would emit an "event" of this kind by emitting a log message prefixed by hash("transfer(uint64,address,address"). The bytes after the hash would be the ABI encoding of those three values.

@ahangsu
Copy link
Contributor

ahangsu commented Feb 22, 2022

Uh I see, thanks for explaining! I was also reading: https://medium.com/mycrypto/understanding-event-logs-on-the-ethereum-blockchain-f4ae7ba50378, seems matching what you just mentioned.

I suppose this "event" sounds like a "structured log", which allows for some structured fields filled by ABI encodings, and it might worth it to check the validity of those fields, just like this PR.

@jasonpaulos jasonpaulos force-pushed the assembler_method_warn branch from 3f8f89f to 471d61e Compare March 16, 2022 17:38
@jasonpaulos jasonpaulos changed the title Warn on invalid method signature assembly Goal: Warn on invalid method signature assembly Mar 17, 2022
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

Seems good. Merging.

@jannotti jannotti merged commit 0e79364 into algorand:master Mar 17, 2022
@jasonpaulos jasonpaulos deleted the assembler_method_warn branch March 17, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants