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/constrain-ids #466

Merged
merged 11 commits into from
Sep 14, 2023
Merged

feat/constrain-ids #466

merged 11 commits into from
Sep 14, 2023

Conversation

kanej
Copy link
Member

@kanej kanej commented Sep 13, 2023

We do not enforce any rules on the types of ids that can be used for modules or actions. This is a problem because we use those ids when writing to the file system (including on windows).

This PR introduces rules on module ids, user provided action ids and all of the components that can be used as fallbacks to generate an id.

Module ids and user provided action ids are only allowed to start with a letter and then include only alphanumerics and underscores:

/^[a-zA-Z][a-zA-Z0-9_]*$/

The contract names, event names, args are validated based on Solidity's identifier rules:

/^[a-zA-Z$_][a-zA-Z0-9$_]*$/

Function names and event names are slightly looser than the Solidity identifier rule to support ethers style function/event + params myfun(uint256,bool):

/^[a-zA-Z$_][a-zA-Z0-9$_,()]*$/

With constraints on the parts that are used to build up the surrogate ids, and by ensuring our combination separators are valid we can ensure that all our ids are valid for filenames on windows/linux.

As such we are changing the separator symbols to those that can work as windows filenames, specifically:

  • : -> #
  • # -> .
| Future                      | Before                                 | After                                  | User Provided ID         |
| --------------------------- | -------------------------------------- | -------------------------------------- | ------------------------ |
| contract/library/contractAt | MyModule:MyContract                    | MyModule#MyContract                    | MyModule#MyId            |
| call/staticCall             | MyModule:MyContract#MyFunction         | MyModule#MyContract.MyFunction         | MyModule#MyContract.MyId |
| readEventArgument           | MyModule:MyContract#MyFunction#MyArg#2 | MyModule#MyContract.MyFunction.MyArg.2 | MyModule#MyId            |
| send                        | MyModule:MyId                          | MyModule#MyId                          | MyModule#MyId            |

This PR also:

  • removes options id from send
  • changes namespacing on calls to just be MyModule#Call1 for user provided ids matching the other rules

Review

I would suggest taking the commits in order. The first commits refactor our code to pull the id and validation code into one place. The final commit swaps the separators (but this ends up touching quite a few files, mainly tests).

@kanej kanej force-pushed the feat/constrain-ids branch 2 times, most recently from 8e459a0 to 9e93069 Compare September 13, 2023 22:06
@kanej kanej marked this pull request as ready for review September 13, 2023 22:11
@kanej kanej requested a review from alcuadrado September 13, 2023 22:11
@kanej kanej linked an issue Sep 13, 2023 that may be closed by this pull request
We are limiting the user provided ids for builder actions to
alphanumeric/underscores/dashes. This is to support filenames on
windows.
The elements we use to build the id should be limited in such a way that
we can write them out as filenames on windows.

We constrain contract names to alphanumerics/underscore/dollar sign. We
similarly constrain function names.

Though function names had to be loosened to allow for the `myfun(uint256,bool)` syntax we
support.
The id is provided as a parameter. We don't need a second overriding id
in this case.
Move the individual future id generators into its own module and put it
under test.
Also remove underscores from Ignition identifiers.
We now use the same rule for namespacing the a call/staticCall action as
we use for other actions. If the user provides an id, the only
namespacing is to the module (rather than the module/contract as it was
before).
Modify our id separators, swapping:

- `:` => `#`
- `#` => `.`

This allows us to write the identifiers as filenames on windows.

Resolves #441.
@kanej kanej force-pushed the feat/constrain-ids branch from 9e93069 to ba6d5bc Compare September 14, 2023 10:04
@kanej kanej merged commit 8d08c1b into development Sep 14, 2023
6 checks passed
@kanej kanej deleted the feat/constrain-ids branch September 14, 2023 10:42
@kanej kanej mentioned this pull request Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

validate module names and actions ids
1 participant