forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/delegate call trace (0xPolygonHermez#2115)
* WIP: fix delegatecall when trace is requested via custom tracer * changes to custom tracer for call, callcode, staticcall, delegatecall opcodes * fix custom tracer staticcall opcode * fix custom tracer subcalls with multi levels * comment test debug code * review error handling * fix custom call tracer for SC calls with precompiled code * fix get precompiled address and input for opcodes that have tx value * increase debug tracer e2e tests timeout * update prover image
- Loading branch information
Showing
24 changed files
with
2,259 additions
and
636 deletions.
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
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
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,30 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract Called { | ||
uint256 num; | ||
address sender; | ||
uint256 value; | ||
|
||
function setVars(uint256 _num) public payable { | ||
num = _num; | ||
sender = msg.sender; | ||
value = msg.value; | ||
} | ||
|
||
function setVarsViaCall(uint256 _num) public payable { | ||
bool ok; | ||
(ok, ) = address(this).call( | ||
abi.encodeWithSignature("setVars(uint256)", _num) | ||
); | ||
require(ok, "failed to perform call"); | ||
} | ||
|
||
function getVars() public view returns (uint256, address, uint256) { | ||
return (num, sender, value); | ||
} | ||
|
||
function getVarsAndVariable(uint256 _num) public view returns (uint256, address, uint256, uint256) { | ||
return (num, sender, value, _num); | ||
} | ||
} |
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,74 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract Caller { | ||
function call(address _contract, uint _num) public payable { | ||
bool ok; | ||
(ok, ) = _contract.call( | ||
abi.encodeWithSignature("setVars(uint256)", _num) | ||
); | ||
require(ok, "failed to perform call"); | ||
} | ||
|
||
function delegateCall(address _contract, uint _num) public payable { | ||
bool ok; | ||
(ok, ) = _contract.delegatecall( | ||
abi.encodeWithSignature("setVars(uint256)", _num) | ||
); | ||
require(ok, "failed to perform delegate call"); | ||
} | ||
|
||
function staticCall(address _contract) public payable { | ||
bool ok; | ||
bytes memory result; | ||
(ok, result) = _contract.staticcall( | ||
abi.encodeWithSignature("getVars()") | ||
); | ||
require(ok, "failed to perform static call"); | ||
|
||
uint256 num; | ||
address sender; | ||
uint256 value; | ||
|
||
(num, sender, value) = abi.decode(result, (uint256, address, uint256)); | ||
} | ||
|
||
function invalidStaticCallMoreParameters(address _contract) public { | ||
bool ok; | ||
(ok,) = _contract.staticcall( | ||
abi.encodeWithSignature("getVarsAndVariable(uint256)", 1, 2) | ||
); | ||
require(!ok, "static call was supposed to fail with more parameters"); | ||
} | ||
|
||
function invalidStaticCallLessParameters(address _contract) public { | ||
bool ok; | ||
(ok,) = _contract.staticcall( | ||
abi.encodeWithSignature("getVarsAndVariable(uint256)") | ||
); | ||
require(!ok, "static call was supposed to fail with less parameters"); | ||
} | ||
|
||
function invalidStaticCallWithInnerCall(address _contract) public { | ||
bool ok; | ||
(ok,) = _contract.staticcall( | ||
abi.encodeWithSignature("getVarsAndVariable(uint256)") | ||
); | ||
require(!ok, "static call was supposed to fail with less parameters"); | ||
} | ||
|
||
function multiCall(address _contract, uint _num) public payable { | ||
call(_contract, _num); | ||
delegateCall(_contract, _num); | ||
staticCall(_contract); | ||
} | ||
|
||
function preEcrecover_0() public { | ||
bytes32 messHash = 0x456e9aea5e197a1f1af7a3e85a3212fa4049a3ba34c2289b4c860fc0b0c64ef3; | ||
uint8 v = 28; | ||
bytes32 r = 0x9242685bf161793cc25603c231bc2f568eb630ea16aa137d2664ac8038825608; | ||
bytes32 s = 0x4f8ae3bd7535248d0bd448298cc2e2071e56992d0774dc340c368ae950852ada; | ||
|
||
ecrecover(messHash, v, r, s); | ||
} | ||
} |
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,26 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract ChainCallLevel1 { | ||
function exec(address level2Addr, address level3Addr, address level4Addr) public payable { | ||
bool ok; | ||
(ok, ) = level2Addr.call( | ||
abi.encodeWithSignature("exec(address,address)", level3Addr, level4Addr) | ||
); | ||
require(ok, "failed to perform call to level 2"); | ||
|
||
(ok, ) = level2Addr.delegatecall( | ||
abi.encodeWithSignature("exec(address,address)", level3Addr, level4Addr) | ||
); | ||
require(ok, "failed to perform delegate call to level 2"); | ||
|
||
bytes memory result; | ||
(ok, result) = level2Addr.staticcall( | ||
abi.encodeWithSignature("get(address,address)", level3Addr, level4Addr) | ||
); | ||
require(ok, "failed to perform static call to level 2"); | ||
|
||
string memory t; | ||
(t) = abi.decode(result, (string)); | ||
} | ||
} |
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,27 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract ChainCallLevel2 { | ||
function exec(address level3Addr, address level4Addr) public payable { | ||
bool ok; | ||
(ok, ) = level3Addr.call(abi.encodeWithSignature("exec(address)", level4Addr)); | ||
require(ok, "failed to perform call to level 3"); | ||
|
||
(ok, ) = level3Addr.delegatecall(abi.encodeWithSignature("exec(address)", level4Addr)); | ||
require(ok, "failed to perform delegate call to level 3"); | ||
} | ||
|
||
function get(address level3Addr, address level4Addr) public view returns (string memory t) { | ||
bool ok; | ||
bytes memory result; | ||
(ok, result) = level3Addr.staticcall(abi.encodeWithSignature("get(address)", level4Addr)); | ||
require(ok, "failed to perform static call to level 3"); | ||
|
||
t = abi.decode(result, (string)); | ||
|
||
(ok, result) = level4Addr.staticcall(abi.encodeWithSignature("get()")); | ||
require(ok, "failed to perform static call to level 4 from level 2"); | ||
|
||
t = abi.decode(result, (string)); | ||
} | ||
} |
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,23 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract ChainCallLevel3 { | ||
function exec(address level4Addr) public payable { | ||
bool ok; | ||
(ok, ) = level4Addr.call(abi.encodeWithSignature("exec()")); | ||
require(ok, "failed to perform call to level 4"); | ||
|
||
(ok, ) = level4Addr.delegatecall(abi.encodeWithSignature("exec()")); | ||
require(ok, "failed to perform delegate call to level 4"); | ||
} | ||
|
||
function get(address level4Addr) public view returns (string memory t) { | ||
bool ok; | ||
bytes memory result; | ||
|
||
(ok, result) = level4Addr.staticcall(abi.encodeWithSignature("get()")); | ||
require(ok, "failed to perform static call to level 4"); | ||
|
||
t = abi.decode(result, (string)); | ||
} | ||
} |
Oops, something went wrong.