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

Addresses the boundary conditions for the Masp VP predicate #1104

Merged
merged 2 commits into from
Apr 13, 2023

Conversation

mariari
Copy link
Member

@mariari mariari commented Jan 31, 2023

This PR implements the boundary conditions found in #56.

The following checks are not included

  1. If the target address is not the masp, then the public key must be
    checked

  2. If the source address is not the masp, then the asset type must be
    derived

  3. If the source address is not the masp, then the value must be
    derived

The first one is not satisifed as TxOut lacks a public key to check
against, not only in code but also in the spec

https://github.com/anoma/namada/blob/83e83315a5eaec302d08ed5db242d70625cfe45f/documentation/specs/src/masp/ledger-integration.md#transparent-output-format

The second and third are not satisfied as TxIn in code lacks the
values in the spec that can be used to satisfy them

https://github.com/anoma/namada/blob/83e83315a5eaec302d08ed5db242d70625cfe45f/documentation/specs/src/masp/ledger-integration.md#transparent-input-format

I suggest a followup pr once those values are in.

This commit adds most of the proper boundary checks from
https://github.com/anoma/namada/blob/main/documentation/specs/src/masp/ledger-integration.md#boundary-conditions

The ones not included are the following:

1. If the target address is not the masp, then the public key must be
checked

2. If the source address is not the masp, then the asset type must be
derived

3. If the source address is not the masp, then the value must be
derived

The first one is not satisifed as TxOut lacks a public key to check
against, not only in code but also in the spec

https://github.com/anoma/namada/blob/83e83315a5eaec302d08ed5db242d70625cfe45f/documentation/specs/src/masp/ledger-integration.md#transparent-output-format

The second and third are not satisfied as TxIn in code lacks the
values in the spec that can be used to satisfy them

https://github.com/anoma/namada/blob/83e83315a5eaec302d08ed5db242d70625cfe45f/documentation/specs/src/masp/ledger-integration.md#transparent-input-format
@mariari
Copy link
Member Author

mariari commented Feb 1, 2023

pls update wasm

@cwgoes cwgoes requested a review from murisi February 6, 2023 08:14
@cwgoes
Copy link
Collaborator

cwgoes commented Feb 6, 2023

This looks alright to me, but @murisi knows the code better - can you take a look?

This commit implements checking the public key from the output
transaction against the ripemd160 of the sha256 of the target address.

Furhter this commit fixes the clippy warnings that appeared in the
last commit
@mariari mariari force-pushed the mariari/masp-boundary-conditionals branch from dce6f9b to 7c5d387 Compare February 7, 2023 07:35
Copy link
Collaborator

@murisi murisi left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. It seems that 3 checks are missing (for MASP target, for MASP source, and for transaction fees). And perhaps maybe some checks could be slightly weakened without affecting the validity of this VP?

if transfer.source != masp() {
// Satisfies 1.
if shielded_tx.vin.len() != 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that we no longer intend to check the amount and asset type of the transparent input, this condition is no longer necessary. The value balance checks will ensure that the user has indeed provided sufficient inputs.

}

// Satisfies 2.
if !shielded_tx.vout.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check enforces that transactions with a non-MASP source must have no transparent outputs. While this check can be done, the transaction would still be valid (i.e. leaving the shielded pool and transparent pool in a consistent state) without it. Perhaps we can remove this check to simplify the logic?

if transfer.target != masp() {
// Satisfies 1.
if !shielded_tx.vin.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check enforces that transactions with non-MASP targets mut not have any transparent inputs. While this check can be done, the transaction would still be valid (i.e. leaving the shielded pool and transparent pool in a consistent state) without it. Perhaps we can remove this check to simplify the logic?

// Timestamp is derived to allow unshields for older tokens
let atype =
let atype: &AssetType =
Copy link
Collaborator

Choose a reason for hiding this comment

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

This use of .components().next().unwrap() seems to be unsafe. What guarantees that shielded_tx.value_balance has at least one component? And when there are multiple components, what does the first extracted component mean semantically?

// 1. One transparent input
// 2. Zero transparent output
// 3. the transparent transaction value pool's amount must equal the
// containing wrapper transaction's fee amount
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do we check that condition (3) is met? It seems to me that there should be some mention of the wrapper transaction's fee somewhere in this code?

// 1. One transparent input
// 2. Zero transparent output
// 3. the transparent transaction value pool's amount must equal the
// containing wrapper transaction's fee amount
if transfer.source != masp() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do we check for the for the following condition?: If the source address is the MASP validity predicate, then no transparent inputs are permitted in the shielded transaction.

It seems to me that if the source and target are MASP, then both the conditional on line 105 and line 146 are skipped. This would allow for these sorts of transactions to have unlimited transparent inputs and outputs.

// 2. One transparent output
// 3. Asset type must be properly derived
// 4. Value from the output must be the same as the containing transfer
// 5. Public key must be the hash of the target
if transfer.target != masp() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do we check for the following condition?: If the target address is the MASP validity predicate, then no transparent outputs are permitted in the shielded transaction.

It seems to me that if the source and target are MASP, then both the conditional on line 105 and line 146 are skipped. This would allow for these sorts of transactions to have unlimited transparent inputs and outputs.

@murisi
Copy link
Collaborator

murisi commented Feb 7, 2023

@cwgoes You mentioned that you found the specs at https://github.com/anoma/namada/blob/main/documentation/specs/src/masp/ledger-integration.md confusing and had (or were going to) rewritten some parts. Have you made any edits to the Boundary Conditions section? Any improvements there could help improve the clarity of this code...

@juped juped merged commit 7c5d387 into main Apr 13, 2023
@juped juped deleted the mariari/masp-boundary-conditionals branch April 13, 2023 06:07
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.

4 participants