bob-collective / bob

BOB is a hybrid L2 that combines the security of Bitcoin with the versatility of Ethereum.
https://app.gobob.xyz/
85 stars 42 forks source link

Hardhat/anvil for Bitcoin local development #54

Open nud3l opened 1 year ago

nud3l commented 1 year ago

Is your feature request related to a problem? Please describe. Local development/regtest is difficult and often impractical, especially when a local Bitcoin node is required. It requires good knowledge of Bitcoin core (which is good to have) but:

  1. There's an overwhelming number of options to start a Bitcoin node
  2. It's not possible to fork Bitcoin mainnet or testnet into a local devnet for testing
  3. Interacting with regtest is not very ergonomical via bitcoin-cli

Describe the solution you'd like We need an easy-to-use tool similar to bitcoind -regtest with additional functionality. It does not need to provide consensus compatibility, but should make it easier to replicate Bitcoin "quirks" for testing. For example with regtest we cannot emulate chain forks to test light client (SPV) logic, it is also cumbersome to auto-mine blocks and bitcoind does not allow us to "fork" from some pre-existing state. The tool should be similar to anvil from the Foundry suite and should provide Bitcoin RPC compatibility so we can re-use existing tools such as Electrs.

Describe alternatives you've considered We have been using regtest for quite some time, right now nothing exists which satisfies these requirements.

Additional context We should use rust-bitcoin and existing Bitcoin libraries as much as possible. We may need to provide additional tooling to support forking since we need to load state over HTTP(S), it may be possible with Electrs but requires further experimentation.

gregdhill commented 1 year ago

Here are some of the advantages of working with Anvil on Ethereum, I've extracted those which could also make sense for Bitcoin.

The toolkit is quite configurable and has several options for startup:

It also provides a compatible ETH RPC interface and some additional methods:

The docs here list many more configurations and methods.

gregdhill commented 1 year ago

The Bitcoin Dev Kit (BDK) provides a variety of tooling, for instance we can integrate the wallet functionality - signing and coin selection.

nud3l commented 1 year ago

Instead of writing our own tool from scratch we want to:

  1. Use https://github.com/vulpemventures/nigiri/ for bitcoin regtest setup
  2. Fork electrs to add ordinals and brc20 functions, see #55
  3. Add our electrs fork to nigiri
  4. Create a hackathon/simple starter template that consists of nigiri and foundry as toolchains and includes an automatic deployment of BOB smart contracts to be used in local test environments
nud3l commented 1 year ago

@gregdhill do you think we should close this issue and create a new one?

gregdhill commented 1 year ago

I would be inclined to leave this open for now and get feedback from teams working directly with regtest so we can get a better idea of the pain points to determine if a more grandiose tool is required. We can open a separate issue to track the setup tooling you described above.