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

1859 trace failed transaction #1875

Merged
merged 28 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c12ddd9
#1859 added test contract
kladkogex Apr 22, 2024
6da373d
#1859 added test contract
kladkogex Apr 22, 2024
4a912bf
#1859 added test contract
kladkogex Apr 22, 2024
335b66e
#1859 added test contract
kladkogex Apr 22, 2024
9215805
#1859 added test contract
kladkogex Apr 22, 2024
7eaa960
#1859 added test contract
kladkogex Apr 22, 2024
d62cfc8
#1859 added test contract
kladkogex Apr 22, 2024
a3c26d7
#1859 added test contract
kladkogex Apr 22, 2024
a203036
#1859 added test contract
kladkogex Apr 22, 2024
f3eb1a1
#1859 added test contract
kladkogex Apr 22, 2024
9b538c7
#1859 added test contract
kladkogex Apr 22, 2024
961fff1
#1859 added test contract
kladkogex Apr 22, 2024
b1a0519
#1859 added test contract
kladkogex Apr 23, 2024
46627eb
#1859 added test contract
kladkogex Apr 23, 2024
2f588b4
#1859 added test contract
kladkogex Apr 23, 2024
f98c5e0
#1859 added test contract
kladkogex Apr 23, 2024
86fc325
#1859 added test contract
kladkogex Apr 23, 2024
ab1679f
#1859 added test contract
kladkogex Apr 23, 2024
aeceb04
#1859 added test contract
kladkogex Apr 23, 2024
d66c3fd
#1859 added test contract
kladkogex Apr 23, 2024
a8f1f97
#1859 added test contract
kladkogex Apr 23, 2024
94a859a
#1859 added test contract
kladkogex Apr 23, 2024
80685dd
#1859 added test contract
kladkogex Apr 23, 2024
7e5335a
#1859 added test contract
kladkogex Apr 23, 2024
c0da15e
#1859 added test contract
kladkogex Apr 23, 2024
b8d4e83
#1859 added test contract
kladkogex Apr 23, 2024
d702d90
#1859 added test contract
kladkogex Apr 23, 2024
567659f
#1859 added test contract
kladkogex Apr 23, 2024
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
22 changes: 13 additions & 9 deletions libevm/LegacyVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,29 @@ void LegacyVM::interpretCases() {
//

CASE( CREATE2 ) {
// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
// ON_OP();
if ( !m_schedule->haveCreate2 )
if ( !m_schedule->haveCreate2 ) {
ON_OP();
throwBadInstruction();
if ( m_ext->staticCall )
}
if ( m_ext->staticCall ) {
ON_OP();
throwDisallowedStateChange();
}

// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
m_bounce = &LegacyVM::caseCreate;
}
BREAK

CASE( CREATE ) {
// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
// ON_OP();
if ( m_ext->staticCall )
if ( m_ext->staticCall ) {
ON_OP();
throwDisallowedStateChange();
}

// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
m_bounce = &LegacyVM::caseCreate;
}
BREAK
Expand Down
3 changes: 1 addition & 2 deletions libhistoric/AlethExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ bool AlethExecutive::go( OnOpFunc const& _onOp ) {
throw;
#ifdef HISTORIC_STATE
} catch ( VMTracingError const& _e ) {
cwarn << "Tracing error: " << *boost::get_error_info< errinfo_evmcStatusCode >( _e )
<< ")";
cerr << "VM tracing error:" << _e.message;
revert();
throw;
#endif
Expand Down
4 changes: 2 additions & 2 deletions libhistoric/AlethStandardTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ void AlethStandardTrace::setTopFunctionCall(

void AlethStandardTrace::recordFunctionReturned(
evmc_status_code _status, const vector< uint8_t >& _returnData, uint64_t _gasUsed ) {
STATE_CHECK( getLastOpRecord()->m_gasRemaining >= getLastOpRecord()->m_opGas )
// note that m_gas remaining can be less than m_opGas. This happens in case
// of out of gas revert
STATE_CHECK( m_currentlyExecutingFunctionCall )
STATE_CHECK( !m_isFinalized )

Expand Down Expand Up @@ -348,7 +349,6 @@ shared_ptr< OpExecutionRecord > AlethStandardTrace::createOpExecutionRecord( uin
opName = "KECCAK256";
}


auto executionRecord = std::make_shared< OpExecutionRecord >( ext.depth, _inst,
( uint64_t ) _gasRemaining, ( uint64_t ) _gasOpGas, _pc, ext.sub.refunds, opName );

Expand Down
7 changes: 7 additions & 0 deletions libhistoric/CallTracePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ void CallTracePrinter::printContractTransactionTrace(
// call trace on the top Solidity function call in the stack
// this will also recursively call printTrace on nested calls if exist
topFunctionCall->printTrace( _jsonTrace, _statePost, 0, m_trace.getOptions() );

// for the top function the gas limit that geth prints is the transaction gas limit
// and not the gas limit given to the top level function, which is smaller because of 21000
// transaction cost and potentially eth transfer cost
_jsonTrace["gas"] =
AlethStandardTrace::toGethCompatibleCompactHexPrefixed( m_trace.getGasLimit() );

// handle the case of a transaction that deploys a contract
// in this case geth prints transaction input data as input
// end prints to as newly created contract address
Expand Down
157 changes: 157 additions & 0 deletions test/historicstate/hardhat/contracts/Erc20Custom.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// SPDX-License-Identifier: AGPL-3.0-only

/**
* ERC20Custom.sol - SKALE Test tokens
* Copyright (C) 2022-Present SKALE Labs
* @author Artem Payvin
*
* SKALE IMA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SKALE IMA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity ^0.8.20;

contract ERC20Custom {

mapping (address => uint256) private _balances;

mapping (address => mapping (address => uint256)) private _allowances;

uint256 private _totalSupply;

string private _name;
string private _symbol;
uint8 private _decimals;

event Approval(address owner, address spender, uint256 amount);

event Transfer(address from, address to, uint256 amount);

constructor(string memory tokenName, string memory tokenSymbol) {
_name = tokenName;
_symbol = tokenSymbol;
_decimals = 18;

_mint(tx.origin, 10);
}

function mint(address account, uint256 amount) external returns (bool) {
_mint(account, amount);
return true;
}

/**
* @dev burn - destroys token on msg sender
*
* NEED TO HAVE THIS FUNCTION ON SKALE-CHAIN
*
* @param amount - amount of tokens
*/
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}

function name() public view returns (string memory) {
return _name;
}

function symbol() public view returns (string memory) {
return _symbol;
}

function decimals() public view returns (uint8) {
return _decimals;
}

function totalSupply() public view returns (uint256) {
return _totalSupply;
}

function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}

function transfer(address recipient, uint256 amount) public virtual returns (bool) {
this._transfer1();
return true;
}

function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}

function approve(address spender, uint256 amount) public virtual returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}

function transferFrom(address sender, address recipient, uint256 amount) public virtual returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender] - amount
);
return true;
}

function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
return true;
}

function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(
msg.sender,
spender,
_allowances[msg.sender][spender] - subtractedValue
);
return true;
}

function _transfer1() public {
}

function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");

_balances[sender] = _balances[sender] - amount;
_balances[recipient] = _balances[recipient] + amount;
emit Transfer(sender, recipient, amount);
}

function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");

_totalSupply = _totalSupply + amount;
_balances[account] = _balances[account] + amount;
emit Transfer(address(0), account, amount);
}

function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");

_balances[account] = _balances[account] - amount;
_totalSupply = _totalSupply - amount;
emit Transfer(account, address(0), amount);
}

function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");

_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
2 changes: 1 addition & 1 deletion test/historicstate/hardhat/run_geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add_ether_to_account(address, amount):
return

# Unlock the default account (coinbase)
coinbase = w3.eth.coinbase
coinbase = w3.eth.accounts[0]
w3.geth.personal.unlock_account(coinbase, '', 0)

# Convert Ether to Wei
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"calls": [
{
"error": "out of gas",
"from": "ERC20Custom.address",
"gas": "0x51",
"gasUsed": "0x30d",
"input": "0x53bb9b8a",
"to": "ERC20Custom.address",
"type": "CALL"
}
],
"error": "out of gas",
"from": "OWNER.address",
"gas": "0x6239",
"gasUsed": "0x6239",
"input": "0xa9059cbb000000000000000000000000ce5c7ca85f8cb94fa284a303348ef42add23f5e70000000000000000000000000000000000000000000000000000000000000001",
"to": "ERC20Custom.address",
"type": "CALL",
"value": "0x0"
}
Loading
Loading