Skip to main content
OP Stack Hacks are explicitly things that you can do with the OP Stack that are not currently intended for production use.OP Stack Hacks are not for the faint of heart. You will not be able to receive significant developer support for OP Stack Hacks — be prepared to get your hands dirty and to work without support.

Overview

In this tutorial, you’ll modify the Bedrock Rollup. Although there are many ways to modify the OP Stack, you’re going to spend this tutorial modifying the Derivation function. Specifically, you’re going to update the Derivation function to track the amount of ETH being burned on L1! Who’s gonna tell ultrasound.money that they should replace their backend with an OP Stack chain?

Getting the idea

Let’s quickly recap what you’re about to do. The op-node is responsible for generating the Engine API payloads that trigger op-geth to produce blocks and transactions. The op-node already generates a “system transaction” for every L1 block that relays information about the current L1 state to the L2 chain. You’re going to modify the op-node to add a new system transaction that reports the total burn amount (the base fee multiplied by the gas used) in each block. Although it might sound like a lot, the whole process only involves deploying a single smart contract, adding one new file to op-node, and modifying one existing file inside op-node. It’ll be painless. Let’s go!

Deploy the burn contract

You’re going to use a smart contract on your Rollup to store the reports that the op-node makes about the L1 burn. Here’s the code for your smart contract:
Deploy this smart contract to your L2 (using any tool you find convenient). Make a note of the address that the contract is deployed to because you’ll need it in a minute. Simple!

Add the burn transaction

Now you need to add logic to the op-node to automatically submit a burn report whenever an L1 block is produced. Since this transaction is very similar to the system transaction that reports other L1 block info (found in l1_block_info.go), you’ll use that transaction as a jumping-off point.
1

Navigate to the `op-node` package:

2

Inside of the folder `rollup/derive`, create a new file called `l1_burn_info.go`:

3

Paste the following into `l1_burn_info.go`, and make sure to replace `YOUR_BURN_CONTRACT_HERE` with the address of the `L1Burn` contract you just deployed.

Feel free to take a look at this file if you’re interested. It’s relatively simple, mainly just defining a new transaction type and describing how the transaction should be encoded.

Insert the burn transactions

Finally, you’ll need to update ~/optimism/op-node/rollup/derive/attributes.go to insert the new burn transaction into every block. You’ll need to make the following changes:
1

Find these lines:

2

After those lines, add this code fragment:

3

Immediately following, change these lines:

to
All you’re doing here is creating a new burn transaction after every l1InfoTx and inserting it into every block.

Rebuild your op-node

Before you can see this change take effect, you’ll need to rebuild your op-node:
Now start your op-node if it isn’t running or restart your op-node if it’s already running. You should see the change immediately — new blocks will contain two system transactions instead of just one!

Checking the result

Query the total function of your contract, you should also start to see the total slowly increasing. Play around with the tally function to grab the amount of gas burned since a given L2 block. You could use this to implement a version of ultrasound.money that keeps track of things with an OP Stack as a backend. One way to get the total is to run these commands:

Conclusion

With just a few tiny changes to the op-node, you were just able to implement a change to the OP Stack that allows you to keep track of the L1 ETH burn on L2. With a live Cannon Fault Proof System, you should not only be able to track the L1 burn on L2, you should be able to prove the burn to contracts back on L1. That’s crazy! The OP Stack is an extremely powerful platform that allows you to perform a large amount of computation trustlessly. It’s a superpower for smart contracts. Tracking the L1 burn is just one of the many, many wild things you can do with the OP Stack. If you’re looking for inspiration or you want to see what others are building on the OP Stack, check out the OP Stack Hacks page. Maybe you’ll find a project you want to work on, or maybe you’ll get the inspiration you need to build the next killer smart contract.