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

Support detecting print/console.log #685

Closed
fubuloubu opened this issue May 1, 2022 · 5 comments · Fixed by #1930
Closed

Support detecting print/console.log #685

fubuloubu opened this issue May 1, 2022 · 5 comments · Fixed by #1930
Assignees
Labels
category: feature New feature or request

Comments

@fubuloubu
Copy link
Member

fubuloubu commented May 1, 2022

Overview

Hardhat supports the console.log feature, which works the same as the print feature that Vyper added in v0.3.3

It would be great to support this keyword (perhaps as an INFO log?)

Specification

According to Vyper's docs: https://vyper.readthedocs.io/en/latest/built-in-functions.html#print

If a static call is detected to a specialized address, interpret that call as a printout statement. This requires transactions traces. It might be better off partially implemented in evm-trace

Dependencies

#347

@fubuloubu fubuloubu added the category: feature New feature or request label May 1, 2022
@NotPeopling2day NotPeopling2day removed their assignment May 2, 2022
@charles-cooper
Copy link

note there are currently two formats floating around: NomicFoundation/hardhat#2666 (comment)

nomic folks seem open to the idea of switching to the generic version of console.log, but they might be a bit backlogged

@mikeshultz
Copy link
Member

This requires transactions traces. It might be better off partially implemented in evm-trace.

We're thinking that this will support live networks? My initial thought was that this would be leveraged via eth-tester or anvil or some kind of local testnet. Generally speaking, I'd never want console.log calls in a live contract.

Though I suppose that would be fairly limiting on which nodes/backends you could use.

So to fill out the spec, we're looking to basically just use the ape logger to output this calldata if it's seen on any transaction?

@fubuloubu
Copy link
Member Author

fubuloubu commented Feb 9, 2024

This requires transactions traces. It might be better off partially implemented in evm-trace.

We're thinking that this will support live networks? My initial thought was that this would be leveraged via eth-tester or anvil or some kind of local testnet. Generally speaking, I'd never want console.log calls in a live contract.

Yes, although I have seen people accidentally deploy to a public network. But maybe turn it off by default in that scenario.

Though I suppose that would be fairly limiting on which nodes/backends you could use.

Yes, it should basically opt in if it is essentially "cheap/free" to get the data via trace for display from that provider. May be also a good idea to disable it by default in ape test unless -s is provided that prints those out to the console during runtime?

So to fill out the spec, we're looking to basically just use the ape logger to output this calldata if it's seen on any transaction?

And decode it, yes

@mikeshultz
Copy link
Member

Don't know if there's any "official" docs anywhere (other than the brief API docs for print()), but there's some existing implementations like @charles-cooper's titanoboa implementation and some discussion in some GH issues. Enough to get something working.

Vyper's default print() encoding is pretty straight forward and nicely dynamic. Proof of concept: https://gist.github.com/mikeshultz/a254eac9c6e2c84ce362ff11b16f0122

Will figure out Hardhat's Solidity contract (and the Vyper compat) next.

@mikeshultz
Copy link
Member

Hardhat proof of concept: https://gist.github.com/mikeshultz/7c2847c2d0b4f48940ba809e61513daf

A much more rigid ABI. We could probably auto-generate the selectors/abi by just mixing and matching the base types but this was pretty straight forward to generate by just compiling the contact. And as @antazoey pointed out, we may have use for the ContractType for enriched traces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants