forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
print values in DELEGATECALL on callTracer + added contract for testi…
…ng (#914)
- Loading branch information
Showing
5 changed files
with
141 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
zk/debug_tools/test-contracts/contracts/DelegateCalled.sol
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 DelegateCalled { | ||
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); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
zk/debug_tools/test-contracts/contracts/DelegateCaller.sol
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 DelegateCaller { | ||
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) view 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) view 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) view 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() pure 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
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,31 @@ | ||
// deploys contracts and calls a method to produce delegate call | ||
async function main() { | ||
try { | ||
const DelegateCalled = await hre.ethers.getContractFactory("DelegateCalled"); | ||
const DelegateCaller = await hre.ethers.getContractFactory("DelegateCaller"); | ||
|
||
// Deploy the contracts | ||
const calledContract = await DelegateCalled.deploy(); | ||
const callerContract = await DelegateCaller.deploy(); | ||
|
||
// Wait for the deployment transactions to be mined | ||
await calledContract.waitForDeployment(); | ||
await callerContract.waitForDeployment(); | ||
|
||
console.log(`DelegateCalled deployed to: ${await calledContract.getAddress()}`); | ||
console.log(`DelegateCaller deployed to: ${await callerContract.getAddress()}`); | ||
|
||
const delegateCallResult = await callerContract.delegateCall(calledContract.getAddress(), 1); | ||
console.log('delegateCallResult method call transaction: ', delegateCallResult.hash); | ||
} catch (error) { | ||
console.error(error.toString()); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |