-
Notifications
You must be signed in to change notification settings - Fork 54
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
test: add debug_traceTransaction
with opcode logger tests
#786
Merged
natanasow
merged 26 commits into
main
from
783-add-debug_traceTransaction-with-opcode-logger-tests
Jul 18, 2024
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
dd193ef
chore: add tests
natanasow 4c56114
chore: remove only
natanasow 8c3ea4f
chore: edit tests
natanasow 00954e0
chore: remove only
natanasow 6cf3f21
chore: add ci
natanasow c67b69b
chore: add -d mode
natanasow 1019293
chore: test
natanasow 33126d6
chore: add tests
natanasow 04d07c0
chore: add tests
natanasow 3199d28
chore: edit name
natanasow d27d820
chore: add tests
natanasow c3019b5
Merge branch 'main' into 783-add-debug_traceTransaction-with-opcode-l…
natanasow c31dd18
chore: edit workflow
natanasow 82ad825
chore: bump local node version
natanasow ed75d98
chore: debug ci
natanasow 775fc53
chore: debug
natanasow 6897892
chore: debug
natanasow 6c22644
chore: debug
natanasow 45c7261
Merge branch 'main' into 783-add-debug_traceTransaction-with-opcode-l…
natanasow 21a444c
chore: fix besu
natanasow 542d158
chore: add new line
natanasow 5ddb967
chore: add readme
natanasow f5e3a1b
Merge branch 'main' into 783-add-debug_traceTransaction-with-opcode-l…
natanasow 6c873bd
chore: fix contracts
natanasow d06862d
Merge branch 'main' into 783-add-debug_traceTransaction-with-opcode-l…
natanasow 5bb40fe
chore: pin version
natanasow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Opcode logger testing | ||
|
||
on: | ||
pull_request: | ||
branches: [ main, release/** ] | ||
push: | ||
branches: [ main, release/** ] | ||
tags: [ v* ] | ||
|
||
jobs: | ||
check: | ||
name: | ||
Opcode logger comparison between besu and hedera | ||
runs-on: [self-hosted, Linux, large, ephemeral] | ||
steps: | ||
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Use Node.js [18.15] | ||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | ||
with: | ||
node-version: 18.15 | ||
cache: npm | ||
|
||
- name: Create .env file | ||
run: cp local.env .env | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Upgrade @hashgraph/hedera-local to v2.27.1 | ||
run: npm install @hashgraph/[email protected] --save | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773 # v1.2.0 | ||
with: | ||
version: nightly | ||
|
||
- name: Run besu node | ||
run: npm run besu:start | ||
|
||
- name: Run opcode tests against besu | ||
run: npx hardhat test --grep "besu comparison" --network besu_local | ||
Nana-EC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Start the hedera local node | ||
run: npx hedera start -d | ||
|
||
- name: Run opcode tests against hedera local node | ||
run: npx hardhat test --grep @OpcodeLogger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
contracts-abi/contracts/solidity/opcode-logger/OpcodeLogger.sol/OpcodeLogger.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "call", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "callCode", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"name": "callsCounter", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "delegateCall", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "resetCounter", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "staticCall", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "updateOwner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
contract OpcodeLogger { | ||
address public owner; | ||
mapping(address => uint256) public callsCounter; | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
callsCounter[owner]++; | ||
} | ||
|
||
function updateOwner() external returns (address) { | ||
owner = msg.sender; | ||
callsCounter[owner]++; | ||
|
||
return owner; | ||
} | ||
|
||
function resetCounter() external { | ||
callsCounter[msg.sender] = 0; | ||
} | ||
|
||
function call(address payable _target, bytes memory _calldata) external payable returns (bool, uint256) { | ||
bool isSuccess; | ||
uint256 res; | ||
|
||
assembly { | ||
let resPlaceholder := mload(0x40) | ||
isSuccess := call(gas(), _target, callvalue(), add(_calldata, 0x20), mload(_calldata), resPlaceholder, 0x20) | ||
res := mload(resPlaceholder) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return (isSuccess, res); | ||
} | ||
|
||
function delegateCall(address payable _target, bytes memory _calldata) external returns (bool) { | ||
bool isSuccess; | ||
|
||
assembly { | ||
isSuccess := delegatecall(gas(), _target, add(_calldata, 0x20), mload(_calldata), 0, 0) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return isSuccess; | ||
} | ||
|
||
function staticCall(address payable _target, bytes memory _calldata) external returns (bool, uint256) { | ||
bool isSuccess; | ||
uint256 res; | ||
|
||
assembly { | ||
let resPlaceholder := mload(0x40) | ||
isSuccess := staticcall(gas(), _target, add(_calldata, 0x20), mload(_calldata), resPlaceholder, 0x20) | ||
res := mload(resPlaceholder) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return (isSuccess, res); | ||
} | ||
|
||
function callCode(address payable _target, bytes memory _calldata) external payable returns (bool) { | ||
bool isSuccess; | ||
|
||
assembly { | ||
isSuccess := callcode(gas(), _target, callvalue(), add(_calldata, 0x20), mload(_calldata), 0, 0) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return isSuccess; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why do we need to run besu again.
Is it that the
@OpcodeLogger
tests rely on comparing outputs from besu and local node?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of them (tagged with 'besu comparison') - yes, and that's the reason. Another possible question could be:
Every time we change a solidity's compiler version in the
hardhat.config.js
, we will have to locally run these tests against besu to generate a new hardcoded JSON which will be used for further comparison. That should be needed because let's get for example changes from solidity 0.8.23 and 0.8.24. Contracts compiled with the older version will not include EIP-5656 (for mcopy opcode) and EIP-1153 (for tstore and tload opcodes) anddebug_traceTransaction
will return opcodes based on the contract's bytecode. When we change a solidity version to 0.8.24 inhardhat.config.js
, contracts will be precompiled and the new opcodes (from EIP-5656 and EIP-1153) will be introduced in the contracts bytecodes, so when we run the tests and comparedebug_traceTransaction
responses with the hardcoded ones (generated with contracts compiled with solidity 0.8.23) they will differ.Based on the info above, we have two possible approaches:
hardhat.config.js
hardhat.config.js
I prefer the second approach because it's not binding to the developers and we shouldn't take extra care if the solidity version is bumped.
Hope that clears some of the things out. I'm open to changes if you find something disrupting or not right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. I'd like this called out in some doc somewhere so people understand the flow