keep-starknet-strange / raito

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

[feat] Calculate transaction weight #107 #127

Closed Jeanmichel7 closed 1 month ago

Jeanmichel7 commented 2 months ago
vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
raito ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 5, 2024 2:04pm
Jeanmichel7 commented 1 month ago

I forgot the header weight in the block size validation ...

m-kus commented 1 month ago

I'd suggest to implement block weight validation in a follow up PR

m-kus commented 1 month ago

@maciejka so what you suggested makes sense in terms of optimisation:

txid = hash(encoded)
wtxid = hash(encoded_with_witness)
weight = 4 * len(encoded) + (len(encoded_with_witness) - len(encoded))

So one option is to do this in fee_and_merkle_roots function instead of TransactionTrait that exposes txid, wtxid, and weight methods.

Another option is to implement byte_size as part of the Encode trait to have a lightweight size estimation, but it would still be an overhead.

Generally we are already doing double work when encoding two times w/ and w/o witnesses. Maybe it makes sense to leave optimizations for the future, idk.

Jeanmichel7 commented 1 month ago

Since we're computing directly in the function, I don't really see how to do the tests. So I've mocked the logic for my tests, but perhaps it would be better to move the tests to encode?

m-kus commented 1 month ago

@Jeanmichel7 this is getting out of control 😅 I'll make a draft PR with interfaces to illustrate what is needed

See #146

maciejka commented 1 month ago

@Jeanmichel7 this is getting out of control 😅 I'll make a draft PR with interfaces to illustrate what is needed

See #146

@Jeanmichel7 let's continue in #146