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

Avoid possible truncation of higher bits #619

Merged
merged 5 commits into from
Oct 31, 2023

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Oct 30, 2023

Closes #570

@xgreenx xgreenx requested a review from a team October 30, 2023 02:11
@xgreenx xgreenx self-assigned this Oct 30, 2023
(*Hasher::default().chain(txid).chain([idx as u8]).finalize()).into()
(*Hasher::default()
.chain(txid)
.chain(idx.to_bytes())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we are okay with supporting more than 255 receipts, then we also need to update the specification

Copy link
Member

Choose a reason for hiding this comment

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

I think this was settled yesterday and we do want to support U16::MAX receipts. Would a PR changing the linked paragraph be enough? I recall there was some discussion about serialization as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to update the paragraph and mention that we need to use canonical serialization for integers.

We have a separate issue to add a u16::max limit #620


#[test]
fn test_msb_for_bytes_1() {
const NUM_BITS: usize = size_of::<Bytes1>() * 8;
Copy link
Member

Choose a reason for hiding this comment

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

I like the size_of approach as it's more obvious to the code reader how this value is constructed. Maybe we should split this into two constants like NUM_BYTES vs NUM_BITS?

@xgreenx xgreenx requested a review from a team October 31, 2023 10:38
@xgreenx xgreenx added this pull request to the merge queue Oct 31, 2023
Merged via the queue into master with commit c008624 Oct 31, 2023
37 checks passed
@xgreenx xgreenx deleted the feature/avoid-cast-where-possible branch October 31, 2023 16:02
@@ -5,11 +5,11 @@ pub enum Bit {
}

trait GetBit {
fn get_bit(&self, bit_index: usize) -> Option<Bit>;
fn get_bit(&self, bit_index: u32) -> Option<Bit>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these changes to fuel-merkle necessary? It feels like we're changing library logic to fit business logic. A library should promise correctness under all targets it supports, including all 32 bit and 64 bit targets. If it has internal problems with truncation, that should be fixed in the library. But this change appears to be changing the library interface to accommodate changes to external libraries.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a private trait, so it is an internal detail of how Merkle tree works=)

@xgreenx xgreenx mentioned this pull request Oct 31, 2023
xgreenx added a commit to FuelLabs/fuel-core that referenced this pull request Oct 31, 2023
Closes #1261

Awaits reelasing of the FuelLabs/fuel-vm#619.

---------

Co-authored-by: Hannes Karppila <hannes.karppila@gmail.com>
crypto523 added a commit to crypto523/fuel-core that referenced this pull request Oct 7, 2024
Closes FuelLabs/fuel-core#1261

Awaits reelasing of the FuelLabs/fuel-vm#619.

---------

Co-authored-by: Hannes Karppila <hannes.karppila@gmail.com>
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.

TOB-FUEL-36: Consensus between 32bit and 64bit systems can fail
4 participants