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

Deployment Review Script #683

Merged
merged 16 commits into from
Jul 9, 2024
Merged

Deployment Review Script #683

merged 16 commits into from
Jul 9, 2024

Conversation

remedcu
Copy link
Member

@remedcu remedcu commented Jul 4, 2024

This PR improves the review cycle for the safe-deployment by checking the new deployments when a new PR is created for a particular chain.

This PR:

  • instead of an ISSUE_TEMPLATE, introduced a PR Template which will ask for the required data from the PR creator, and help run the CI script.
  • adds a CI review script, which succeeds if everything seems ok, else, it helps the PR creator to know what might be a problem with merging the PR in the CI logs.
  • updates the github-review script, which checks for edge cases when a chain ID with the highest number is added.
  • updates the test to accommodate the change in the JSON structure for the codehash (because v.1.3.0 has multiple deployment types).
  • updated the JSON structure to include address and code hash within a single object with the deployment type as the key.
  • ZKSync support in CI mentioned in Add zkSync Support To Automated New Chain Checks #662 (Ex: 324 remedcu/safe-deployments#8)

Remaining TODO's:

  • There is a possibility that a user removes one of the deployment types (currently only applicable with v1.3.0) from the current list. This can't be detected with the current script.

@remedcu remedcu added the enhancement New feature or request label Jul 4, 2024
@remedcu remedcu self-assigned this Jul 4, 2024
@remedcu remedcu requested review from gjeanmart and a team as code owners July 4, 2024 11:57
scripts/codehash.js Outdated Show resolved Hide resolved
@remedcu remedcu marked this pull request as draft July 5, 2024 08:51
bin/github-review.sh Outdated Show resolved Hide resolved
bin/github-review.sh Outdated Show resolved Hide resolved
fileLineChangeJSON=$(gh pr view $pr --json files) # This line fetches the JSON output of the files changed in the PR
edgeCase=0
echo "$fileLineChangeJSON" | jq -r '.files[] | "\(.path) \(.additions) \(.deletions)"' | while read -r line; do
path=$(echo $line | cut -d ' ' -f1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

uber-nano-nit: If path has a space, this will break. I suggest using a non-standard character (\0 is commonly used).

Not a huge deal for our case, since we know the file names - but just wanted to point it out in case it is easy to fix (if it isn't - leave 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.

Did you mean something like:

    path=$(echo $line | cut -d '\0' -f1)

In this case, as you mentioned, as file names are known, this might not be a scenario for us.

bin/github-review.sh Outdated Show resolved Hide resolved
bin/github-review.sh Outdated Show resolved Hide resolved
# Adding three elements at a time together to compare from the output array
diffPatch=()
for ((i=0; i<${#diffPatchSeparated[@]}; i+=3)); do
diffPatch+=("${diffPatchSeparated[i]} ${diffPatchSeparated[i+1]} ${diffPatchSeparated[i+2]}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this depend on how many before lines and after lines are included in the diff?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but we already know that if it enters this if branch, there are only 2 additions and 1 subtraction. With grep we only take the actual lines added and deleted in the diff patch. And if it doesn't follow the intended pattern (based on the check we have written), then it errors out, as it should be.

done

if [[ $edgeCase == 1 ]]; then
echo "Edge case when adding chain with the highest chain id number"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This loop is quite complicated to me, and I'm not sure I understand it. I will try with fresh eyes on Monday.

bin/github-review.sh Outdated Show resolved Hide resolved
bin/github-review.sh Outdated Show resolved Hide resolved
echo "ERROR: "$file" code hash is not the same as the one created for the chain id" 1>&2
exit 1
fi
for deploymentType in "${deploymentTypes[@]}"; do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this run for each version type for each file for each file? My understanding is that the deploymentTypes is built for all files (so it will have a duplicate for each file).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it will run for each version if there is more than one version deployed for that particular chain (only limited to v1.3.1). Which I think should not be a problem, other than if the RPC have some limit of less than 18 requests per minute or so.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be fixed by deduping deploymentTypes. My point is that, AFAIU from how JQ works with multiple files specified, for 1.3.1 it will be something like:

deploymentTypes=(canonical eip155 canonical eip155 canonical eip155 canonical eip155 canonical eip155 canonical eip155 canonical eip155 canonical eip155 canonical eip155)

Copy link
Member Author

Choose a reason for hiding this comment

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

So, I just checked with the below bash code for this PR:

deploymentTypes=($(jq -r --arg c "$chainid" '[.networkAddresses[$c]] | flatten | .[]' "$versionFiles"))
echo ${deploymentTypes[@]}
for file in "${versionFiles[@]}"; do
    for deploymentType in "${deploymentTypes[@]}"; do
        echo $deploymentType

And I get the output:

Checking changes to other files
Checking changes to assets files
Verifying Deployment Asset
canonical eip155
canonical
eip155
canonical
eip155
canonical
eip155
canonical
eip155
canonical
eip155
canonical
eip155
canonical
eip155
canonical
eip155
canonical
eip155
Network addresses & Code hashes are correct

This is what I was expecting, so it doesn't have 18 values in total for each file, instead has 2 values (based on the deployment type: canonical and eip155) for each file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh... I guess I don't know bash arrays very well. Is "$versionFiles" implicitly doing "${versionFiles[0]}"?

Copy link
Member Author

Choose a reason for hiding this comment

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

@remedcu
Copy link
Member Author

remedcu commented Jul 8, 2024

Test results:

In all the PR's the test CI fail, because to check things, I deleted some Chains. Before making this PR "Ready for review", will restore it.

@remedcu remedcu requested a review from nlordell July 8, 2024 11:38

# Getting default addresses, address on the chain and checking code hash.
deploymentTypes=($(jq -r --arg c "$chainid" '[.networkAddresses[$c]] | flatten | .[]' "$versionFiles"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is dangerous for arrays - you should use:

Suggested change
deploymentTypes=($(jq -r --arg c "$chainid" '[.networkAddresses[$c]] | flatten | .[]' "$versionFiles"))
deploymentTypes=($(jq -r --arg c "$chainid" '[.networkAddresses[$c]] | flatten | .[]' "${versionFiles[@]}"))

Copy link
Member Author

Choose a reason for hiding this comment

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

Now this comment make more sense. So, instead of all the version files, I am intentionally only selecting a single file (defaults to the first value in the array), as the deployment types should be the same for all the files.

So, if I make it to parse the values from all files (based on the above suggestion), then it will return all the deployment types of all the files, which is not the intended output.

@remedcu remedcu requested a review from nlordell July 9, 2024 07:58
src/types.ts Outdated Show resolved Hide resolved
@remedcu remedcu requested a review from mmv08 July 9, 2024 12:11
@remedcu remedcu marked this pull request as ready for review July 9, 2024 12:19
Copy link
Member

@mmv08 mmv08 left a comment

Choose a reason for hiding this comment

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

gj 🔥

},
"eip155": {
"address": "0x998739BFdAAdde7C933B942a68053933098f9EDa",
"codeHash": "0x81db0e4afdf5178583537b58c5ad403bd47a4ac7f9bde2442ef3e341d433126a"
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that the codehash is different here 🤔

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 codeHash for multiSend and SimulateTxAccessor is different as it uses the address(this) within the constructor, thus making a different bytecode based on the address.

@remedcu remedcu merged commit 57ebd9b into safe-global:main Jul 9, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants