Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add / edit code comments to createNewAssertion #457

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions contracts/src/rollup/RollupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
require(assertion.beforeState.machineStatus == MachineStatus.FINISHED, "BAD_PREV_STATUS");

AssertionNode storage prevAssertion = getAssertionStorage(prevAssertionHash);
// Required inbox position through which the next assertion (the one after this new assertion) must consume
uint256 nextInboxPosition;
bytes32 sequencerBatchAcc;
{
// This new assertion consumes the messages from prevInboxPosition to afterInboxPosition
uint64 afterInboxPosition = assertion.afterState.globalState.getInboxPosition();
uint64 prevInboxPosition = assertion.beforeState.globalState.getInboxPosition();

Expand All @@ -411,7 +413,8 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {

// SANITY CHECK: the next inbox position did indeed move forward
// this is enforced by code in a later section that artificially increases the nextInboxPosition
// if it hadn't changed the next inbox always increasing means that the assertions will continue to advance
// even if there hadn't been any new messages since the last assertion;
// this ensures that assertions will continue to advance.
// It also means that below, where we check that afterInboxPosition equals prev.nextInboxPosition
// in the FINISHED state, we can be sure that it processed at least one message
require(assertion.beforeStateData.configData.nextInboxPosition > prevInboxPosition, "NEXT_INBOX_BACKWARDS");
Expand All @@ -425,7 +428,7 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
);
}
} else if (assertion.afterState.machineStatus == MachineStatus.FINISHED) {
// if the machine is FINISHED, then it should consume all messages in the inbox as seen at the time of prev
// if the machine is FINISHED, then it should consume all messages in the inbox as seen at the time of prev (and possibly one additional message; see below)
require(
afterInboxPosition == assertion.beforeStateData.configData.nextInboxPosition,
"INVALID_FINISHED_INBOX"
Expand All @@ -436,7 +439,7 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
// we checked this above, but include a safety check here in case of refactoring
revert("INVALID_STATUS");
}

// Inbox position at the time of this assertion being created
uint256 currentInboxPosition = bridge.sequencerMessageCount();
// Cannot read more messages than currently exist in the inbox
require(afterInboxPosition <= currentInboxPosition, "INBOX_PAST_END");
Expand All @@ -455,7 +458,9 @@ abstract contract RollupCore is IRollupCore, PausableUpgradeable {
// No new messages have been added to the inbox since the last assertion
// In this case if we set the next inbox position to the current one we would be insisting that
// the next assertion process no messages. So instead we increment the next inbox position to current
// plus one, so that the next assertion will process exactly one message
// plus one, so that the next assertion will process exactly one message.
// Thus, no assertion can be empty (except the genesis assertion, which is created
// via a different codepath).
nextInboxPosition = currentInboxPosition + 1;
} else {
nextInboxPosition = currentInboxPosition;
Expand Down
Loading