Skip to content

Support for hardhat/foundry console output#1050

Open
gustavo-grieco wants to merge 9 commits intomainfrom
dev-console
Open

Support for hardhat/foundry console output#1050
gustavo-grieco wants to merge 9 commits intomainfrom
dev-console

Conversation

@gustavo-grieco
Copy link
Copy Markdown
Collaborator

@gustavo-grieco gustavo-grieco commented Mar 26, 2026

Description

This PR implement console logging in the same way Foundry did (and Hardhat initially). The feature is explained here. This will help to fix crytic/echidna#1233.

Checklist

  • tested locally
  • added automated tests
  • updated the docs
  • updated the changelog

Copy link
Copy Markdown
Collaborator

@msooseth msooseth left a comment

Choose a reason for hiding this comment

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

LGTM, but can you maybe give more explanation at the top of the PR what this is about? I am not very familiar with hardhat. Then I'll approve and we can merge!

@gustavo-grieco
Copy link
Copy Markdown
Collaborator Author

Added some description to this PR.

Copy link
Copy Markdown
Collaborator

@blishko blishko left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.
The tests need additional work.

Comment thread test/EVM/ConcreteExecution/ConcreteExecutionTests.hs Outdated
Comment thread test/EVM/ConcreteExecution/ConcreteExecutionTests.hs Outdated
EXTCODESIZE now returns 1 for the console address (matching cheatCode
behavior), so contracts that check code size before calling won't
skip the console.log call. Added 8 new tests covering EXTCODESIZE,
format decoding (bool, address, no-args, unknown selector, short
input), return value correctness, and multiple console.log calls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@msooseth
Copy link
Copy Markdown
Collaborator

msooseth commented Apr 2, 2026

I did a thing -- adding more tests, changelog, and also one more place where a hardcoded address should be checked maybe?

gustavo-grieco and others added 4 commits April 2, 2026 19:49
The test contract files were not tracked in git, causing CI failures
since the Nix build only includes git-tracked files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@msooseth
Copy link
Copy Markdown
Collaborator

msooseth commented Apr 8, 2026

@blishko can you maybe re-review and then we can merge? Thanks!

Copy link
Copy Markdown
Collaborator

@blishko blishko left a comment

Choose a reason for hiding this comment

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

The unit tests should be moved, otherwise should be good to go!

Comment on lines +93 to +118
[ testCase "format-string" $ do
let encoded = ConcreteBuf $ abiMethod "log(string)" (AbiTuple $ V.fromList [AbiString "hello world"])
assertEqual "console.log(string) format" "console::log(\"hello world\")" (formatConsoleLog encoded)
, testCase "format-uint" $ do
let encoded = ConcreteBuf $ abiMethod "log(uint256)" (AbiTuple $ V.fromList [AbiUInt 256 42])
assertEqual "console.log(uint256) format" "console::log(42)" (formatConsoleLog encoded)
, testCase "format-string-uint" $ do
let encoded = ConcreteBuf $ abiMethod "log(string,uint256)" (AbiTuple $ V.fromList [AbiString "count", AbiUInt 256 7])
assertEqual "console.log(string,uint256) format" "console::log(\"count\", 7)" (formatConsoleLog encoded)
, testCase "format-bool" $ do
let encoded = ConcreteBuf $ abiMethod "log(bool)" (AbiTuple $ V.fromList [AbiBool True])
assertEqual "console.log(bool) format" "console::log(true)" (formatConsoleLog encoded)
, testCase "format-address" $ do
let encoded = ConcreteBuf $ abiMethod "log(address)" (AbiTuple $ V.fromList [AbiAddress 0xdeadbeef])
assertEqual "console.log(address) format" "console::log(0x00000000000000000000000000000000DeaDBeef)" (formatConsoleLog encoded)
, testCase "format-no-args" $ do
let encoded = ConcreteBuf $ abiMethod "log()" (AbiTuple $ V.fromList [])
assertEqual "console.log() format" "console::log()" (formatConsoleLog encoded)
, testCase "format-unknown-selector" $ do
let encoded = ConcreteBuf $ BS.pack [0xde, 0xad, 0xbe, 0xef, 0x01, 0x02]
let result = formatConsoleLog encoded
assertBool "unknown selector should produce hex fallback" (T.isPrefixOf "console::log(0x" result)
, testCase "format-short-input" $ do
let encoded = ConcreteBuf $ BS.pack [0x01, 0x02]
assertEqual "short input format" "console::log()" (formatConsoleLog encoded)
]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These tests should be moved elsewhere.
They do not test concrete VM executions (which is the purpose of this file), they are just unit tests for formatConsoleLog.
Not sure what is the best place for them, we can move them to the main test.hs for now.

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.

Feature Request: Support for logging in view functions like Foundry's console2

3 participants