Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 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
172dbe3
add blocknum to rollup queue
ben-chain Aug 18, 2020
e52c5b4
get CTC tests passing
ben-chain Aug 18, 2020
d848f33
add block num peek
ben-chain Aug 18, 2020
3d534b9
add monotonicity check tests
ben-chain Aug 18, 2020
b62ee57
add missing monotonicity assertion:
ben-chain Aug 18, 2020
88e29cf
add blocknumber bound check
ben-chain Aug 18, 2020
bc8307a
fix up all CTC tests
ben-chain Aug 18, 2020
66aa2cb
fix up broken SCC/FV tests
ben-chain Aug 19, 2020
d1371f4
add blocknumber to EM, testing
ben-chain Aug 19, 2020
a704162
fix up timing tests'
ben-chain Aug 19, 2020
0813bf9
Created the OVM toolchain and removed other packages
smartcontracts Aug 19, 2020
b8bfccb
Added a test for evm_increaseTime
smartcontracts Aug 20, 2020
bfdc295
Added eth_getProof and eth_getAccount RPC methods
smartcontracts Aug 20, 2020
80f59b4
Merged master
smartcontracts Aug 20, 2020
2b16717
Transitioned to new compiler, fixed a bug
smartcontracts Aug 20, 2020
630c4fb
Replace logger types
smartcontracts Aug 20, 2020
8a723f4
Fixed another type error
smartcontracts Aug 20, 2020
c1b8492
Added a build step for waffle
smartcontracts Aug 20, 2020
b2123ff
Updated ethereumjs-vm package name
smartcontracts Aug 20, 2020
7665780
Slight update to buidler plugins and README
smartcontracts Aug 20, 2020
f95e386
all tests passing
ben-chain Aug 20, 2020
e9e0508
merge js-vm fork
ben-chain Aug 21, 2020
a894cf3
linting
ben-chain Aug 21, 2020
794acb5
bump timeout
ben-chain Aug 21, 2020
0c78eeb
Merge remote-tracking branch 'origin/master' into feat/YAS432/add-l1-…
ben-chain Aug 24, 2020
a4f2a91
first stab update services
ben-chain Aug 24, 2020
67de0ea
update services to work on local deployment
ben-chain Aug 24, 2020
08ffacd
linting
ben-chain Aug 24, 2020
c7b2c89
Merge remote-tracking branch 'origin/master' into feat/YAS432/add-l1-…
ben-chain Aug 25, 2020
207b3dc
missed merge conflict
ben-chain Aug 25, 2020
575b287
remove unused function
ben-chain Aug 25, 2020
9409536
add missing mock fn
ben-chain Aug 25, 2020
113778b
blocknumber -> blockNumber
ben-chain Aug 25, 2020
cea0d11
Merge remote-tracking branch 'origin/master' into feat/YAS432/add-l1-…
ben-chain Aug 25, 2020
72b6639
missing rename
ben-chain Aug 25, 2020
ef04114
add missing name update
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 @@ -29,9 +29,11 @@ contract CanonicalTransactionChain is ContractResolver {

address public sequencer;
uint public forceInclusionPeriodSeconds;
uint public forceInclusionPeriodBlocks;
uint public cumulativeNumElements;
bytes32[] public batches;
uint public lastOVMTimestamp;
uint public lastOVMBlockNumber;


/*
Expand All @@ -53,6 +55,7 @@ contract CanonicalTransactionChain is ContractResolver {
{
sequencer = _sequencer;
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
forceInclusionPeriodBlocks = _forceInclusionPeriodSeconds / 13;
lastOVMTimestamp = 0;
}

Expand Down Expand Up @@ -86,6 +89,7 @@ contract CanonicalTransactionChain is ContractResolver {
{
return keccak256(abi.encodePacked(
_batchHeader.timestamp,
_batchHeader.blockNumber,
_batchHeader.isL1ToL2Tx, // TODO REPLACE WITH QUEUE ORIGIN (if you are a PR reviewer please lmk!)
_batchHeader.elementsMerkleRoot,
_batchHeader.numElementsInBatch,
Expand All @@ -94,11 +98,11 @@ contract CanonicalTransactionChain is ContractResolver {
}

/**
* Checks whether a sender is allowed to append to the chain.
* Checks whether an address is the sequencer.
* @param _sender Address to check.
* @return Whether or not the address can append.
* @return Whether or not the address is the sequencer.
*/
function authenticateAppend(
function isSequencer(
address _sender
)
public
Expand All @@ -121,7 +125,7 @@ contract CanonicalTransactionChain is ContractResolver {

require(
safetyQueue.isEmpty() || l1ToL2Header.timestamp <= safetyQueue.peekTimestamp(),
"Must process older SafetyQueue batches first to enforce timestamp monotonicity"
"Must process older SafetyQueue batches first to enforce OVM timestamp monotonicity"
);

_appendQueueBatch(l1ToL2Header, true);
Expand All @@ -141,7 +145,7 @@ contract CanonicalTransactionChain is ContractResolver {

require(
l1ToL2Queue.isEmpty() || safetyHeader.timestamp <= l1ToL2Queue.peekTimestamp(),
"Must process older L1ToL2Queue batches first to enforce timestamp monotonicity"
"Must process older L1ToL2Queue batches first to enforce OVM timestamp monotonicity"
);

_appendQueueBatch(safetyHeader, false);
Expand All @@ -155,15 +159,16 @@ contract CanonicalTransactionChain is ContractResolver {
*/
function appendSequencerBatch(
bytes[] memory _txBatch,
uint _timestamp
uint _timestamp,
uint _blockNumber
)
public
{
L1ToL2TransactionQueue l1ToL2Queue = resolveL1ToL2TransactionQueue();
SafetyTransactionQueue safetyQueue = resolveSafetyTransactionQueue();

require(
authenticateAppend(msg.sender),
isSequencer(msg.sender),
"Message sender does not have permission to append a batch"
);

Expand All @@ -178,31 +183,62 @@ contract CanonicalTransactionChain is ContractResolver {
);

require(
_timestamp <= now,
"Cannot submit a batch with a timestamp in the future"
_blockNumber + forceInclusionPeriodBlocks > block.number,
"Cannot submit a batch with a blockNumber older than the sequencer inclusion period"
);

require(
l1ToL2Queue.isEmpty() || _timestamp <= l1ToL2Queue.peekTimestamp(),
"Must process older L1ToL2Queue batches first to enforce timestamp monotonicity"
_timestamp <= now,
"Cannot submit a batch with a timestamp in the future"
);

require(
safetyQueue.isEmpty() || _timestamp <= safetyQueue.peekTimestamp(),
"Must process older SafetyQueue batches first to enforce timestamp monotonicity"
_blockNumber <= block.number,
"Cannot submit a batch with a blockNumber in the future"
);

if (!l1ToL2Queue.isEmpty()) {
require(
_timestamp <= l1ToL2Queue.peekTimestamp(),
"Must process older L1ToL2Queue batches first to enforce OVM timestamp monotonicity"
);

require(
_blockNumber <= l1ToL2Queue.peekBlockNumber(),
"Must process older L1ToL2Queue batches first to enforce OVM blockNumber monotonicity"
);
}

if (!safetyQueue.isEmpty()) {
require(
_timestamp <= safetyQueue.peekTimestamp(),
"Must process older SafetyQueue batches first to enforce OVM timestamp monotonicity"
);

require(
_blockNumber <= safetyQueue.peekBlockNumber(),
"Must process older SafetyQueue batches first to enforce OVM blockNumber monotonicity"
);
}

require(
_timestamp >= lastOVMTimestamp,
"Timestamps must monotonically increase"
);

require(
_blockNumber >= lastOVMBlockNumber,
"BlockNumbers must monotonically increase"
);

lastOVMTimestamp = _timestamp;
lastOVMBlockNumber = _blockNumber;

RollupMerkleUtils merkleUtils = resolveRollupMerkleUtils();
bytes32 batchHeaderHash = keccak256(abi.encodePacked(
_timestamp,
false, // isL1ToL2Tx
_blockNumber,
false, // isL1ToL2Tx TODO: replace with queue origin
merkleUtils.getMerkleRoot(_txBatch), // elementsMerkleRoot
_txBatch.length, // numElementsInBatch
cumulativeNumElements // cumulativeNumElements
Expand Down Expand Up @@ -270,18 +306,21 @@ contract CanonicalTransactionChain is ContractResolver {
internal
{
uint timestamp = _timestampedHash.timestamp;
uint blockNumber = _timestampedHash.blockNumber;

require(
timestamp + forceInclusionPeriodSeconds <= now || authenticateAppend(msg.sender),
timestamp + forceInclusionPeriodSeconds <= now || isSequencer(msg.sender),
"Message sender does not have permission to append this batch"
);

lastOVMTimestamp = timestamp;
lastOVMBlockNumber = blockNumber;
bytes32 elementsMerkleRoot = _timestampedHash.txHash;
uint numElementsInBatch = 1;

bytes32 batchHeaderHash = keccak256(abi.encodePacked(
timestamp,
blockNumber,
_isL1ToL2Tx,
elementsMerkleRoot,
numElementsInBatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ contract ExecutionManager is ContractResolver {
// Make the EOA call for the account
executeTransaction(
_timestamp,
0, // note: since executeEOACall is soon to be deprecated, not bothering to add blockNumber here.
_queueOrigin,
_ovmEntrypoint,
_callBytes,
Expand All @@ -214,6 +215,7 @@ contract ExecutionManager is ContractResolver {
* Execute a transaction. Note that unsigned EOA calls are unauthenticated.
* This means that they should not be allowed for normal execution.
* @param _timestamp The timestamp which should be used for this call's context.
* @param _blockNumber The blockNumber which should be used for this call's context.
* @param _queueOrigin The parent-chain queue from which this call originated.
* @param _ovmEntrypoint The contract which this transaction should be executed against.
* @param _callBytes The calldata for this ovm transaction.
Expand All @@ -223,6 +225,7 @@ contract ExecutionManager is ContractResolver {
*/
function executeTransaction(
uint _timestamp,
uint _blockNumber,
uint _queueOrigin,
address _ovmEntrypoint,
bytes memory _callBytes,
Expand All @@ -238,7 +241,7 @@ contract ExecutionManager is ContractResolver {
require(_timestamp > 0, "Timestamp must be greater than 0");

// Initialize our context
initializeContext(_timestamp, _queueOrigin, _fromAddress, _l1MsgSenderAddress, _ovmTxGasLimit);
initializeContext(_timestamp, _blockNumber, _queueOrigin, _fromAddress, _l1MsgSenderAddress, _ovmTxGasLimit);

// Set the active contract to be our EOA address
switchActiveContract(_fromAddress);
Expand Down Expand Up @@ -479,6 +482,28 @@ contract ExecutionManager is ContractResolver {
}
}

/**
* @notice NUMBER opcode
* This gets the current blockNumber. Since the L2 value for this
* will necessarily be different than L1, this needs to be overridden for the OVM.
* Note: This is a raw function, so there are no listed (ABI-encoded) inputs / outputs.
* Below format of the bytes expected as input and written as output:
* calldata: 4 bytes: [methodID (bytes4)]
* returndata: uint256 representing the current blockNumber.
*/
function ovmNUMBER()
public
view
{
uint t = executionContext.blockNumber;

assembly {
let timestampMemory := mload(0x40)
mstore(timestampMemory, t)
return(timestampMemory, 32)
}
}

/**
* @notice CHAINID opcode
* This gets the chain id. Since the L2 value for this
Expand Down Expand Up @@ -1315,6 +1340,7 @@ contract ExecutionManager is ContractResolver {
*/
function initializeContext(
uint _timestamp,
uint _blockNumber,
uint _queueOrigin,
address _ovmTxOrigin,
address _l1MsgSender,
Expand All @@ -1326,9 +1352,10 @@ contract ExecutionManager is ContractResolver {
// reserved for the genesis contract & initial msgSender).
restoreContractContext(ZERO_ADDRESS, ZERO_ADDRESS);

// And finally set the timestamp, queue origin, tx origin, and
// And finally set the timestamp, blockNumber, queue origin, tx origin, and
// l1MessageSender.
executionContext.timestamp = _timestamp;
executionContext.blockNumber = _blockNumber;
executionContext.queueOrigin = _queueOrigin;
executionContext.ovmTxOrigin = _ovmTxOrigin;
executionContext.l1MessageSender = _l1MsgSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ contract StateTransitioner is IStateTransitioner, ContractResolver {
// Execute the transaction via the execution manager.
executionManager.executeTransaction(
_transactionData.timestamp,
_transactionData.blockNumber,
_transactionData.queueOrigin,
_transactionData.ovmEntrypoint,
_transactionData.callBytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract RollupQueue {

/**
* Peeks the timestamp of the front element on the queue.
* @return Front queue element timestamp.
* @return Front queue element timestamp (lowest in queue).
*/
function peekTimestamp()
public
Expand All @@ -70,14 +70,16 @@ contract RollupQueue {
}

/**
* Checks if this is a calldata transaction queue.
* @return Whether or not this is a calldata tx queue.
* Peeks the blockNumber of the front element on the queue.
* @return Front queue element blockNumber (lowest in queue).
*/
function isCalldataTxQueue()
function peekBlockNumber()
public
returns (bool)
view
returns (uint)
{
return true;
DataTypes.TimestampedHash memory frontBatch = peek();
return frontBatch.blockNumber;
}

/*
Expand All @@ -96,8 +98,9 @@ contract RollupQueue {
bytes32 txHash = keccak256(_data);

batchHeaders.push(DataTypes.TimestampedHash({
txHash: txHash,
timestamp: now,
txHash: txHash
blockNumber: block.number
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ library DataTypes {
bool inStaticContext;
uint chainId;
uint timestamp;
uint blockNumber;
uint queueOrigin;
address ovmActiveContract;
address ovmMsgSender;
Expand Down Expand Up @@ -64,15 +65,17 @@ library DataTypes {

struct TxChainBatchHeader {
uint timestamp;
uint blockNumber;
bool isL1ToL2Tx;
bytes32 elementsMerkleRoot;
uint numElementsInBatch;
uint cumulativePrevElements;
}

struct TimestampedHash {
uint timestamp;
bytes32 txHash;
uint timestamp;
uint blockNumber;
}

struct AccountState {
Expand All @@ -91,6 +94,7 @@ library DataTypes {

struct OVMTransactionData {
uint256 timestamp;
uint256 blockNumber;
uint256 queueOrigin;
address ovmEntrypoint;
bytes callBytes;
Expand Down
27 changes: 27 additions & 0 deletions packages/contracts/contracts/test-helpers/ContextContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ contract ContextContract {
}
}

function getNUMBER() public {
// bitwise right shift 28 * 8 bits so the 4 method ID bytes are in the right-most bytes
bytes32 methodId = keccak256("ovmNUMBER()") >> 224;
address addr = executionManagerAddress;

assembly {
let callBytes := mload(0x40)
calldatacopy(callBytes, 0, calldatasize)

// replace the first 4 bytes with the right methodID
mstore8(callBytes, shr(24, methodId))
mstore8(add(callBytes, 1), shr(16, methodId))
mstore8(add(callBytes, 2), shr(8, methodId))
mstore8(add(callBytes, 3), methodId)

// overwrite call params
let result := mload(0x40)
let success := call(gas, addr, 0, callBytes, calldatasize, result, 32)

if eq(success, 0) {
revert(result, returndatasize)
}

return(result, returndatasize)
}
}

function getADDRESS() public {
// bitwise right shift 28 * 8 bits so the 4 method ID bytes are in the right-most bytes
bytes32 methodId = keccak256("ovmADDRESS()") >> 224;
Expand Down
Loading