Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions contracts/test-helpers/Helper_GasMeasurer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;

contract Helper_GasMeasurer {
function measureCallGas(
address _target,
bytes memory _data
)
public
returns ( uint )
{
uint gasBefore;
uint gasAfter;

uint calldataStart;
uint calldataLength;
assembly {
calldataStart := add(_data,0x20)
calldataLength := mload(_data)
}

bool success;
assembly {
gasBefore := gas()
success := call(gas(), _target, 0, calldataStart, calldataLength, 0, 0)
gasAfter := gas()
Comment on lines +24 to +26
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure exactly how this overhead works, but presumably will need to subtract at minimum the cost of GAS + CALL`, and possibly more, to get this to be the value we consume in geth.

}
require(success, "Call failed, but calls we want to measure gas for should succeed!");

return gasBefore - gasAfter;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"build:typechain": "buidler typechain",
"test": "yarn run test:contracts",
"test:contracts": "buidler test --show-stack-traces",
"test:gas": "buidler test \"test/contracts/OVM/execution/OVM_StateManager.gas-spec.ts\" --no-compile --show-stack-traces",
"lint": "yarn run lint:typescript",
"lint:typescript": "tslint --format stylish --project .",
"lint:fix": "yarn run lint:fix:typescript",
"lint:fix:typescript": "prettier --config prettier-config.json --write \"buidler.config.ts\" \"{src,test}/**/*.ts\"",
"clean": "rm -rf ./artifacts ./build ./cache",
"deploy": "./bin/deploy.js"
Expand Down
Loading