ethereum-optimism / ecosystem-contributions

Find ways to contribute to the Optimism Collective
MIT License
294 stars 114 forks source link

🧪 Mad Science Project Idea: Trigger L2 contracts with L1 events #46

Open smartcontracts opened 1 year ago

smartcontracts commented 1 year ago

What is an Mad Science Project Idea?

A Mad Science Project Idea is an idea for a project within the Optimism ecosystem that may not have clear value but is generally cool as heck. Mad Science Project Ideas make great hackathon projects and tend to be a great way to explore Optimism, OP Mainnet, and the OP Stack.


Summary

The OP Stack makes it possible to trigger actions on L2 based on things that happen on L1. One powerful mechanism that an OP Stack chain could introduce is the ability to register "hooks" that are automatically triggered when certain events are emitted on the L1 chain. Doing so would require modifying the derivation layer of the OP Stack in a manner similar to the example modification found within the OP Stack documentation.

An ideal hook system would allow any address to register a hook via a smart contract on L2 by providing the L1 address, an event filter, and a function to be triggered whenever the event is emitted. You may have to come up with a fee mechanism that accounts for the cost of checking for events each time a new block is introduced. It may also be necessary to supply a maximum number of hooks that can be registered at any point.

Possible Features

Resources

protocolwhisper commented 1 year ago

Is this like some oracle that will listen to events in the L1 and then execute the sc in optimism? If that's what's "modification of the derivation layer"?

smartcontracts commented 1 year ago

@protocolwhisper yes, sort of. You can modify the derivation layer of the OP Stack so that it automatically generates new L2 transactions when certain things happen on L1. This is already what happens for L1 => L2 transactions, so the same logic could be extended to any L1 event. You can see an example of this in the OP Stack docs: https://stack.optimism.io/docs/build/tutorials/add-attr/

AlexBHarley commented 1 year ago

This seems like such an incredibly cool and powerful concept for rollup deployers, I had a stab at an implementation of this here. The readme has all the relevant information + a quickstart so people can try it out locally with the devnet.

For the proof of concept, hook registration is permissioned (stealing some nomenclature from the Cosmos ecosystem, meaning only rollup deployers can add them). But this could totally be expanded to be semi-permissioned or even permissionless if DOS considerations are thought through.

I would love feedback on the general approach because I haven't done EVM stuff for a while, let alone Op Stack stuff.

Somewhat off topic, but it came to me while building the event hook functionality. A BeforeBlock type hook would be awesome as it'd mean rollup deployers can "easily" take advantage of their privileged position and do "good" MEV. Maybe distributing profits to stakers/holders of the native asset or bolstering a community pool.