-
Notifications
You must be signed in to change notification settings - Fork 990
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 nullifier uniqueness #2240
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why the unit and integration tests are failing in the CI? They seem to be timing out for some reason... Do they pass on your machine? Have you tried regenerating the MASP test fixtures maybe?
@@ -237,6 +239,19 @@ where | |||
); | |||
self.write(¤t_tx_key, record.serialize_to_vec())?; | |||
self.write(&head_tx_key, (current_tx_idx + 1).serialize_to_vec())?; | |||
for description in shielded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a bit of duplication in how we update the nullifier set in the transaction codes. But maybe getting rid of it is easier said than done and can be deferred to a later PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to improve the thing with a shared function now
Both unit and integration tests pass on my machine without the need to rebuild the proofs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Could you please just check out the serialize_to_vec
issue in the comments to see if there is anything to it? And if you get the chance (but it's not strictly necessary), could you please try seeing if moving handle_masp_tx
from tx_prelude/src/token.rs
into core/src/ledger/masp_utils.rs
is trivial or not?
@@ -237,6 +238,7 @@ where | |||
); | |||
self.write(¤t_tx_key, record.serialize_to_vec())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a bug? We call serialize_to_vec
on (Epoch, BlockHeight, TxIndex, Transfer, Transaction)
to obtain a Vec<u8>
. And then StorageWrite::write
itself calls serialize_to_vec
again on the Vec<u8>
argument it receives producing another Vec<u8>
, but this time prefixed with 4 bytes indicating the length of record.serialize_to_vec()
. We should probably change this line to self.write(¤t_tx_key, record)?;
so that we remain compatible with how we write to the same key in /tx_prelude/src/token.rs
. No?
@@ -237,6 +238,7 @@ where | |||
); | |||
self.write(¤t_tx_key, record.serialize_to_vec())?; | |||
self.write(&head_tx_key, (current_tx_idx + 1).serialize_to_vec())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same serialize_to_vec
issue as above?
tx_prelude/src/token.rs
Outdated
@@ -60,6 +61,7 @@ pub fn handle_masp_tx( | |||
); | |||
ctx.write(¤t_tx_key, record)?; | |||
ctx.write(&head_tx_key, current_tx_idx + 1)?; | |||
masp_utils::reveal_nullifiers(ctx, shielded)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deduplication will do. But note that the contexts in which masp_utils::reveal_nullifiers
is called are essentially identical. So I am wondering if there is a way to reuse handle_masp_tx
wholesale? Like can't we move this whole handle_masp_tx
function into core/src/ledger/masp_utils.rs
and call it like namada_core::ledger::masp_utils::handle_masp_tx(ctx, transfer, shielded)
here and namada_core::ledger::masp_utils::handle_masp_tx(self, shielded.transfer, shielded.masp_tx)
from shared/src/vm/host_env.rs
and shared/src/ledger/native_vp/ibc/context.rs
?
65d031a
to
39e00c5
Compare
Ok, I've moved the entire I had to keep a wrapper inside the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating again. Looks good to me!
* origin/grarco/nullifier-uniqueness: Refactors `handle_masp_tx` Reduce code duplication to reveal masp nullifiers Fixes masp vp nullifier validation Changelog #2240 Removes wrong comment Masp VP checks uniqueness of nullifiers Updates masp tx to reveal nullifiers
* origin/grarco/nullifier-uniqueness: Refactors `handle_masp_tx` Reduce code duplication to reveal masp nullifiers Fixes masp vp nullifier validation Changelog #2240 Removes wrong comment Masp VP checks uniqueness of nullifiers Updates masp tx to reveal nullifiers
Describe your changes
Addresses #1373.
Implements a nullifier set to prevent double spending in masp transactions. Updates the masp VP to check that the transactions writes the correct nullifiers and that these haven't already been revealed.
NOTE: testing this with an integration or e2e test is impossible cause we cannot force the submission of the tx if the builder fails to construct the shielded
Transaction
. We'd need to test this with a unit test (which I think would be the correct way regardless of theforce
issue) but at the moment we don't have the tools to write unit tests for the masp vp (at least to my knowledge)Indicate on which release or other PRs this topic is based on
v0.27.0
Checklist before merging to
draft