0xSpaceShard / starknet-devnet

A local testnet for Starknet
https://0xspaceshard.github.io/starknet-devnet/
MIT License
211 stars 77 forks source link

L1->L2 & L2->L1 messages #10

Closed RoboTeddy closed 2 years ago

RoboTeddy commented 2 years ago

Has any thought been given to how these should be supported yet?

FabijanC commented 2 years ago

In fact just yesterday I was "giving thought" to this issue while going through this: https://www.cairo-lang.org/docs/hello_starknet/l1l2.html.

To be clear, the Alpha testnet, which this devnet aims to mimic, is able to communicate with an Ethereum testnet (currently Goerli). And currently, the devnet is isolated from L1 chains.

Do you have an idea on how this could be addressed? Or have you found the relevant starknet code parts concerning the L1-L2 connection?

RoboTeddy commented 2 years ago

Do you have an idea on how this could be addressed?

One possibility could be to try to set up a local Ethereum devnet (e.g. ganache) such that L1->L2 and L2->L1 messages can be passed between them. That way, there'd be a totally local devnet which replicates what can be done on the Goerli testnet.

I'm not sure how much integration work/complexity/maintenance would be required.

RoboTeddy commented 2 years ago

Barring total integration, we could add an endpoint to starknet-devnet that calls starknet.send_message_to_l2 (as in this example: https://github.com/makerdao/starknet-dai-bridge/blob/mk/draft/test/l2/l2_dai_bridge.py#L288)

I suppose a broader question is: should starknet-devnet be solely about replicating the testnet deployment locally, or should it also be about exposing Starkware's testing framework more broadly? If the former, then including send_message_to_l2 like this might not make sense. If the latter, then it could be a good addition.

FabijanC commented 2 years ago

One possibility could be to try to set up a local Ethereum devnet (e.g. ganache) such that L1->L2 and L2->L1 messages can be passed between them. That way, there'd be a totally local devnet which replicates what can be done on the Goerli testnet.

Yes, that also occurred to me. But it could be more generic: just providing the RPC endpoint of the testnet you wish your devnet instance to be connected with, be it something local like Ganache, or something nonlocal like Goerli. Something like passing --l1_endpoint https://goerli... on devnet startup.

I'd say this is a good enhancement idea and I'd keep this issue open until a proper PR is merged.

FabijanC commented 2 years ago

This has been addressed with v0.1.15. There are now dedicated endpoints for specifying the L1 address and flushing the L1->L2 and L2->L1 communication channels. Handlers for these endpoints are being added to starknet-hardhat-plugin.