RGB-WG / rgb-core

RGB Core Library: consensus validation for private & scalable client-validated smart contracts on Bitcoin & Lightning
https://spec.rgb.tech
Apache License 2.0
207 stars 52 forks source link

Increase portability for v0.10 #129

Closed dr-orlovsky closed 1 year ago

dr-orlovsky commented 1 year ago

I plan to dramatically increase portability of the new release, including support for WASM builds, by reducing number of dependencies - and getting rid of all C-libraries downstream. Specifically, I plan to:

  1. Remove any dependencies on rust-miniscript, since this consensus library must not touch anything wallet-related
  2. Remove secp256k1 dependency, since this library doesn't do anything to public or private keys outside of bulletproffs/pedenrsen commitments, which anyway are not a part of secp256k1
  3. In order to do that we would also need to abandon rust-bitcoin library (which requires secp256k1), but this is nice, since again, only a very few structures from rust-bitcoin are used in RGB core and in single-use-seals and they can be replaced with local vatiants. We do not use transactions, keys etc - just txids and output numbers, which is highly trivial and for sure shouldn't require rust-bitcoin dependency tree.
  4. We also can get rid of descriptor-wallet dependency here, since again RGB Core has nothing to do with any wallet-level stuff.
  5. I plan to revisit and remove any other possible dependencies on lightning-related and generic things, which shouldn't belong here;
  6. The most problematic part is to remove secp256k1-zkp fork which requires C lib, breaks WASM compillation and is needed for bulletproofs. But I think this is also possible and I am opening a separate issue to discuss on the best way of achieving that (UPD: https://github.com/RGB-WG/rgb-core/issues/130).

All these changes should significantly speed up compilation time - and also allow us to have a good progress toward ossification and v1.0 release: without rust-bitcoin family of dependencies we would not need to re-factor everything each new release and do a new version. RGB Core would become pure consensus library not requiring regular releases - and the release cycle of RGB standard library, RGB Node and LN-/wallet-related stuff can become fully independent (and much shorter) with that. I.e. version v0.10 of RGB Core should become the last version for at least this year (unless a major bugs are discovered); after which we can move to v1.0 of it.

cryptoquick commented 1 year ago

I think this is a good decision; since we're using BDK for wallet stuff, it's often difficult to upgrade RGB due to the mutual rust-bitcoin dependency. All three had to be updated at once.

As for bulletproofs, have you received any updates from the Blockstream folks? Is there anything @fedsten or @Gigi3D at DIBA can do to help that along from the business side?

dr-orlovsky commented 1 year ago

This also would help RGB Core to become no-std and be able to run on hardware wallets.

dr-orlovsky commented 1 year ago

My expectation that the proposal would allow to go from this list of consensus-level libraries (plus their upstream dependencies):

to this list:

25 vs 10 libraries; and in 25 libs there were 6 which are not maintained by LNP/BP + 2 C libs, including one WASM-compatible. Wit this proposal we are getting rid of all those external legacy

cryptoquick commented 1 year ago

Much better! This will also streamline review, publishing, and a security audit, in addition to the portability improvements.

cryptoquick commented 1 year ago

Also, I Just ran into a case today where I could've made use of this, since there are data structures returned from RGB like rgb_std::Disclosure that we can't really decode in WASM right now, see:

https://github.com/diba-io/bitmask-core/blob/7bbed2715c4a3d77158dbf68ae7cdef59cd54752/src/data/structs.rs#L1-L13

So we basically have to return double-encoded (unparsable) JSON, which is ugly and useless.

dr-orlovsky commented 1 year ago

where I could've made use of this

Sorry, not clear, use of what?

cryptoquick commented 1 year ago

where I could've made use of this

Sorry, not clear, use of what?

RGB structs that can compile to WASM so I can deserialize them on the frontend.

dr-orlovsky commented 1 year ago

But why some of RGB structs can't compile to wasm? Because they depend/contain bulletproof data? Or any other reason?

cryptoquick commented 1 year ago

The crates I get them from (like rgb_std) depend on stuff like Amplify; I forget if you were able to fix that, but if you did, maybe the latest version isn't being used by the 0.9 rc crates we're using.

dr-orlovsky commented 1 year ago

Amplify was fixed, but probably v0.9 are not on the latest version, yes.