From ac87d8e5369bf4013468f088b249f68ae958aec9 Mon Sep 17 00:00:00 2001
From: Stan Kladko <13399135+kladkogex@users.noreply.github.com>
Date: Wed, 10 Apr 2024 14:52:05 +0000
Subject: [PATCH 01/34] 1856_checkout_external_gas
---
libethereum/Transaction.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp
index 5bd057524..1a109fe30 100644
--- a/libethereum/Transaction.cpp
+++ b/libethereum/Transaction.cpp
@@ -209,12 +209,15 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, boo
if ( CorrectForkInPowPatch::isEnabled() )
scheduleForUse = _cp.scheduleForBlockNumber( _bn );
+
+#ifndef HISTORIC_STATE // FIX FOR 2.3.1. Will not be needed in 2.4
// never call checkOutExternalGas with non-last block
if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) {
ctrace << _bn << " != " << CorrectForkInPowPatch::getLastBlockNumber();
BOOST_THROW_EXCEPTION( std::runtime_error(
"Internal error: checkOutExternalGas() has invalid block number" ) );
}
+#endif
if ( externalGas >= baseGasRequired( scheduleForUse ) )
m_externalGas = externalGas;
From f3b977aba08536645d5d4bf889f59032797dcdb2 Mon Sep 17 00:00:00 2001
From: Stan Kladko <13399135+kladkogex@users.noreply.github.com>
Date: Wed, 10 Apr 2024 14:57:00 +0000
Subject: [PATCH 02/34] 1856 fix clang format
---
libethereum/Transaction.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp
index 1a109fe30..dc41a2838 100644
--- a/libethereum/Transaction.cpp
+++ b/libethereum/Transaction.cpp
@@ -210,7 +210,7 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, boo
scheduleForUse = _cp.scheduleForBlockNumber( _bn );
-#ifndef HISTORIC_STATE // FIX FOR 2.3.1. Will not be needed in 2.4
+#ifndef HISTORIC_STATE // FIX FOR 2.3.1. Will not be needed in 2.4
// never call checkOutExternalGas with non-last block
if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) {
ctrace << _bn << " != " << CorrectForkInPowPatch::getLastBlockNumber();
From c12ddd96d9103de499e646489faf4bf80fd889fe Mon Sep 17 00:00:00 2001
From: Stan Kladko <13399135+kladkogex@users.noreply.github.com>
Date: Mon, 22 Apr 2024 12:11:05 +0000
Subject: [PATCH 03/34] #1859 added test contract
---
.../hardhat/contracts/Erc20Custom.sol | 153 ++++++++++++++++++
1 file changed, 153 insertions(+)
create mode 100644 test/historicstate/hardhat/contracts/Erc20Custom.sol
diff --git a/test/historicstate/hardhat/contracts/Erc20Custom.sol b/test/historicstate/hardhat/contracts/Erc20Custom.sol
new file mode 100644
index 000000000..5267f56cf
--- /dev/null
+++ b/test/historicstate/hardhat/contracts/Erc20Custom.sol
@@ -0,0 +1,153 @@
+// 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 .
+ */
+
+pragma solidity 0.8.6;
+
+
+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;
+ }
+
+ 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) {
+ _transfer(msg.sender, recipient, amount);
+ 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 _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);
+ }
+}
\ No newline at end of file
From 6da373d8877ab012df9f8fdbcb2fb5387369448c Mon Sep 17 00:00:00 2001
From: Stan Kladko <13399135+kladkogex@users.noreply.github.com>
Date: Mon, 22 Apr 2024 12:15:55 +0000
Subject: [PATCH 04/34] #1859 added test contract
---
test/historicstate/hardhat/contracts/Erc20Custom.sol | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/test/historicstate/hardhat/contracts/Erc20Custom.sol b/test/historicstate/hardhat/contracts/Erc20Custom.sol
index 5267f56cf..6df6f0514 100644
--- a/test/historicstate/hardhat/contracts/Erc20Custom.sol
+++ b/test/historicstate/hardhat/contracts/Erc20Custom.sol
@@ -19,8 +19,7 @@
* along with SKALE IMA. If not, see .
*/
-pragma solidity 0.8.6;
-
+pragma solidity ^0.8.20;
contract ERC20Custom {
From 4a912bf4fc59780ad7af052cc8bf3503fc880a07 Mon Sep 17 00:00:00 2001
From: Stan Kladko <13399135+kladkogex@users.noreply.github.com>
Date: Mon, 22 Apr 2024 12:40:57 +0000
Subject: [PATCH 05/34] #1859 added test contract
---
test/historicstate/hardhat/contracts/Erc20Custom.sol | 2 ++
1 file changed, 2 insertions(+)
diff --git a/test/historicstate/hardhat/contracts/Erc20Custom.sol b/test/historicstate/hardhat/contracts/Erc20Custom.sol
index 6df6f0514..bcb698f76 100644
--- a/test/historicstate/hardhat/contracts/Erc20Custom.sol
+++ b/test/historicstate/hardhat/contracts/Erc20Custom.sol
@@ -41,6 +41,8 @@ contract ERC20Custom {
_name = tokenName;
_symbol = tokenSymbol;
_decimals = 18;
+
+ _mint(tx.origin, 1000);
}
function mint(address account, uint256 amount) external returns (bool) {
From 335b66e6f53e6ae65b88ee953362a3969194d2cc Mon Sep 17 00:00:00 2001
From: Stan Kladko <13399135+kladkogex@users.noreply.github.com>
Date: Mon, 22 Apr 2024 12:41:11 +0000
Subject: [PATCH 06/34] #1859 added test contract
---
.../hardhat/scripts/token_revert.ts | 470 ++++++++++++++++++
1 file changed, 470 insertions(+)
create mode 100644 test/historicstate/hardhat/scripts/token_revert.ts
diff --git a/test/historicstate/hardhat/scripts/token_revert.ts b/test/historicstate/hardhat/scripts/token_revert.ts
new file mode 100644
index 000000000..478ce369b
--- /dev/null
+++ b/test/historicstate/hardhat/scripts/token_revert.ts
@@ -0,0 +1,470 @@
+import {mkdir, readdir, writeFileSync, readFile, unlink} from "fs";
+
+const fs = require('fs');
+import {existsSync} from "fs";
+import deepDiff, {diff} from 'deep-diff';
+import {expect} from "chai";
+import * as path from 'path';
+import {int, string} from "hardhat/internal/core/params/argumentTypes";
+import internal from "node:stream";
+
+const OWNER_ADDRESS: string = "0x907cd0881E50d359bb9Fd120B1A5A143b1C97De6";
+const CALL_ADDRESS: string = "0xCe5c7ca85F8cB94FA284a303348ef42ADD23f5e7";
+
+const ZERO_ADDRESS: string = '0x0000000000000000000000000000000000000000';
+
+const SKALE_TRACES_DIR = "/tmp/skale_traces/"
+const GETH_TRACES_DIR = "scripts/geth_traces/"
+
+const DEFAULT_TRACER = "defaultTracer";
+const CALL_TRACER = "callTracer";
+const PRESTATE_TRACER = "prestateTracer";
+const PRESTATEDIFF_TRACER = "prestateDiffTracer";
+const FOURBYTE_TRACER = "4byteTracer";
+const REPLAY_TRACER = "replayTracer";
+
+var DEPLOYED_CONTRACT_ADDRESS_LOWER_CASE: string = "";
+var globalCallCount = 0;
+
+
+async function replaceAddressesWithSymbolicNames(_traceFileName: string) {
+
+ let callAddressLowerCase = CALL_ADDRESS.toLowerCase();
+
+ await replaceStringInFile(SKALE_TRACES_DIR + _traceFileName,
+ callAddressLowerCase, "CALL.address");
+
+ let ownerAddressLowerCase = OWNER_ADDRESS.toLowerCase();
+
+ await replaceStringInFile(SKALE_TRACES_DIR + _traceFileName,
+ ownerAddressLowerCase, "OWNER.address");
+
+ // if the contract has been deployed, also replace contract address
+
+ if (DEPLOYED_CONTRACT_ADDRESS_LOWER_CASE.length > 0) {
+ await replaceStringInFile(SKALE_TRACES_DIR + _traceFileName,
+ DEPLOYED_CONTRACT_ADDRESS_LOWER_CASE, TEST_CONTRACT_NAME + ".address");
+
+ }
+
+
+}
+
+async function getTraceJsonOptions(_tracer: string): Promise