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

Fix: Use VRFProof::consensus_serialize() #4121

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

jbencin
Copy link
Contributor

@jbencin jbencin commented Dec 4, 2023

Description

Use VRFProof::consensus_serialize() to serialize it rather than .to_bytes.to_vec()

Applicable issues

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

LGTM. Just make sure that the codec tests for the Nakamoto-flavored coinbase continue to work.

@kantai
Copy link
Member

kantai commented Dec 5, 2023

Can you add a test with an explicit test vector?
e.g.

let test_vector = "013fab..";
assert_eq!(&to_hex(&payload.serialize_to_vec(), test_vector);

@jbencin jbencin changed the title Fix: Use VRFProof::consensus_deserialize() Fix: Use VRFProof::consensus_serialize() Dec 5, 2023
@ASuciuX
Copy link
Contributor

ASuciuX commented Dec 5, 2023

I ran the tests related to the NakamotoCoinbase tx and they are failing:

From the output, I see the created tx doesn't have this bytes sequence 0, 0, 0, 80 in both tests, while the predefined tx has them.
1.

8, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 9, 
`0, 0, 0, 80`,
146, 117, 223, 103, 166, 140, 135, 69, 192, 255, 151, 180, 130, 1, 238, 109, 180, 71, 247, 201, 59, 35, 174, 36, 205, 194, 64, 15, 82, 253, 176, 138, 26, 106, 199, 236, 113, 191, 156, 156, 118, 233, 110, 228, 103, 94, 191, 246, 6, 37, 175, 40, 113, 133, 1, 4, 123, 253, 135, 184, 16, 194, 210, 19, 155, 115, 194, 59, 214, 157, 230, 99, 96, 149, 58, 100, 44, 42, 51, 10
8, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 10, 6, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 12, 102, 111, 111, 45, 99, 111, 110, 116, 114, 97, 99, 116, 
`0, 0, 0, 80`, 
146, 117, 223, 103, 166, 140, 135, 69, 192, 255, 151, 180, 130, 1, 238, 109, 180, 71, 247, 201, 59, 35, 174, 36, 205, 194, 64, 15, 82, 253, 176, 138, 26, 106, 199, 236, 113, 191, 156, 156, 118, 233, 110, 228, 103, 94, 191, 246, 6, 37, 175, 40, 113, 133, 1, 4, 123, 253, 135, 184, 16, 194, 210, 19, 155, 115, 194, 59, 214, 157, 230, 99, 96, 149, 58, 100, 44, 42, 51, 10

@jbencin
Copy link
Contributor Author

jbencin commented Dec 5, 2023

Can you add a test with an explicit test vector?

There's already 3 tests that serialize/deserialize this struct:

chainstate::stacks::transaction::test::tx_stacks_transaction_codec
chainstate::stacks::transaction::test::tx_stacks_transaction_payload_nakamoto_coinbase 
chainstate::stacks::transaction::test::tx_stacks_transaction_payload_nakamoto_coinbase_alt_recipient

From the output, I see the created tx doesn't have this bytes sequence 0, 0, 0, 80

This number is the length prefix for a vector, and since VRFproof is fixed length (80 bytes), it isn't necessary. I have removed it from the unit tests and from TransactionPayload::consensus_deserialize() now so all tests pass

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9ca75e1) 72.02% compared to head (396b34b) 72.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #4121      +/-   ##
==========================================
- Coverage   72.02%   72.01%   -0.01%     
==========================================
  Files         421      421              
  Lines      298095   298095              
==========================================
- Hits       214700   214683      -17     
- Misses      83395    83412      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jbencin jbencin merged commit 2c1c777 into stacks-network:next Dec 7, 2023
2 checks passed
@jbencin jbencin deleted the fix/issue-4115 branch December 7, 2023 14:18
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.

None yet

4 participants