Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7a47f43
add internal call gas consumer
ben-chain Aug 6, 2020
d52186c
update changed EM gas overhead constant
ben-chain Aug 6, 2020
a852295
add first pass of SM gas virtualization proxy
ben-chain Aug 7, 2020
fbf1be0
finish proxy unit tests
ben-chain Aug 7, 2020
d4f583d
tests failing but EM updated
ben-chain Aug 7, 2020
e0d8e31
old gas metering tests passing with proxy
ben-chain Aug 9, 2020
17615f9
add gas consuming proxy, not working
ben-chain Aug 9, 2020
f37cac1
updates, need to refactor :(
ben-chain Aug 10, 2020
7a04554
first pass gas burn working
ben-chain Aug 10, 2020
f4686a2
more tests passing
ben-chain Aug 11, 2020
d44542c
all new gas tests passing
ben-chain Aug 11, 2020
040d618
cleaning
ben-chain Aug 11, 2020
cd06162
more cleanup, linting
ben-chain Aug 11, 2020
109c662
fixes, updating deployments
ben-chain Aug 11, 2020
40d1882
linting, renaming
ben-chain Aug 11, 2020
a67316e
pre fmsuf
ben-chain Aug 12, 2020
d3ff9ec
fix state transitioner tests
ben-chain Aug 12, 2020
cc920e5
linting
ben-chain Aug 12, 2020
aa84a07
remove .only
ben-chain Aug 12, 2020
26d9408
add back EVM precompile association
ben-chain Aug 12, 2020
384e9b2
linting
ben-chain Aug 12, 2020
81c2509
fix most fullnode tests, skipping events
ben-chain Aug 12, 2020
74114ad
linting, cleanup
ben-chain Aug 12, 2020
6bb7bf4
Merge remote-tracking branch 'origin' into feat/YAS422/enforce-SM-gas…
ben-chain Aug 12, 2020
3ecebe8
skip all fullnode tests
ben-chain Aug 12, 2020
e667ca7
Revert "skip all fullnode tests"
ben-chain Aug 12, 2020
037ab60
improve EM metadata functions
ben-chain Aug 12, 2020
1eba718
fix messed up gas vals, lint
ben-chain Aug 13, 2020
287a543
unused vars
ben-chain Aug 13, 2020
c7775d0
refactor queue inheritance pattern
ben-chain Aug 13, 2020
2036c02
add gas consumption to L1->L2
ben-chain Aug 14, 2020
a8874c1
all tests passing
ben-chain Aug 17, 2020
22c9896
fix CTC tests/proofs
ben-chain Aug 17, 2020
dc961a4
encoded event and log handling
ben-chain Aug 17, 2020
b4dbab2
Merge remote-tracking branch 'origin' into feat/YAS430/gas-limit-burn
ben-chain Aug 17, 2020
e9424f0
fix event test
ben-chain Aug 17, 2020
cf0ccf2
linting
ben-chain Aug 17, 2020
931b2a1
remove 'em
ben-chain Aug 24, 2020
b637744
fix test's compiler usage
ben-chain Aug 24, 2020
3338fd3
update yarn lock
ben-chain Aug 24, 2020
e7aeb33
remove .only
ben-chain Aug 24, 2020
08bd000
merge master
ben-chain Aug 24, 2020
70a69b3
merge upstream
ben-chain Aug 25, 2020
91d7323
linting
ben-chain Aug 25, 2020
088c2ac
patch failing test
ben-chain Aug 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ contract CanonicalTransactionChain is ContractResolver {
{
return keccak256(abi.encodePacked(
_batchHeader.timestamp,
_batchHeader.isL1ToL2Tx,
_batchHeader.isL1ToL2Tx, // TODO REPLACE WITH QUEUE ORIGIN (if you are a PR reviewer please lmk!)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

_batchHeader.elementsMerkleRoot,
_batchHeader.numElementsInBatch,
_batchHeader.cumulativePrevElements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { L2ToL1MessagePasser } from "./precompiles/L2ToL1MessagePasser.sol";
import { L1MessageSender } from "./precompiles/L1MessageSender.sol";
import { StateManager } from "./StateManager.sol";
import { SafetyChecker } from "./SafetyChecker.sol";
import { StateManagerGasSanitizer } from "./StateManagerGasSanitizer.sol";

/* Library Imports */
import { ContractResolver } from "../utils/resolvers/ContractResolver.sol";
Expand All @@ -15,6 +16,7 @@ import { RLPWriter } from "../utils/libraries/RLPWriter.sol";

/* Testing Imports */
import { StubSafetyChecker } from "./test-helpers/StubSafetyChecker.sol";
import { console } from "@nomiclabs/buidler/console.sol";

/**
* @title ExecutionManager
Expand Down Expand Up @@ -108,7 +110,7 @@ contract ExecutionManager is ContractResolver {
{
// Deploy a default state manager
StateManager stateManager = resolveStateManager();

// Associate all Ethereum precompiles
for (uint160 i = 1; i < 20; i++) {
stateManager.associateCodeContract(address(i), address(i));
Expand Down Expand Up @@ -241,10 +243,6 @@ contract ExecutionManager is ContractResolver {
// Set the active contract to be our EOA address
switchActiveContract(_fromAddress);

// Do pre-execution gas checks and updates
startNewGasEpochIfNecessary(_timestamp);
validateTxGasLimit(_ovmTxGasLimit, _queueOrigin);

// Set methodId based on whether we're creating a contract
bytes32 methodId;
uint256 callSize;
Expand Down Expand Up @@ -287,6 +285,10 @@ contract ExecutionManager is ContractResolver {
mstore8(add(_callBytes, 3), methodId)
}

// Do pre-execution gas checks and updates
startNewGasEpochIfNecessary(_timestamp);
validateTxGasLimit(_ovmTxGasLimit, _queueOrigin);
StateManagerGasSanitizer(address(resolveStateManager())).resetOVMGasRefund();
// subtract the flat gas fee off the tx gas limit which we will pass as gas
_ovmTxGasLimit -= gasMeterConfig.OvmTxBaseGasFee;

Expand Down Expand Up @@ -1022,7 +1024,6 @@ contract ExecutionManager is ContractResolver {
*/
function ovmEXTCODESIZE()
public
view
{
StateManager stateManager = resolveStateManager();
bytes32 _targetAddressBytes;
Expand Down Expand Up @@ -1053,7 +1054,6 @@ contract ExecutionManager is ContractResolver {
*/
function ovmEXTCODEHASH()
public
view
{
StateManager stateManager = resolveStateManager();
bytes32 _targetAddressBytes;
Expand Down Expand Up @@ -1089,7 +1089,6 @@ contract ExecutionManager is ContractResolver {
*/
function ovmEXTCODECOPY()
public
view
{
StateManager stateManager = resolveStateManager();
bytes32 _targetAddressBytes;
Expand Down Expand Up @@ -1147,12 +1146,12 @@ contract ExecutionManager is ContractResolver {
return executionContext.l1MessageSender;
}

function getCumulativeSequencedGas() public view returns(uint) {
return uint(StateManager(resolveStateManager()).getStorageView(METADATA_STORAGE_ADDRESS, CUMULATIVE_SEQUENCED_GAS_STORAGE_KEY));
function getCumulativeSequencedGas() public returns(uint) {
return uint(StateManager(resolveStateManager()).getStorage(METADATA_STORAGE_ADDRESS, CUMULATIVE_SEQUENCED_GAS_STORAGE_KEY));
}

function getCumulativeQueuedGas() public view returns(uint) {
return uint(StateManager(resolveStateManager()).getStorageView(METADATA_STORAGE_ADDRESS, CUMULATIVE_QUEUED_GAS_STORAGE_KEY));
function getCumulativeQueuedGas() public returns(uint) {
return uint(StateManager(resolveStateManager()).getStorage(METADATA_STORAGE_ADDRESS, CUMULATIVE_QUEUED_GAS_STORAGE_KEY));
}

/*
Expand Down Expand Up @@ -1226,17 +1225,20 @@ contract ExecutionManager is ContractResolver {
}

function updateCumulativeGas(uint _gasConsumed) internal {
uint refund = StateManagerGasSanitizer(address(resolveStateManager())).getOVMGasRefund();
if (executionContext.queueOrigin == 0) {
setCumulativeSequencedGas(
getCumulativeSequencedGas()
+ gasMeterConfig.OvmTxBaseGasFee
+ _gasConsumed
- refund
);
} else {
setCumulativeQueuedGas(
getCumulativeQueuedGas()
+ gasMeterConfig.OvmTxBaseGasFee
+ _gasConsumed
- refund
);
}
}
Expand Down Expand Up @@ -1386,56 +1388,67 @@ contract ExecutionManager is ContractResolver {
* @notice Sets the new cumulative sequenced gas as a result of tx execution.
*/
function setCumulativeSequencedGas(uint _value) internal {
StateManager(resolveStateManager()).setStorage(METADATA_STORAGE_ADDRESS, CUMULATIVE_SEQUENCED_GAS_STORAGE_KEY, bytes32(_value));
setMetadataStorageSlot(CUMULATIVE_SEQUENCED_GAS_STORAGE_KEY, bytes32(_value));
}

/**
* @notice Sets the new cumulative queued gas as a result of this new tx.
*/
function setCumulativeQueuedGas(uint _value) internal {
StateManager(resolveStateManager()).setStorage(METADATA_STORAGE_ADDRESS, CUMULATIVE_QUEUED_GAS_STORAGE_KEY, bytes32(_value));
setMetadataStorageSlot(CUMULATIVE_QUEUED_GAS_STORAGE_KEY, bytes32(_value));
}

/**
* @notice Gets what the cumulative sequenced gas was at the start of this gas rate limit epoch.
*/
function getGasRateLimitEpochStart() public view returns (uint) {
return uint(StateManager(resolveStateManager()).getStorageView(METADATA_STORAGE_ADDRESS, GAS_RATE_LMIT_EPOCH_START_STORAGE_KEY));
function getGasRateLimitEpochStart() public returns (uint) {
return uint(getMetadataStorageSlot(GAS_RATE_LMIT_EPOCH_START_STORAGE_KEY));
}

/**
* @notice Used to store the current time at the start of a new gas rate limit epoch.
*/
function setGasRateLimitEpochStart(uint _value) internal {
StateManager(resolveStateManager()).setStorage(METADATA_STORAGE_ADDRESS, GAS_RATE_LMIT_EPOCH_START_STORAGE_KEY, bytes32(_value));
setMetadataStorageSlot(GAS_RATE_LMIT_EPOCH_START_STORAGE_KEY, bytes32(_value));
}

/**
* @notice Sets the cumulative sequenced gas at the start of a new gas rate limit epoch.
*/
function setCumulativeSequencedGasAtEpochStart(uint _value) internal {
StateManager(resolveStateManager()).setStorage(METADATA_STORAGE_ADDRESS, CUMULATIVE_SEQUENCED_GAS_AT_EPOCH_START_STORAGE_KEY, bytes32(_value));
setMetadataStorageSlot(CUMULATIVE_SEQUENCED_GAS_AT_EPOCH_START_STORAGE_KEY, bytes32(_value));
}

/**
* @notice Gets what the cumulative sequenced gas was at the start of this gas rate limit epoch.
*/
function getCumulativeSequencedGasAtEpochStart() internal view returns (uint) {
return uint(StateManager(resolveStateManager()).getStorageView(METADATA_STORAGE_ADDRESS, CUMULATIVE_SEQUENCED_GAS_AT_EPOCH_START_STORAGE_KEY));
function getCumulativeSequencedGasAtEpochStart() internal returns (uint) {
return uint(getMetadataStorageSlot(CUMULATIVE_SEQUENCED_GAS_AT_EPOCH_START_STORAGE_KEY));
}

/**
* @notice Sets what the cumulative queued gas is at the start of a new gas rate limit epoch.
*/
function setCumulativeQueuedGasAtEpochStart(uint _value) internal {
StateManager(resolveStateManager()).setStorage(METADATA_STORAGE_ADDRESS, CUMULATIVE_QUEUED_GAS_AT_EPOCH_START_STORAGE_KEY, bytes32(_value));
setMetadataStorageSlot(CUMULATIVE_QUEUED_GAS_AT_EPOCH_START_STORAGE_KEY, bytes32(_value));
}

/**
* @notice Gets the cumulative queued gas was at the start of this gas rate limit epoch.
*/
function getCumulativeQueuedGasAtEpochStart() internal view returns (uint) {
return uint(StateManager(resolveStateManager()).getStorageView(METADATA_STORAGE_ADDRESS, CUMULATIVE_QUEUED_GAS_AT_EPOCH_START_STORAGE_KEY));
function getCumulativeQueuedGasAtEpochStart() internal returns (uint) {
return uint(getMetadataStorageSlot(CUMULATIVE_QUEUED_GAS_AT_EPOCH_START_STORAGE_KEY));
}

/**
* @notice Gets the OVM slot value for the given key at the METADATA_STORAGE_ADDRESS.
*/
function getMetadataStorageSlot(bytes32 _key) internal returns (bytes32) {
return StateManager(resolveStateManager()).getStorage(METADATA_STORAGE_ADDRESS, _key);
}

function setMetadataStorageSlot(bytes32 _key, bytes32 _value) internal {
StateManager(resolveStateManager()).setStorage(METADATA_STORAGE_ADDRESS, _key, _value);
}

/*
Expand All @@ -1455,6 +1468,6 @@ contract ExecutionManager is ContractResolver {
view
returns (StateManager)
{
return StateManager(resolveContract("StateManager"));
return StateManager(resolveContract("StateManagerGasSanitizer"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ contract FullStateManager is StateManager {
address _ovmContractAddress
)
public
view
returns (address)
{
return ovmAddressToCodeContractAddress[_ovmContractAddress];
Expand All @@ -203,7 +202,6 @@ contract FullStateManager is StateManager {
address _codeContractAddress
)
public
view
returns (address)
{
return codeContractAddressToOvmAddress[_codeContractAddress];
Expand All @@ -219,7 +217,6 @@ contract FullStateManager is StateManager {
address _codeContractAddress
)
public
view
returns (bytes memory codeContractBytecode)
{
assembly {
Expand All @@ -246,7 +243,6 @@ contract FullStateManager is StateManager {
address _codeContractAddress
)
public
view
returns (bytes32 _codeContractHash)
{
// TODO: Look up cached hash values eventually to avoid having to load all of this bytecode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma experimental ABIEncoderV2;
import { StateManager } from "./StateManager.sol";
import { StateTransitioner } from "./StateTransitioner.sol";
import { ExecutionManager } from "./ExecutionManager.sol";
import { StateManagerGasSanitizer } from "./StateManagerGasSanitizer.sol";

/* Library Imports */
import { ContractResolver } from "../utils/resolvers/ContractResolver.sol";
Expand Down Expand Up @@ -57,9 +58,9 @@ contract PartialStateManager is ContractResolver {
_;
}

modifier onlyExecutionManager {
ExecutionManager executionManager = resolveExecutionManager();
require(msg.sender == address(executionManager));
modifier onlyStateManagerGasSanitizer {
StateManagerGasSanitizer StateManagerGasSanitizer = resolveStateManagerGasSanitizer();
require(msg.sender == address(StateManagerGasSanitizer));
_;
}

Expand Down Expand Up @@ -278,7 +279,7 @@ contract PartialStateManager is ContractResolver {
bytes32 _slot
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
returns (bytes32)
{
flagIfNotVerifiedStorage(_ovmContractAddress, _slot);
Expand Down Expand Up @@ -315,7 +316,7 @@ contract PartialStateManager is ContractResolver {
bytes32 _value
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
{
if (!storageSlotTouched[_ovmContractAddress][_slot]) {
updatedStorageSlotContract[updatedStorageSlotCounter] = bytes32(bytes20(_ovmContractAddress));
Expand All @@ -342,7 +343,7 @@ contract PartialStateManager is ContractResolver {
address _ovmContractAddress
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
returns (uint)
{
flagIfNotVerifiedContract(_ovmContractAddress);
Expand Down Expand Up @@ -375,7 +376,7 @@ contract PartialStateManager is ContractResolver {
uint _value
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
{
// TODO: Figure out if we actually need to verify contracts here.
//flagIfNotVerifiedContract(_ovmContractAddress);
Expand All @@ -398,7 +399,7 @@ contract PartialStateManager is ContractResolver {
address _ovmContractAddress
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
{
flagIfNotVerifiedContract(_ovmContractAddress);

Expand Down Expand Up @@ -428,7 +429,7 @@ contract PartialStateManager is ContractResolver {
address _codeContractAddress
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
{
ovmAddressToCodeContractAddress[_ovmContractAddress] = _codeContractAddress;
}
Expand All @@ -442,7 +443,7 @@ contract PartialStateManager is ContractResolver {
address _ovmContractAddress
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
{
isVerifiedContract[_ovmContractAddress] = true;
setOvmContractNonce(_ovmContractAddress, 0);
Expand Down Expand Up @@ -472,7 +473,7 @@ contract PartialStateManager is ContractResolver {
address _ovmContractAddress
)
public
onlyExecutionManager
onlyStateManagerGasSanitizer
returns(address)
{
flagIfNotVerifiedContract(_ovmContractAddress);
Expand Down Expand Up @@ -586,10 +587,10 @@ contract PartialStateManager is ContractResolver {
* Contract Resolution
*/

function resolveExecutionManager()
function resolveStateManagerGasSanitizer()
internal
view returns (ExecutionManager)
view returns (StateManagerGasSanitizer)
{
return ExecutionManager(resolveContract("ExecutionManager"));
return StateManagerGasSanitizer(resolveContract("StateManagerGasSanitizer"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ contract StateManager {
// Contract code storage / contract address retrieval
function associateCodeContract(address _ovmContractAddress, address _codeContractAddress) public;
function registerCreatedContract(address _ovmContractAddress) public;
function getCodeContractAddressFromOvmAddress(address _ovmContractAddress) external view returns(address);
function getOvmAddressFromCodeContractAddress(address _codeContractAddress) external view returns(address);
function getCodeContractAddressFromOvmAddress(address _ovmContractAddress) external returns(address);
function getOvmAddressFromCodeContractAddress(address _codeContractAddress) external returns(address);
function getCodeContractBytecode(
address _codeContractAddress
) public view returns (bytes memory codeContractBytecode);
function getCodeContractHash(address _codeContractAddress) external view returns (bytes32 _codeContractHash);
) public returns (bytes memory codeContractBytecode);
function getCodeContractHash(address _codeContractAddress) external returns (bytes32 _codeContractHash);
}
Loading