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

[Hardhat] Hook into EVM internal message calls to properly setup the storage #56

Closed
Tracked by #70
acuarica opened this issue Oct 4, 2024 · 0 comments · Fixed by #66
Closed
Tracked by #70

[Hardhat] Hook into EVM internal message calls to properly setup the storage #56

acuarica opened this issue Oct 4, 2024 · 0 comments · Fixed by #66
Assignees
Labels
feature Enhancing an existing feature driven by business requirements. Typically backwards compatible.

Comments

@acuarica
Copy link
Contributor

acuarica commented Oct 4, 2024

Our solution to setup storage slots prior being accessed is trap Provider's request calls. However, something we overlook is when a contract calls an HTS token. For example

contract CallToken {
    function getTokenTotalSupply(address htsTokenAddress) external view returns (uint256) {
        return IERC20(htsTokenAddress).totalSupply();
    }
}

In this case, the request mechanism won't work because the call is internal and not visible through the provider. We need a solution that allows us to hook into the EVM when calls are being executed.

We could hook into the EVM using something like1

    vm.evm.events?.on("beforeMessage", this.handleBeforeMessage.bind(this));

where vm is provider._node._vm. It seems this approach allows us to catch all messages calls before the actual call.

If this solution works, it would change the current approach. Instead of extending the provider, we need would need to listen to this event, and hook only into calls to 0x167. From the payload data to 0x167 we can get the actual token address and setup the storage accordingly. This should solve both #55 and #50 (comment) as well.

Footnotes

  1. https://github.com/zemse/hardhat-tracer/blob/bc75d49be050476d01f078489ba2a50823af6faa/src/trace-recorder.ts#L57

@acuarica acuarica added the feature Enhancing an existing feature driven by business requirements. Typically backwards compatible. label Oct 4, 2024
@acuarica acuarica self-assigned this Oct 8, 2024
@acuarica acuarica moved this from Backlog to Sprint Backlog in Smart Contract Sprint Board Oct 8, 2024
@acuarica acuarica linked a pull request Oct 8, 2024 that will close this issue
2 tasks
@github-project-automation github-project-automation bot moved this from In Review to Done in Smart Contract Sprint Board Oct 16, 2024
@se7enarianelabs se7enarianelabs changed the title Hook into EVM internal message calls to properly setup the storage [Hardhat] Hook into EVM internal message calls to properly setup the storage Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Enhancing an existing feature driven by business requirements. Typically backwards compatible.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant