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

chore: add audit comments #163

Closed
wants to merge 1 commit into from
Closed

Conversation

enricobottazzi
Copy link
Member

No description provided.

@enricobottazzi enricobottazzi requested a review from sifnoc October 2, 2023 08:09
@enricobottazzi enricobottazzi linked an issue Oct 30, 2023 that may be closed by this pull request
1 task
Copy link
Member

@sifnoc sifnoc left a comment

Choose a reason for hiding this comment

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

In this audit comments, many findings are related to supporting the off-chain verification with full_verifier.

/*
If I understand correctly, the function `dispatch_proof_of_address_ownership` returns a `Result<(), Box<dyn Error>>`.
When we call unwrap on the result, it will panic if the result is an error.
Is that correct?
Copy link
Member

Choose a reason for hiding this comment

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

Yes, It is correct. I will modify all error propagation in the async functions.

@@ -38,13 +38,24 @@ async fn main() -> Result<(), Box<dyn Error>> {
)
.unwrap();

/*
I think that this part related to `address_hashes` can be safely removed.
The example should be as simple as possible.
Copy link
Member

Choose a reason for hiding this comment

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

That makes sense. There isn't any check procedure for the Submit solvency proof too.
FYI, The only reason for adding this checking step is due to the require term in the contract:

require(
addressOwnershipProofs.length != 0,
"The CEX has not submitted any address ownership proofs"
);

@@ -140,6 +169,15 @@ async fn main() -> Result<(), Box<dyn Error>> {

let public_inputs = downloaded_inclusion_proof.get_public_inputs();

/*
Why leaf_hash is public_inputs[0][0] while mst_root is public_inputs[1]?
Shouldn't public_inputs be a vector with 2 elements?
Copy link
Member

Choose a reason for hiding this comment

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

I've overridden public_inputs to be a one-dimensional vector for simplicity.
However, the reason public_inputs was initially structured as a two-dimensional vector was due to the way the full_verifier function receives and processes it.

pub fn full_verifier(
params: &ParamsKZG<Bn256>,
vk: &VerifyingKey<G1Affine>,
proof: Vec<u8>,
public_inputs: Vec<Vec<Fp>>,
) -> bool {

@@ -29,6 +32,11 @@ impl AddressOwnership {
&self.address_ownership_proofs
}

/*
If I understand correctly, an error in submit_proof_of_address_ownership is propagated to the caller.
Is that correct?
Copy link
Member

Choose a reason for hiding this comment

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

Yes, the try operator, "?", returns an Error when one occurs.

/*
Since we are now using the `MstInclusionProof` only for on-chain verification,
why don't we replace the data type with something that can be directly consumed by the contract?
Similar to `SolvencyProof`.
Copy link
Member

Choose a reason for hiding this comment

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

We still support off-chain verification using the full_verifier method.
That's why I haven't changed the public_inputs type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can set the on-chain verifcation (via the smart contract interface) as standard way to perform the proof of inclusion verification. This is because of the nice UX that it provides + full transparency on the code being executed compared to the other available solutions.

Therefore I suggest to remove every dependency that relates to off-chain verification and foucs on the on-chain path.

@@ -78,6 +86,9 @@ where
[usize; N_ASSETS + 1]: Sized,
[usize; 2 * (1 + N_ASSETS)]: Sized,
{
/*
Build signer outside of the constructor and pass it in as a parameter.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I will handle this at #155 Refactor signers

@@ -104,6 +115,10 @@ where
self.timestamp
}

/*
If I understand correctly, an error in submit_proof_of_solvency is propagated to the caller.
Is that correct?
Copy link
Member

Choose a reason for hiding this comment

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

Yes, the try operator, "?", returns an Error when one occurs.

@@ -202,6 +217,10 @@ where
let circuit =
MstInclusionCircuit::<LEVELS, N_ASSETS, N_BYTES>::init(self.mst.clone(), user_index);

/*
Why can't we get the `calldata` using `gen_proof_solidity_calldata` similar to `generate_proof_of_solvency`?
*/
Copy link
Member

Choose a reason for hiding this comment

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

We can use gen_proof_solidity_calldata similar to generate_proof_of_solvency.
However, as I mentioned earlier, the type of public_inputs is closely related to the full_verifier, which is why I've kept it as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

See comments above

@@ -41,6 +41,9 @@ impl SummaSigner {
}
}

/*
This method is never used. Can it be removed?
*/
Copy link
Member

Choose a reason for hiding this comment

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

Yes! I will remove this.

@enricobottazzi enricobottazzi deleted the enrico/backend-audit branch November 21, 2023 14:32
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.

Internal Audit of Backend
2 participants