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

Masp client invalidates spent notes #2534

Merged
merged 15 commits into from
Feb 22, 2024

Conversation

grarco
Copy link
Collaborator

@grarco grarco commented Feb 6, 2024

Describe your changes

Modifies the client to invalidate the spend notes after their usage, to allow the construction of consecutive valid masp transactions (mandatory requirement for fee unshielding and masp tx with the same source key).

The ShieldedContext can now be in two states: Confirmed or Speculative. A Confirmed state is one coming from a sync operation, meaning that the data in the context comes from transaction that have been accepted by the protocol. When calling gen_shielded_transfer, instead, the context invalidates any spend notes used and transitions to a Speculative state (i.e. not that is not guaranteed to che coherent with the protocol). The speculative state is stored in a separate file and is always reload instead of the confirmed one when present. When calling fetch the Confirmed state is reloaded from disk to discard any possible speculative state and the fetch operates on this. Finally, when saving the newly synced confirmed state to storage, the file of the speculative state is removed if found.

Improved previous integration tests to be more strict and added new ones.

Indicate on which release or other PRs this topic is based on

#2458 rebased on v0.31.3

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

grarco added a commit that referenced this pull request Feb 6, 2024
@grarco grarco force-pushed the grarco/invalidate-masp-notes-in-client branch from 8d97f3d to 8d8893b Compare February 6, 2024 18:53
@grarco grarco marked this pull request as ready for review February 6, 2024 18:53
@grarco grarco requested review from murisi and batconjurer February 6, 2024 18:53
@@ -113,6 +113,26 @@ pub const OUTPUT_NAME: &str = "masp-output.params";
/// Convert circuit name
pub const CONVERT_NAME: &str = "masp-convert.params";

/// Type alias for convenience and profit
Copy link
Member

Choose a reason for hiding this comment

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

😆

@grarco grarco mentioned this pull request Feb 9, 2024
2 tasks
grarco added a commit that referenced this pull request Feb 9, 2024
@grarco grarco force-pushed the grarco/invalidate-masp-notes-in-client branch from 8d8893b to 44b4dd8 Compare February 9, 2024 23:56
@grarco grarco mentioned this pull request Feb 12, 2024
2 tasks
Comment on lines 2495 to 2523
if updated_balance.source == source && updated_balance.token == args.token {
if validated_amount.amount() > updated_balance.post_balance {
if args.tx.force {
edisplay_line!(
context.io(),
"The balance of the source {} of token {} is lower than \
the amount to be transferred. Amount to transfer is {} \
and the balance is {}.",
source,
args.token,
context
.format_amount(&args.token, validated_amount.amount())
.await,
context
.format_amount(
&args.token,
updated_balance.post_balance
)
.await,
);
} else {
return Err(Error::from(TxSubmitError::BalanceTooLow(
source.clone(),
args.token.clone(),
validated_amount.amount().to_string_native(),
updated_balance.post_balance.to_string_native(),
)));
}
}
Copy link
Member

Choose a reason for hiding this comment

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

this code block is repeated a few times. Can we factor it out into a separate func?

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've moved this logic inside check_balance_too_low_err

grarco added a commit that referenced this pull request Feb 13, 2024
@grarco grarco force-pushed the grarco/invalidate-masp-notes-in-client branch from 44b4dd8 to 2a437de Compare February 13, 2024 13:35
@grarco grarco force-pushed the grarco/invalidate-masp-notes-in-client branch from 2a437de to 8f5e41b Compare February 13, 2024 15:41
@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2024

Codecov Report

Attention: 856 lines in your changes are missing coverage. Please review.

Comparison is base (9181fbe) 53.38% compared to head (8f5e41b) 53.11%.
Report is 8 commits behind head on main.

Files Patch % Lines
crates/sdk/src/masp.rs 0.00% 300 Missing ⚠️
crates/sdk/src/tx.rs 0.00% 236 Missing ⚠️
crates/apps/src/lib/client/masp.rs 0.00% 97 Missing ⚠️
crates/apps/src/lib/cli.rs 0.00% 69 Missing ⚠️
crates/sdk/src/signing.rs 0.00% 40 Missing ⚠️
crates/apps/src/lib/cli/client.rs 0.00% 32 Missing ⚠️
crates/apps/src/lib/bench_utils.rs 0.00% 28 Missing ⚠️
...tes/apps/src/lib/node/ledger/shell/testing/node.rs 0.00% 19 Missing ⚠️
crates/apps/src/lib/client/tx.rs 0.00% 18 Missing ⚠️
crates/sdk/src/eth_bridge/bridge_pool.rs 0.00% 9 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2534      +/-   ##
==========================================
- Coverage   53.38%   53.11%   -0.28%     
==========================================
  Files         302      303       +1     
  Lines      103398   103937     +539     
==========================================
+ Hits        55203    55207       +4     
- Misses      48195    48730     +535     

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

@grarco grarco requested a review from batconjurer February 13, 2024 16:23
This was referenced Feb 13, 2024
Fraccaman pushed a commit that referenced this pull request Feb 19, 2024
* origin/grarco/invalidate-masp-notes-in-client:
  Refactors `check_balance_too_low_err` to accept either a balance key or a balance
  Changelog #2534
  Refactors the `ShieldedUtils` trait
  Fixes e2e test
  Updates masp proofs
  Invalidate spent keys when generating masp transactions
  Returns error if the provided gas-spending-key is not needed
  Improves tests of fee unshielding
  [chore]: Fix integration masp test fixtures
  I don't know
  [chore] Rebase on main
  [fix] Some e2e test fixes
  Moved fetch calls completely from other calls. Updated cli. Fixed tests
  Added changelog entry.
  Changed the note scanning algorithm to not require additional context.
Fraccaman pushed a commit that referenced this pull request Feb 19, 2024
* origin/grarco/invalidate-masp-notes-in-client:
  Refactors `check_balance_too_low_err` to accept either a balance key or a balance
  Changelog #2534
  Refactors the `ShieldedUtils` trait
  Fixes e2e test
  Updates masp proofs
  Invalidate spent keys when generating masp transactions
  Returns error if the provided gas-spending-key is not needed
  Improves tests of fee unshielding
  [chore]: Fix integration masp test fixtures
  I don't know
  [chore] Rebase on main
  [fix] Some e2e test fixes
  Moved fetch calls completely from other calls. Updated cli. Fixed tests
  Added changelog entry.
  Changed the note scanning algorithm to not require additional context.
Fraccaman pushed a commit that referenced this pull request Feb 20, 2024
* origin/grarco/invalidate-masp-notes-in-client:
  Refactors `check_balance_too_low_err` to accept either a balance key or a balance
  Changelog #2534
  Refactors the `ShieldedUtils` trait
  Fixes e2e test
  Updates masp proofs
  Invalidate spent keys when generating masp transactions
  Returns error if the provided gas-spending-key is not needed
  Improves tests of fee unshielding
  [chore]: Fix integration masp test fixtures
  I don't know
  [chore] Rebase on main
  [fix] Some e2e test fixes
  Moved fetch calls completely from other calls. Updated cli. Fixed tests
  Added changelog entry.
  Changed the note scanning algorithm to not require additional context.
Fraccaman pushed a commit that referenced this pull request Feb 20, 2024
Fraccaman pushed a commit that referenced this pull request Feb 20, 2024
@grarco grarco mentioned this pull request Feb 21, 2024
2 tasks
@tzemanovic tzemanovic merged commit cd087fe into main Feb 22, 2024
14 of 17 checks passed
@tzemanovic tzemanovic deleted the grarco/invalidate-masp-notes-in-client branch February 22, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants