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: remove unnecessary range proof verify and fix test temp disk usage #3334

Merged

Conversation

stringhandler
Copy link
Collaborator

@stringhandler stringhandler commented Sep 10, 2021

Description

Remove an unnecessary rangeproof verify after we just created it

Note: Also reduced the size impact of LMDB temp databases that cargo test has when running on Windows machines.

Motivation and Context

There is no benefit in verifying a rangeproof immediately after creating it

How Has This Been Tested?

Copy link
Member

@sdbondi sdbondi left a comment

Choose a reason for hiding this comment

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

Nice - maybe @philipr-za can confirm that this is sound and then we can remove the commented out code.

"Range proof could not be verified".into(),
));
}
// // A range proof can be constructed for an invalid value so we should confirm that the proof can be verified.
Copy link
Member

Choose a reason for hiding this comment

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

// range proof can be constructed for an invalid value so we should confirm that the proof can be verified.

Assuming the invalid value talked about here is a negative value? Something that is already an invariant because Microtari is backed by a u64.

Copy link
Contributor

@philipr-za philipr-za left a comment

Choose a reason for hiding this comment

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

It does seem a bit paranoid to check the proof right after its been constructed with the same data. It came from the fact that you build the proof using the unblinded data and verify it with the commitment and the factory that produces the commitment here could be different to the commitment factory used within the tari_crypto crate during proof construction.

philipr-za
philipr-za previously approved these changes Sep 13, 2021
Copy link
Contributor

@philipr-za philipr-za left a comment

Choose a reason for hiding this comment

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

Approved, though I agree if the code is coming out then don't leave the comments in.

hansieodendaal
hansieodendaal previously approved these changes Sep 15, 2021
Copy link
Contributor

@hansieodendaal hansieodendaal left a comment

Choose a reason for hiding this comment

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

I agree with this change as the entire transaction including the range proof will be verified multiple times before being submitted to the mempool.

@stringhandler
Copy link
Collaborator Author

Fixed tests by adding a simple check instead of running the full rangeproof validation. @philipr-za @hansieodendaal please have a look again

@@ -281,6 +282,12 @@ impl UnblindedOutput {
}

pub fn as_transaction_output(&self, factories: &CryptoFactories) -> Result<TransactionOutput, TransactionError> {
if factories.range_proof.range() < 64 && self.value > MicroTari::from(1u64.shl(&factories.range_proof.range()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is correct as opposed to shl(....range() - 1)

Copy link
Member

Choose a reason for hiding this comment

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

factories.range_proof.range() < 64 will never be true in our case since we set the range to 64.
1u64 << 64 will overflow so should be range() - 1.

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's actually true for 90% of the tests, that's why it's there. My reasoning is that if it is 64, then a u64 automatically fits in.

The reason that this is here is because there are some tests that use a smaller range of 32. I'll have to check and see if range() - 1 is correct in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

so just trying 1u64.shl(64) panics with thread 'main' panicked at 'attempt to shift left with overflow'.

1u64(63) will give you half the 64-bit range.

If you are looking for the max value of an arbitrary bit depth you will need to shift up that many ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is correct now that I've added the = to the >=. The case where the range is 64 is covered simply by the fact that you cannot include a higher value inside a u64.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the short circuit protects us from the overflow

@stringhandler stringhandler changed the title fix: remove unnecessary range proof verify fix: remove unnecessary range proof verify and fix test temp disk usage Sep 16, 2021
@aviator-app aviator-app bot merged commit eeb62a6 into tari-project:development Sep 17, 2021
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