Skip to content

Safety Transaction Queue and State Commitment Chain#143

Merged
K-Ho merged 39 commits intomasterfrom
YAS-407/RollupChain/SlowQueue
Jun 4, 2020
Merged

Safety Transaction Queue and State Commitment Chain#143
K-Ho merged 39 commits intomasterfrom
YAS-407/RollupChain/SlowQueue

Conversation

@K-Ho
Copy link
Contributor

@K-Ho K-Ho commented May 25, 2020

Description

Safety Transaction Queue: Open, free-for-all queue of transactions to enforce censorship resistance. Adds tests to enforce timestamp monotonicity in the CanonicalTransactionChain.

State Commitment Chain: Chain of state commitment batches. Implement functionality for proving that an element is at a given absolute position in the chain.

Fixes

  • Fixes #YAS-407 and YAS-376

Contributing Agreement

@K-Ho K-Ho changed the title Safety Transaction Queue Safety Transaction Queue and State Commitment Chain May 28, 2020
@K-Ho K-Ho mentioned this pull request Jun 2, 2020
1 task
Copy link
Collaborator

@ben-chain ben-chain left a comment

Choose a reason for hiding this comment

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

This is awesome!!! Found only one critical component left to add, and a few minor ways that could improve tests, but this is 🔥

Comment on lines 55 to 70
dt.TimestampedHash memory l1ToL2Header = l1ToL2Queue.peek();
if(!safetyQueue.isEmpty()) {
require(l1ToL2Header.timestamp <= safetyQueue.peekTimestamp(), "Must process older SafetyQueue batches first to enforce timestamp monotonicity");
}
_appendQueueBatch(l1ToL2Header, true);
l1ToL2Queue.dequeue();
}

function appendSafetyBatch() public {
dt.TimestampedHash memory safetyHeader = safetyQueue.peek();
if(!l1ToL2Queue.isEmpty()) {
require(safetyHeader.timestamp <= l1ToL2Queue.peekTimestamp(), "Must process older L1ToL2Queue batches first to enforce timestamp monotonicity");
}
_appendQueueBatch(safetyHeader, false);
safetyQueue.dequeue();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we are missing some sequencing authentication logic here--looks like these functions can be called by anyone right now, however they should not be callable by non-sequencers unless peekTimestamp() shows they are sufficiently old.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh whoops you can ignore this, forgot this authentication is handled by _appendQueueBatch!! Nice!

l1ToL2Queue.dequeue();
}

function appendTransactionBatch(bytes[] memory _txBatch, uint _timestamp) public {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit which I previously missed in review: I think appendSequencerTransactionBatch or something of that sort might be worthwhile to disambiguate here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 576c035

batch
)
await localBatch.generateTree()
return localBatch
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we have relatively good unit tests around this from the class which StateChainBatch extends, but a potentially good sanity check here would be to confirm that the elementsMerkleRoot which gets stored on-chain matches the localBatch's root returned here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think this is solved by the "calculates Batch header hash correctly" test - hard to check if the Merkle root is calculated the same since it's not actually stored, it's immediately hashed w/ the batch header and stored as the batch header hash

it('should return true for valid elements for different batches and elements', async () => {
await appendTxBatch(DEFAULT_TX_BATCH)
await appendTxBatch(DEFAULT_TX_BATCH)
const numBatches = 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

A small improvement of coverage here would be to make the batches distinct, e.g. batches = [abatch, adifferentbatch, adifferentdifferentbatch] and using for (let batch in batches). Just takes care of the edge case where we somehow verify against the previous batch, but since they are the same the inclusion proof still passes.

Copy link

@willmeister willmeister left a comment

Choose a reason for hiding this comment

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

👍 LGTM 👍

Left a stylistic suggestion re: if-then-require cases, but no need to incorporate it if you don't want to 😄

Comment on lines 56 to 58
if(!safetyQueue.isEmpty()) {
require(l1ToL2Header.timestamp <= safetyQueue.peekTimestamp(), "Must process older SafetyQueue batches first to enforce timestamp monotonicity");
}

Choose a reason for hiding this comment

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

Suggested change
if(!safetyQueue.isEmpty()) {
require(l1ToL2Header.timestamp <= safetyQueue.peekTimestamp(), "Must process older SafetyQueue batches first to enforce timestamp monotonicity");
}
require(safetyQueue.isEmpty() || l1ToL2Header.timestamp <= safetyQueue.peekTimestamp(), "Must process older SafetyQueue batches first to enforce timestamp monotonicity");

Comment on lines 65 to 67
if(!l1ToL2Queue.isEmpty()) {
require(safetyHeader.timestamp <= l1ToL2Queue.peekTimestamp(), "Must process older L1ToL2Queue batches first to enforce timestamp monotonicity");
}

Choose a reason for hiding this comment

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

Suggested change
if(!l1ToL2Queue.isEmpty()) {
require(safetyHeader.timestamp <= l1ToL2Queue.peekTimestamp(), "Must process older L1ToL2Queue batches first to enforce timestamp monotonicity");
}
require(l1ToL2Queue.isEmpty() || safetyHeader.timestamp <= l1ToL2Queue.peekTimestamp(), "Must process older L1ToL2Queue batches first to enforce timestamp monotonicity");

Comment on lines 100 to 103
require(_timestamp <= l1ToL2Queue.peekTimestamp(), "Must process older L1ToL2Queue batches first to enforce timestamp monotonicity");
}
if(!safetyQueue.isEmpty()) {
require(_timestamp <= safetyQueue.peekTimestamp(), "Must process older SafetyQueue batches first to enforce timestamp monotonicity");

Choose a reason for hiding this comment

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

Can do same thing here where you remove the if and incorporate the if logic in the require

@K-Ho K-Ho merged commit 5b3ce22 into master Jun 4, 2020
@K-Ho K-Ho mentioned this pull request Jun 5, 2020
1 task
@gakonst gakonst deleted the YAS-407/RollupChain/SlowQueue branch March 18, 2021 15:01
snario pushed a commit that referenced this pull request Apr 14, 2021
* add check and test

* uint->uint256
OptimismBot pushed a commit that referenced this pull request Jan 16, 2025
blockchaindevsh pushed a commit to blockchaindevsh/optimism that referenced this pull request Jan 25, 2025
theochap pushed a commit that referenced this pull request Dec 10, 2025
* WIP init commit for host tracking

* add telemetry

* address comments

* address more comments and add docs

* linter changes

* exclude host in just file ci commands
Zena-park added a commit to tokamak-network/optimism that referenced this pull request Dec 30, 2025
theochap pushed a commit that referenced this pull request Jan 15, 2026
### Description

Cleans up workspace manifest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants