Skip to content

Murisi/dot product#100

Merged
murisi merged 6 commits intomainfrom
murisi/dot-product
Jul 23, 2025
Merged

Murisi/dot product#100
murisi merged 6 commits intomainfrom
murisi/dot-product

Conversation

@murisi
Copy link
Contributor

@murisi murisi commented Jul 15, 2025

The Namada MASP client needs a way to select transaction input notes in such a way that the number of notes used is minimized (in order to reduce the number of spend descriptions and hence overall size of MASP transactions and gas consumption). To facilitate the writing of such an algorithm, this PR implements more operations for ValueSum, specifically:

  • infimum in order to be able to compute how much of a ValueSum is covered by another
  • supremum since it's the dual to the infimum, and is useful for discarding negative ValueSum components
  • dot product in order to be able to compute norms and facilitate comparisons
  • checked negation in order to allow this operation to be carried out in checked!(...) contexts

Additionally, usage of the Default trait has been replaced with the Zero trait where zero was actually needed. As for ValueSum itself, an implementation of Zero has been added to it (to complement the existing Default implementation).

@murisi murisi requested a review from sug0 July 18, 2025 07:23
pub fn inf(&self, rhs: &Self) -> Self {
let mut comps = BTreeMap::new();
for (atype, rhs_amount) in rhs.components() {
// rhs_amount is positive by definition
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this guarantee comes from the fact that notes always carry positive amounts? Cause ValueSums could actually carry any type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're correct. I made a bad assumption. I think the issue is now fixed.

@murisi murisi force-pushed the murisi/dot-product branch from 56c9c01 to cecf8d1 Compare July 23, 2025 09:29
@murisi murisi merged commit a6dbeca into main Jul 23, 2025
11 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.

3 participants