keep-starknet-strange / raito

Bitcoin ZK client written in Cairo.
https://raito.wtf
MIT License
40 stars 34 forks source link

[feat] Implement Hash trait for OutPoint #110

Closed m-kus closed 1 month ago

m-kus commented 2 months ago

We will need to calculate hashes of outpoints to update Utreexo accumulator and local cache.

Hash trait: https://github.com/starkware-libs/cairo/blob/93221753088d58f54f9a7f35a0bb338cf0bfb952/corelib/src/hash.cairo#L13

Hints:

Suggested deadline: 9 Sep

ScottyDavies commented 2 months ago

@m-kus can you please assign this issue to me?

m-kus commented 2 months ago

How is the progress @ScottyDavies ? Do you need help with this task?

ScottyDavies commented 2 months ago

It’s going fine, I would be done soon

maciejka commented 1 month ago

@ScottyDavies how is it going? Do you need any help? Please let us know when do you expect to complete this issue.

bloomingpeach commented 1 month ago

Can I work on this issue? My PR #142 is almost done.

onlydustapp[bot] commented 1 month ago

Hey @bloomingpeach! Thanks for showing interest. We've created an application for you to contribute to Raito - Bitcoin ZK Client. Go check it out on OnlyDust!

onlydustapp[bot] commented 1 month ago

Hey @od-hunter! Thanks for showing interest. We've created an application for you to contribute to Raito - Bitcoin ZK Client. Go check it out on OnlyDust!

m-kus commented 1 month ago

@bloomingpeach ideally you'd need to wait for #144 to be merged to use it for serialization

bloomingpeach commented 1 month ago

Hi, @m-kus, could you help me a little bit on this issue? what hash function should I use and should I introduce a new struct for the purpose of implement the HashState trait?

m-kus commented 1 month ago

@bloomingpeach Hash trait is agnostic to the particular hash function, it just allows to update hash state with a value of a given type. You can use Poseidon in unit tests for example.

You can find more info here: https://book.cairo-lang.org/ch11-04-hash.html#working-with-hashes

Here is an example of how Hash is implemented for a new type: https://github.com/starkware-libs/cairo/blob/004d2b4627b6a06a72f837957f0970cdd49d01d7/corelib/src/hash.cairo#L92

Note that you can also derive hash like #[derive(Hash)] as long as all members also implement it.
Maybe it will be enough to just implement Hash for @ByteArray (see how Serde is implemented for @ByteArray in types::transaction) and derive for the rest of the types.