alloy-rs / alloy

Transports, Middleware, and Networks for the Alloy project
https://alloy.rs
Apache License 2.0
473 stars 158 forks source link

[Feature] Add tree hash root for BidTrace #1024

Open ferranbt opened 2 weeks ago

ferranbt commented 2 weeks ago

Component

rpc

Describe the feature you would like

Generate the tree hash root for the BidTrace. In order to send the Bid to the relayer, the builder has to sign the hash tree root of the BidTrace.

Additional context

No response

ferranbt commented 2 weeks ago

I think it could be as simple as:

#[cfg_attr(feature = "ssz_hash", derive(tree_hash_derive::TreeHash))]
pub struct BidTrace {

and

# ssz_hash
tree_hash = { version = "0.6", optional = true }
tree_hash_derive = { version = "0.6", optional = true }

[features]
...
ssz_hash = [
    "dep:tree_hash",
    "dep:tree_hash_derive"
]

But, we need to add the TreeHash trait impl for Address and Uint<> type in core too? Should I open a PR with the changes there first?

mattsse commented 2 weeks ago

makes sense, although, this crate currently only supports the ethereum_primitives: https://github.com/sigp/tree_hash https://github.com/sigp/tree_hash/blob/93d0e3ff58fb174f84dea8d2b5374787b7a4c85a/tree_hash/src/impls.rs#L2

the impls don't look to complex and I think we could easily feature gate them in alloy-primitives, like ssz

but it's not ideal because the treehash API uses ethereum-types h256 ...

fyi @DaniPopes

DaniPopes commented 2 weeks ago

If this gets released we don't need to add derives in alloy core https://github.com/sigp/tree_hash/pull/16

mattsse commented 2 weeks ago

oh nice!

michaelsproul commented 2 weeks ago

we (upstream tree_hash) will hopefully make progress on the alloy migration in the coming weeks