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

feat: constraining slots #7758

Merged
merged 9 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions docs/docs/guides/developer_guides/js_apps/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,12 @@ The [`CheatCodes`](../../../reference/developer_references/sandbox_reference/che

### Set next block timestamp

The `warp` method sets the time for next execution, both on L1 and L2. We can test this using an `isTimeEqual` function in a `Test` contract defined like the following:
Since the rollup time is dependent on what "slot" the block is included in, time can be progressed by progressing slots.
The duration of a slot is available by calling `SLOT_DURATION()` on the Rollup (code in Leonidas.sol).

#include_code is-time-equal noir-projects/noir-contracts/contracts/test_contract/src/main.nr rust
You can then use the `warp` function on the EthCheatCodes to progress the underlying chain.

We can then call `warp` and rely on the `isTimeEqual` function to check that the timestamp was properly modified.

#include_code warp /yarn-project/end-to-end/src/guides/dapp_testing.test.ts typescript
<!--#include_code warp /yarn-project/end-to-end/src/guides/dapp_testing.test.ts typescript-->

## Further reading

Expand Down
31 changes: 23 additions & 8 deletions docs/docs/protocol-specs/l1-smart-contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,33 @@ The state transitioner is the heart of the validating light node for the L2.
The contract keeps track of the current state of the L2 and progresses this state when a valid L2 block is received.
It also facilitates cross-chain communication (communication between the L1 inbox and outbox contracts).

:::info
The following example shows a simplified case where proof and block are provided in the same transaction.
:::

```python
class StateTransitioner:

struct BlockLog:
archive: bytes32
slot_number: uint128

VERIFIER: immutable(IVerifier)
AVAILABILITY_ORACLE: immutable(IAvailabilityOracle)
INBOX: immutable(IInbox)
OUTBOX: immutable(IOutbox)
VERSION: immutable(uint256)
GENESIS_TIME: immutable(uint256)
SLOT_DURATION: immutable(uint256)

archive: TreeSnapshot
block_number: uint256
last_block_ts: uint256
blocks: BlockLog[]

def __init__(self, ...):
'''
Initialize the state transitioner
'''
self.blocks.append(BlockLog({archive: bytes32(0), slot_number: 0}))
self.GENESIS_TIME = block.timestamp

def process(
self,
Expand All @@ -131,19 +141,24 @@ class StateTransitioner:
header.content_commitment.out_hash,
header.content_commitment.tx_tree_height + math.ceil(log2(MAX_L2_TO_L1_MSGS_PER_TX))
)
self.blocks.append(BlockLog({
archive: archive,
slot_number: header.global_variables.slot_number
}))
self.archive = archive
emit BlockProcessed(block_number)

def validate_header(
self,
header: Header
) -> bool:
assert header.global_variables.block_number = self.block_number + 1
assert header.global_variables.block_number = len(self.blocks)
assert header.global_variables.chain_id == block.chain_id
assert header.global_variables.version == self.version
assert header.global_variables.timestamp < block.timestamp
assert header.global_variables.timestamp > self.last_block_ts
assert header.archive == self.archive
assert header.global_variables.version == self.VERSION
assert header.global_variables.timestamp == self.GENESIS_TIME + self.SLOT_DURATION * header.global_variables.slot_number
last_block = self.blocks[-1]
assert header.global_variables.slot_number > last_block.slot_number
assert header.archive == last_block.archive
return True
```

Expand Down
Loading
Loading