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

feat(state-tree-depth) - ensure stateTreeDepth is not hardcoded #777

Merged
merged 5 commits into from
Nov 15, 2023

Conversation

ctrlc03
Copy link
Collaborator

@ctrlc03 ctrlc03 commented Oct 24, 2023

We do not want to hardcode the stateTreeDepth in the smart contracts, but instead we want to pass them as arguments.

Changes:

  • in the smart contract this is an immutable param thus passed in the constructor
  • MaciState.ts and Poll.ts take them as constructor argument
  • in tests we hardcode to 10 for the sake of testing
  • contracts package.json's script compileSol takes an additional parameter so that we can compile the trees contracts with the correct params

@@ -129,6 +131,7 @@ contract MACI is IMACI, DomainObjs, Params, SnarkCommon, Ownable {
pollFactory = _pollFactory;
signUpGatekeeper = _signUpGatekeeper;
initialVoiceCreditProxy = _initialVoiceCreditProxy;
stateTreeDepth = _stateTreeDepth;
Copy link
Member

Choose a reason for hiding this comment

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

Is there any danger in this value now being an arbitrary size? i.e. should there be a check against some max value?

Copy link
Collaborator Author

@ctrlc03 ctrlc03 Oct 26, 2023

Choose a reason for hiding this comment

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

Yes and no. If they put a value that does not match the circuit, they would basically need to start over (there might be some workarounds though, still not ideal).

This is a uint8 so max value would be 255, having said that, a tree depth of 255 would be incredibly big, considering 10 allows for a little bit more than 1M total signups.
My view here is the following:

  1. if we put a max value, what should this be?
  2. In the past, we asked the users to change a constant variable rather than passing it as a constructor parameter:
    • I consider these options kinda the same, we never really validated that this constant variable was > than a max value
    • people running MACI should be (and are to some extent) informed that this parameter should match the one in the circuits, hence it is their responsibility of setting it up correctly.
  3. even if this value was < than a max value we decide on, it could still be different than what they put in the circuit and in the other components of MACI -> end result would still not work

To summarize, I think the best we can do here in terms of "validation" is to properly inform that this value should match whichever value is in the Circom circuits and how many signups each value supports.


describe('Deployment', () => {
beforeAll(async () => {
signer = await getDefaultSigner()
const r = await deployTestContracts(
initialVoiceCreditBalance,
STATE_TREE_DEPTH,
true
Copy link
Member

Choose a reason for hiding this comment

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

Why pass true here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh basically those utils functions like deployTestContract or deployContract have an optional parameter called "quiet", passing true so it doesn't print unnecessary logs while running the tests

@ctrlc03 ctrlc03 requested a review from samajammin October 26, 2023 08:55
@ctrlc03 ctrlc03 force-pushed the feat/immutable-circuit-params branch from 7c1580d to a755b18 Compare November 1, 2023 14:57
@baumstern
Copy link
Member

To confirm, we don't have to follow the steps described in this doc anymore?

@ctrlc03 ctrlc03 force-pushed the feat/immutable-circuit-params branch from 6d562ea to 30ec3d9 Compare November 1, 2023 18:55
@ctrlc03
Copy link
Collaborator Author

ctrlc03 commented Nov 1, 2023

To confirm, we don't have to follow the steps described in this doc anymore?

correct, I would say we probably need to improve documentation on this change - for now I updated the scripts in the contracts folder, as well as the README. What do you think, should we updated the cli docs too to ensure the new flag ("-s") is more evident? would be curious to hear your opinion after you review this PR and how it worked for you testing it

str2BigInt,
getSignal
}
export const STATE_TREE_DEPTH = 10
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason this is here? Perhaps it could fit well in constants.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

totally

crypto/ts/__tests__/AccQueue.test.ts Outdated Show resolved Hide resolved
crypto/ts/__tests__/Crypto.test.ts Outdated Show resolved Hide resolved
@baumstern
Copy link
Member

To confirm, we don't have to follow the steps described in this doc anymore?

correct, I would say we probably need to improve documentation on this change - for now I updated the scripts in the contracts folder, as well as the README. What do you think, should we updated the cli docs too to ensure the new flag ("-s") is more evident? would be curious to hear your opinion after you review this PR and how it worked for you testing it

It’s an essential value, so it should be as visible as possible. However, people often don’t read the documentation thoroughly..so we might need to seek a somewhat better way to highlight it. Although a good idea doesn’t come to mind immediately.

@ctrlc03 ctrlc03 requested a review from baumstern November 10, 2023 15:41
@baumstern
Copy link
Member

Just a reminder that there is a merge conflict that needs to be addressed. Once that's resolved, it looks like we're all set to merge this PR into the dev branch. Great work!

@ctrlc03 ctrlc03 force-pushed the feat/immutable-circuit-params branch from 30ec3d9 to b01eabc Compare November 14, 2023 08:11
@ctrlc03
Copy link
Collaborator Author

ctrlc03 commented Nov 14, 2023

Just a reminder that there is a merge conflict that needs to be addressed. Once that's resolved, it looks like we're all set to merge this PR into the dev branch. Great work!

merge conflicts sorted! thanks for the review

Copy link
Member

@baumstern baumstern left a comment

Choose a reason for hiding this comment

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

LGTM

@baumstern baumstern merged commit 5aa400f into dev Nov 15, 2023
8 checks passed
@samajammin samajammin deleted the feat/immutable-circuit-params branch November 24, 2023 05:46
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.

maci-contracts and maci-core packages have a hard-coded stateTreeDepth value of 10
3 participants