Commit 21f3098f authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

feat/simulate message (#238)

* add function

* cleaning

* fix revert prefixing and add test revertmsg

* write SM

* debug: progress

* Remove unnecessary logs

* Fix typo

Typo
Co-authored-by: default avatarben-chain <ben@pseudonym.party>

* Update contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol
Co-authored-by: default avatarben-chain <ben@pseudonym.party>
Co-authored-by: default avatarBen Jones <ben@pseudonym.party>
Co-authored-by: default avatarKelvin Fichter <kelvinfichter@gmail.com>
parent 2e4182cb
...@@ -29,7 +29,7 @@ import { OVM_DeployerWhitelist } from "../precompiles/OVM_DeployerWhitelist.sol" ...@@ -29,7 +29,7 @@ import { OVM_DeployerWhitelist } from "../precompiles/OVM_DeployerWhitelist.sol"
* OVM operation, which will read state from the State Manager contract. * OVM operation, which will read state from the State Manager contract.
* The EM relies on the Safety Checker to verify that code deployed to Layer 2 does not contain any * The EM relies on the Safety Checker to verify that code deployed to Layer 2 does not contain any
* context-dependent operations. * context-dependent operations.
* *
* Compiler used: solc * Compiler used: solc
* Runtime target: EVM * Runtime target: EVM
*/ */
...@@ -891,7 +891,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver { ...@@ -891,7 +891,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
if (!isAllowed || !success) { if (!isAllowed || !success) {
_revertWithFlag(RevertFlag.CREATOR_NOT_ALLOWED); _revertWithFlag(RevertFlag.CREATOR_NOT_ALLOWED);
} }
} }
/******************************************** /********************************************
...@@ -967,7 +967,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver { ...@@ -967,7 +967,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
// We reserve addresses of the form 0xdeaddeaddead...NNNN for the container contracts in L2 geth. // We reserve addresses of the form 0xdeaddeaddead...NNNN for the container contracts in L2 geth.
// So, we block calls to these addresses since they are not safe to run as an OVM contract itself. // So, we block calls to these addresses since they are not safe to run as an OVM contract itself.
if ( if (
(uint256(_contract) & uint256(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000)) (uint256(_contract) & uint256(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000))
== uint256(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000) == uint256(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000)
) { ) {
return (true, hex''); return (true, hex'');
...@@ -1051,7 +1051,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver { ...@@ -1051,7 +1051,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
_revertWithFlag(flag); _revertWithFlag(flag);
} }
// INTENTIONAL_REVERT, UNSAFE_BYTECODE, STATIC_VIOLATION, and CREATOR_NOT_ALLOWED aren't // INTENTIONAL_REVERT, UNSAFE_BYTECODE, STATIC_VIOLATION, and CREATOR_NOT_ALLOWED aren't
// dependent on the input state, so we can just handle them like standard reverts. Our only change here // dependent on the input state, so we can just handle them like standard reverts. Our only change here
// is to record the gas refund reported by the call (enforced by safety checking). // is to record the gas refund reported by the call (enforced by safety checking).
if ( if (
...@@ -1805,4 +1805,38 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver { ...@@ -1805,4 +1805,38 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager, Lib_AddressResolver {
messageRecord.nuisanceGasLeft = 0; messageRecord.nuisanceGasLeft = 0;
messageRecord.revertFlag = RevertFlag.DID_NOT_REVERT; messageRecord.revertFlag = RevertFlag.DID_NOT_REVERT;
} }
/*****************************
* L2-only Helper Functions *
*****************************/
/**
* Unreachable helper function for simulating eth_calls with an OVM message context.
* This function will throw an exception in all cases other than when used as a custom entrypoint in L2 Geth to simulate eth_call.
* @param _transaction the message transaction to simulate.
* @param _from the OVM account the simulated call should be from.
*/
function simulateMessage(
Lib_OVMCodec.Transaction memory _transaction,
address _from,
iOVM_StateManager _ovmStateManager
)
external
returns (
bool,
bytes memory
)
{
// Prevent this call from having any effect unless in a custom-set VM frame
require(msg.sender == address(0));
ovmStateManager = _ovmStateManager;
_initContext(_transaction);
messageRecord.nuisanceGasLeft = uint(-1);
messageContext.ovmADDRESS = _transaction.entrypoint;
messageContext.ovmCALLER = _from;
return _transaction.entrypoint.call{gas: _transaction.gasLimit}(_transaction.data);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment