-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding more scenarios of test with dynamic execution context
- Loading branch information
Showing
7 changed files
with
733 additions
and
8 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
147 changes: 147 additions & 0 deletions
147
.../src/test/resources/dsl/transaction_storage_rskip446/dynamic_execution_context_simple.txt
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,147 @@ | ||
comment | ||
|
||
// CONTRACT CODE | ||
pragma solidity ^0.8.24; | ||
|
||
contract TestTransientStorageCallAndDelegateCall { | ||
|
||
constructor() { | ||
} | ||
|
||
event OK(); | ||
event ERROR(string, uint256); | ||
|
||
function testCallCodeAndDelegateCall(uint256 useCallCode) external { | ||
// Deploy the Callee contract | ||
address calleeAddress = address(new Callee()); | ||
uint256 success; | ||
uint256 valueLoadedFrom0; | ||
uint256 valueLoadedFrom1; | ||
uint256 valueLoadedSstore2; | ||
uint256 valueLoadedSstore3; | ||
bytes4 executeSignature = bytes4(keccak256("execute()")); | ||
|
||
assembly { | ||
tstore(0, 420) | ||
let availablePointer := mload(0x40) | ||
mstore(availablePointer, executeSignature) | ||
|
||
// If useCallCode is 0, execute callCode otherwise execute delegateCall | ||
switch useCallCode | ||
case 1 { | ||
success := callcode(gas(), calleeAddress, 0, availablePointer, 0x4, availablePointer, 0x20) | ||
} | ||
default { | ||
success := delegatecall(gas(), calleeAddress, availablePointer, 0x4, availablePointer, 0x20) | ||
} | ||
valueLoadedFrom0 := tload(0) | ||
valueLoadedSstore2 := sload(2) | ||
valueLoadedSstore3 := sload(3) | ||
valueLoadedFrom1 := tload(1) | ||
} | ||
|
||
checkReturnValueExpected(success, 'Checking result callee execution', 1); | ||
checkReturnValueExpected(valueLoadedFrom0, 'Checking value from tload 0', 420); | ||
checkReturnValueExpected(valueLoadedSstore2, 'Checking value from sstore 2', 420); | ||
checkReturnValueExpected(valueLoadedSstore3, 'Checking value from sstore 3', 69); | ||
checkReturnValueExpected(valueLoadedFrom1, 'Checking value from tload 1', 69); | ||
} | ||
|
||
function checkReturnValueExpected(uint256 valueReceived, string memory message, uint256 expectedValue) private { | ||
if( valueReceived == expectedValue){ | ||
emit OK(); | ||
} else { | ||
emit ERROR(message, valueReceived); | ||
} | ||
} | ||
} | ||
|
||
contract Callee { | ||
|
||
function execute() external { | ||
assembly { | ||
sstore(2, tload(0)) | ||
tstore(1, 69) | ||
sstore(3, tload(1)) | ||
} | ||
} | ||
} | ||
|
||
// CONTRACT BYTECODE | ||
|
||
TestTransientStorageCallAndDelegateCall: 6080604052348015600e575f5ffd5b5061048e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063a61face91461002d575b5f5ffd5b610047600480360381019061004291906102ec565b610049565b005b5f604051610056906102a9565b604051809103905ff08015801561006f573d5f5f3e3d5ffd5b5090505f5f5f5f5f5f7f614619540b5b5abe478b88f28a37eb328054be3b41a7570ad5e8b701113364c490506101a45f5d60405181815288600181146100bf576020826004848c5af497506100cc565b6020826004845f8d5af297505b505f5c95506002549350600354925060015c945050610122866040518060400160405280602081526020017f436865636b696e6720726573756c742063616c6c656520657865637574696f6e8152506001610232565b610164856040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d20746c6f6164203000000000008152506101a4610232565b6101a6836040518060400160405280601c81526020017f436865636b696e672076616c75652066726f6d207373746f72652032000000008152506101a4610232565b6101e7826040518060400160405280601c81526020017f436865636b696e672076616c75652066726f6d207373746f72652033000000008152506045610232565b610228846040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d20746c6f6164203100000000008152506045610232565b5050505050505050565b80830361026a577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16102a4565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f828460405161029b929190610396565b60405180910390a15b505050565b6094806103c583390190565b5f5ffd5b5f819050919050565b6102cb816102b9565b81146102d5575f5ffd5b50565b5f813590506102e6816102c2565b92915050565b5f60208284031215610301576103006102b5565b5b5f61030e848285016102d8565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f61035982610317565b6103638185610321565b9350610373818560208601610331565b61037c8161033f565b840191505092915050565b610390816102b9565b82525050565b5f6040820190508181035f8301526103ae818561034f565b90506103bd6020830184610387565b939250505056fe6080604052348015600e575f5ffd5b50607a80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c80636146195414602a575b5f5ffd5b60306032565b005b5f5c600255604560015d60015c60035556fea26469706673582212201771c67495697664bc8f0b297a683b4e7dbb7e31feaf9cf735faf209a14d64fa64736f6c634300081c0033a2646970667358221220ce4a7e6da5344a1d5a34ebef6c0267ac15796a3a9529427da9ba17a9cc4bee0864736f6c634300081c0033 | ||
|
||
a61face9: testCallCodeAndDelegateCall(uint256) | ||
|
||
end | ||
|
||
# Create and fund new account | ||
account_new acc1 10000000 | ||
|
||
# Create transaction to deploy TestTransientStorageCallAndDelegateCall contract | ||
transaction_build txCallAndDelegateCallSimpleTest | ||
sender acc1 | ||
receiverAddress 00 | ||
value 0 | ||
data 6080604052348015600e575f5ffd5b5061048e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063a61face91461002d575b5f5ffd5b610047600480360381019061004291906102ec565b610049565b005b5f604051610056906102a9565b604051809103905ff08015801561006f573d5f5f3e3d5ffd5b5090505f5f5f5f5f5f7f614619540b5b5abe478b88f28a37eb328054be3b41a7570ad5e8b701113364c490506101a45f5d60405181815288600181146100bf576020826004848c5af497506100cc565b6020826004845f8d5af297505b505f5c95506002549350600354925060015c945050610122866040518060400160405280602081526020017f436865636b696e6720726573756c742063616c6c656520657865637574696f6e8152506001610232565b610164856040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d20746c6f6164203000000000008152506101a4610232565b6101a6836040518060400160405280601c81526020017f436865636b696e672076616c75652066726f6d207373746f72652032000000008152506101a4610232565b6101e7826040518060400160405280601c81526020017f436865636b696e672076616c75652066726f6d207373746f72652033000000008152506045610232565b610228846040518060400160405280601b81526020017f436865636b696e672076616c75652066726f6d20746c6f6164203100000000008152506045610232565b5050505050505050565b80830361026a577fd48fe2800bace8f5ca2450feacbd6efc681b1cd0115019bb49fa529b6171bf6760405160405180910390a16102a4565b7fc9e730d5b570f89e168eb8c3d29f8c396b957e540af248c95c9519ac47c2c69f828460405161029b929190610396565b60405180910390a15b505050565b6094806103c583390190565b5f5ffd5b5f819050919050565b6102cb816102b9565b81146102d5575f5ffd5b50565b5f813590506102e6816102c2565b92915050565b5f60208284031215610301576103006102b5565b5b5f61030e848285016102d8565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f61035982610317565b6103638185610321565b9350610373818560208601610331565b61037c8161033f565b840191505092915050565b610390816102b9565b82525050565b5f6040820190508181035f8301526103ae818561034f565b90506103bd6020830184610387565b939250505056fe6080604052348015600e575f5ffd5b50607a80601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106026575f3560e01c80636146195414602a575b5f5ffd5b60306032565b005b5f5c600255604560015d60015c60035556fea26469706673582212201771c67495697664bc8f0b297a683b4e7dbb7e31feaf9cf735faf209a14d64fa64736f6c634300081c0033a2646970667358221220ce4a7e6da5344a1d5a34ebef6c0267ac15796a3a9529427da9ba17a9cc4bee0864736f6c634300081c0033 | ||
gas 1000000 | ||
build | ||
|
||
# Create block to hold txCallAndDelegateCallSimpleTest transaction | ||
block_build b01 | ||
parent g00 | ||
transactions txCallAndDelegateCallSimpleTest | ||
gasLimit 1200000 | ||
build | ||
|
||
# Connect block | ||
block_connect b01 | ||
|
||
# Check b01 is best block | ||
assert_best b01 | ||
|
||
# Create transaction to execute txExecuteCallCode transaction | ||
transaction_build txExecuteCallCode | ||
sender acc1 | ||
nonce 1 | ||
contract txCallAndDelegateCallSimpleTest | ||
value 0 | ||
data a61face90000000000000000000000000000000000000000000000000000000000000001 | ||
gas 1000000 | ||
build | ||
|
||
# Create block to hold txExecuteCallCode transaction | ||
block_build b02 | ||
parent b01 | ||
transactions txExecuteCallCode | ||
gasLimit 2000000 | ||
build | ||
|
||
# Connect block | ||
block_connect b02 | ||
|
||
# Check b02 is best block | ||
assert_best b02 | ||
|
||
# Create transaction to execute txExecuteDelegateCall transaction | ||
transaction_build txExecuteDelegateCall | ||
sender acc1 | ||
nonce 2 | ||
contract txCallAndDelegateCallSimpleTest | ||
value 0 | ||
data a61face90000000000000000000000000000000000000000000000000000000000000000 | ||
gas 1000000 | ||
build | ||
|
||
# Create block to hold txExecuteDelegateCall transaction | ||
block_build b03 | ||
parent b02 | ||
transactions txExecuteDelegateCall | ||
gasLimit 2000000 | ||
build | ||
|
||
# Connect block | ||
block_connect b03 | ||
|
||
# Check b03 is best block | ||
assert_best b03 |
Oops, something went wrong.