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

Separated signer from core components. #174

Merged
merged 4 commits into from
Nov 8, 2023
Merged

Separated signer from core components. #174

merged 4 commits into from
Nov 8, 2023

Conversation

sifnoc
Copy link
Member

@sifnoc sifnoc commented Nov 1, 2023

  • AddressOwnership and Round now require a Signer for initialization. and they use same signer instance.
  • The Signer has a mutex lock for preventing nonce collision.
  • Added test case that submit two solvency proofs at the same time.

@sifnoc sifnoc marked this pull request as ready for review November 4, 2023 09:55
@sifnoc sifnoc requested review from enricobottazzi and alxkzmn and removed request for enricobottazzi November 4, 2023 09:55
This was linked to issues Nov 6, 2023
Copy link
Member

@enricobottazzi enricobottazzi left a comment

Choose a reason for hiding this comment

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

Kudos for thinking about the nonce collision problem and finding an elegant solution for that.

I left some minor comment, but LGTM.

Relying on @alxkzmn review for checking that the testing is done correctly

address_ownership_proofs: Vec<AddressOwnershipProof>,
signer: SummaSigner,
signer: &'a SummaSigner,
}
Copy link
Member

Choose a reason for hiding this comment

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

I understand (and appreciate) your choice of using a lifetime annotation for the SummaSigner reference. This is the only place in the code base we use that. Do you think there are other places in which this might be needed for managing references?

Copy link
Member Author

Choose a reason for hiding this comment

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

The lifetime annotation is necessary because the signer instance is shared between both Round and AddressOwnership. I traced the flow of data like this: RoundSnapshotMerkleSumTreeNode, Entry. There doesn't seem to be any need for data sharing along that chain.

The only improvement I identified is that there's no need to clone merkle_sum_tree when initializing circuits.
For instance, instead of
let mut circuit = MstInclusionCircuit::<LEVELS, N_ASSETS, N_BYTES>::init(merkle_sum_tree.clone(), 0);,
it could be
let mut circuit = MstInclusionCircuit::<LEVELS, N_ASSETS, N_BYTES>::init(&merkle_sum_tree, 0);.

Copy link
Member

@enricobottazzi enricobottazzi Nov 6, 2023

Choose a reason for hiding this comment

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

Good point! Gonna create an issue for that => #180

Copy link
Member Author

@sifnoc sifnoc Nov 6, 2023

Choose a reason for hiding this comment

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

Good point! Gonna create an issue for that

I got fixed one, let assign to me :)

1,
)
.unwrap();
let mut round = Round::<4, 2, 14>::new(&signer, entry_csv, asset_csv, params_path, 1).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

can you create a variable named timestamp and assign 1 to that. Passing 1 directly to the new function might not be clear for the reader

.unwrap();
);

let mut address_ownership_client = AddressOwnership::new(&signer, signature_csv_path).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

much more clean 😍

@@ -136,18 +170,77 @@ mod test {
Ok(())
}

#[tokio::test]
async fn test_concurrent_proof_submissions() -> Result<(), Box<dyn Error>> {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make much clear in the commments what is the goal of this test and how the results you are obtaining are proving that the goal was accomplished?

// Using AddressInput::Address to directly provide the summa_contract's address.
// For deployed contracts, if the address is stored in a config file,
// you can alternatively use AddressInput::Path to specify the file's path.
let mut address_ownership_client = AddressOwnership::new(
let signer = SummaSigner::new(
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
anvil.chain_id(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to provide the chainId when instantiating the provider? It's better to have the rpc url and chain ID together in one place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Simply speaking, the provider url is chain-specific so there shouldn't be a discrepancy between the provider url and chain ID

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it's better to derive the chain_id directly from the URL, instead of assigning it explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I got into the ethers code and I see that there's an RPC method call inside that retrieves the chain ID from the node: provider.get_chainid(). I think with this in mind it's enough to create the provider from the URL and then get the chain ID.

backend/src/contracts/signer.rs Show resolved Hide resolved
@alxkzmn alxkzmn merged commit 7489c53 into master Nov 8, 2023
4 checks passed
@enricobottazzi enricobottazzi deleted the shared-signer branch November 21, 2023 14:33
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.

Refactor signers Remove private_keys from Signer
3 participants