Skip to main content
OP Stack interop is in active development. Some features may be experimental.
We showcase cross chain composability through the implementation of contests. Leveraging the same underlying mechanism powering TicTacToe, these contests can permissionlessly integrate with the events emitted by any contract on OP Stack chains.
See the frontend documentation for how the contests UI is presented to the user.

How it works

Unlike TicTacToe which is deployed on every participating chain, the contests are deployed on a single L2, behaving like an application-specific OP Stack chain rather than a horizontally scaled app.
1

Implement contests

Contests.sol contains the implementation of the contests. We won’t go into the details of the implementation here, but instead focus on how the contests can leverage cross chain event reading to compose with other contracts on OP Stack chains.
2

Read cross-chain events

The system predeploy that enables pulling in validated cross-chain events is the CrossL2Inbox.
3

Create the contest

The two contest options are detailed below: BlockHash contest and TicTacToe contest.

BlockHash contest

With the existence of an event that emits the blockhash and height of a block, we can create a contest on the parity of the blockhash being even or odd.
Integrating this emitter into a contest is extremely simple. The BlockHashContestFactory is a simple factory that creates a new contest for a given chain and block height.

TicTacToe contest

A contest for TicTacToe is created on an accepted game between two players, captured by the emitted AcceptedGame event. When decoding the event, the game is uniquely identified by the chain it was created on, chainId, and the associated gameId. These identifying properties of the game are used to create the resolver for the game.
4

Resolve contest

A contest is identified by and has its outcome determined by the IContestResolver instance. The resolver starts in the UNDECIDED state, updated into YES or NO when resolving itself with the contest.

Resolve BlockHash contest

When live, anyone can resolve the BlockHash contest by simply providing the right BlockHash event to the deployed resolver.

Resolve TicTacToe contest

When live, anyone can resolve the TicTacToe contest by providing the GameWon or GameDraw event of the associated game from the TicTacToe contract.

Takeaways

  • Leveraging superchain interop, contracts in the superchain can compose with each other in a similar fashion to how they would on a single chain. No restrictions are placed on the kinds of events a contract can consume via the CrossL2Inbox.
  • In this example, the BlockHashContestFactory and TicTacToeContestFactory can be seen as just starting points for the Contests app chain. As more contracts and apps are created in the superchain, developers can compose with them in a similar fashion without needing to change the Contests contract at all.