Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Implement txid function #44

Merged
merged 28 commits into from
Aug 16, 2024
Merged

Conversation

TAdev0
Copy link
Collaborator

@TAdev0 TAdev0 commented Aug 8, 2024

Here is a first draft for the implementation of TxId function.

@maciejka i'm not sure the TxId we obtain with this function would be the same as references client implementation, because content of Inputs and Outputs doesn't seem to be the same.

Tbh i'm not entirely clear about how Inputs work.

When looking at this :
https://learnmeabitcoin.com/technical/transaction/input/

we can see that all inputs of a transaction include the TxID , but the TxID itselfs is calculated using (among other elements) the inputs data. Its a bit confusing

@TAdev0 TAdev0 requested review from m-kus and maciejka as code owners August 8, 2024 17:51
Copy link

vercel bot commented Aug 8, 2024

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 Aug 16, 2024 3:15pm

@TAdev0 TAdev0 changed the title [feat] Implement TxId function [feat] Implement txid function Aug 8, 2024
@TAdev0
Copy link
Collaborator Author

TAdev0 commented Aug 8, 2024

More context:

here is the Input section of raw transactions:

Screenshot 2024-08-08 at 19 54 00

this Input structure is "repeated for every input being included in the transaction."

but at the same time, txId is defined as

Screenshot 2024-08-08 at 20 00 20

It seems like a circular issue, where each input includes txId but txId computation requires to pass inputs as argument to sha256

Also, should i include VOUT field in the input , although its not in our TxIn struct? I suppose yes. But this means we actually use as Inputs the whole Inputs struct, removing the first field (TxId) because this is what we are calculating...

@TAdev0
Copy link
Collaborator Author

TAdev0 commented Aug 9, 2024

@maciejka just understood that txid in each input it the txid of the tx that generated this input... my bad

src/validation.cairo Outdated Show resolved Hide resolved
src/validation.cairo Outdated Show resolved Hide resolved
@maciejka
Copy link
Collaborator

maciejka commented Aug 9, 2024

More context:

here is the Input section of raw transactions:

Screenshot 2024-08-08 at 19 54 00 this `Input` structure is "repeated for every input being included in the transaction."

but at the same time, txId is defined as

Screenshot 2024-08-08 at 20 00 20 It seems like a circular issue, where each input includes txId but txId computation requires to pass inputs as argument to sha256

Also, should i include VOUT field in the input , although its not in our TxIn struct? I suppose yes. But this means we actually use as Inputs the whole Inputs struct, removing the first field (TxId) because this is what we are calculating...

These are not the same TxIds. TxInput contains TxId of a transaction it wants to spend.

src/validation.cairo Outdated Show resolved Hide resolved
src/validation.cairo Outdated Show resolved Hide resolved
src/validation.cairo Outdated Show resolved Hide resolved
@TAdev0
Copy link
Collaborator Author

TAdev0 commented Aug 11, 2024

@maciejka @m-kus ok so i udpated the PR without using double_sha256 given its inputs will change with #50 and i'm not sure using Array is ideal here. (and there is not reason to split in 2 inputs the whole bunch of data to hash)

will work on tests now. I'm not serializing everything to an array of u32 because it doesnt seem to be the best option here. I dont know actually.
Using ByteArray is nice given that we have elements with various size (input_count / output_count only 1 byte, locktime 4 bytes, scripPubKey which is of various size (43 bytes in the example on learnmeabitcoin..)
Using ByteArray seems easier... waiting for your feedback.

src/utils.cairo Outdated Show resolved Hide resolved
src/state.cairo Outdated Show resolved Hide resolved
Copy link
Contributor

@lana-shanghai lana-shanghai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@lana-shanghai lana-shanghai merged commit 82bbdbe into keep-starknet-strange:main Aug 16, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants