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

Add verify audit action #793

Closed
wants to merge 3 commits into from
Closed

Add verify audit action #793

wants to merge 3 commits into from

Conversation

0xDEnYO
Copy link
Contributor

@0xDEnYO 0xDEnYO commented Sep 6, 2024

Which Jira task belongs to this PR?

Why did I implement it this way?

Checklist before requesting a review

  • I have performed a self-review of my code
  • This pull request is as small as possible and only tackles one problem
  • I have added tests that cover the functionality / test the bug
  • I have updated any required documentation

Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)

  • I have checked that any arbitrary calls to external contracts are validated and or restricted
  • I have checked that any privileged calls (i.e. storage modifications) are validated and or restricted
  • I have ensured that any new contracts have had AT A MINIMUM 1 preliminary audit conducted on by <company/auditor>

Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Warning

Rate limit exceeded

@0xDEnYO has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 46 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 2e19d4d and c0e371c.

Walkthrough

A new GitHub Actions workflow named verifyAudit.yml has been introduced to automate the auditing process for pull requests that modify or add smart contracts in the src directory. The workflow triggers on specific PR events and checks for changes in protected contracts, verifies audit completion, and manages labels to indicate the audit status.

Changes

Files Change Summary
.github/workflows/verifyAudit.yml Introduced a new workflow for auditing smart contracts, including checks for audit completion and status labeling.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lifi-action-bot
Copy link
Collaborator

Test Coverage Report

Line Coverage: 75.37% (1595 / 2116 lines)
Function Coverage: 83.33% ( 345 / 414 functions)
Branch Coverage: 49.41% ( 254 / 514 branches)
Test coverage (75.37%) is above min threshold (74%). Check passed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c1998e and 2e19d4d.

Files selected for processing (1)
  • .github/workflows/verifyAudit.yml (1 hunks)
Additional context used
actionlint
.github/workflows/verifyAudit.yml

144-144: shellcheck reported issue in this script: SC2034:warning:9:1: COMMIT_HASHES_FILE appears unused. Verify use (or export if used externally)

(shellcheck)


144-144: shellcheck reported issue in this script: SC2034:warning:10:1: AUDITOR_GIT_HANDLES_FILE appears unused. Verify use (or export if used externally)

(shellcheck)


144-144: shellcheck reported issue in this script: SC2027:warning:122:94: The surrounding quotes actually unquote this. Remove or escape them

(shellcheck)


144-144: shellcheck reported issue in this script: SC2086:info:122:94: Double quote to prevent globbing and word splitting

(shellcheck)


144-144: shellcheck reported issue in this script: SC2086:info:159:19: Double quote to prevent globbing and word splitting

(shellcheck)

Additional comments not posted (5)
.github/workflows/verifyAudit.yml (5)

1-10: General Overview: Workflow Description

The workflow is well-documented with comments explaining each step, which is crucial for maintainability and understanding the purpose of the workflow. The comments clearly outline the conditions under which labels are assigned and the verification process for audits. This is a good practice as it helps future maintainers or reviewers understand the logic and purpose of the workflow.


15-28: Trigger Conditions and Environment Setup

The workflow is triggered on pull request events such as opened, synchronize, reopened, and ready_for_review, which are appropriate for the audit checks it performs. The environment variables and secrets are well-defined, ensuring that the workflow has all the necessary information to perform its tasks. Using GITHUB_TOKEN with a specific permission set enhances security by limiting the scope of actions the workflow can perform.


29-72: Detailed Review of Steps: Checking for Protected Contracts

The script checks for changes in protected folders and handles the absence of changes robustly by setting an environment variable to prevent further steps from executing. This is a critical part of the workflow as it determines whether an audit is necessary based on the files changed in the PR. The use of environment variables to pass state between steps is a good practice in GitHub Actions workflows.


363-387: Final Steps: Label Assignment and Failure Handling

The final steps of the workflow handle the assignment of the "AuditCompleted" label and ensure that the workflow fails correctly if any critical checks do not pass. The use of conditional steps based on the CONTINUE environment variable is a good practice to control the flow of the workflow based on the outcomes of previous steps.


73-138: Label Management Logic

The logic to manage labels based on the audit requirement is implemented effectively. Using conditional checks and the GitHub CLI to manipulate labels ensures that the PR is correctly annotated based on its audit status. The detailed logging and error handling in this section help in debugging and maintaining the workflow. However, ensure that the labels used are correctly configured in the repository to avoid issues during execution.

Verification successful

Labels are correctly configured in the repository

The labels "AuditRequired" and "AuditNotRequired" used in the workflow are present in the repository, ensuring that the label management logic will function as intended. No further action is needed regarding label configuration.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify label configuration in the repository
gh label list

Length of output: 231

Comment on lines +11 to +14
# KNOWN LIMITATIONS
# - will only check the last 100 commits for any matches with audit commit hashes
# - only one audit can be registered per contract (in a specific version)

Copy link
Contributor

Choose a reason for hiding this comment

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

Consideration of Known Limitations

The workflow acknowledges its limitations, such as only checking the last 100 commits and handling one audit per contract version. This transparency is beneficial for users and maintainers to understand the scope and constraints of the workflow. However, it might be useful to explore ways to handle these limitations in future iterations, possibly by integrating more robust handling mechanisms or expanding the scope of the audit checks.

Consider addressing these limitations in future updates to ensure the workflow can handle more complex scenarios.

Comment on lines +139 to +362

##### make sure that a file exists at the audit report path
if [ ! -f "$AUDIT_REPORT_PATH" ]; then
echo -e "\033[31mCould not find an audit report in path $AUDIT_REPORT_PATH for contract "$FILENAME".\033[0m"
echo -e "\033[31mThis github action cannot complete before the audit report is uploaded to 'audit/reports/'.\033[0m"
echo -e "\033[31mAborting now.\033[0m"
echo "CONTINUE=false" >> "$GITHUB_ENV"
exit 1
else
echo "The audit report for $AUDIT_ID was found in path $AUDIT_REPORT_PATH"
fi

##### make sure that audit log entry contains audit commit hash
if [ -z "$AUDIT_COMMIT_HASH" ]; then
echo -e "\033[31mThe audit log entry for file $FILE contains invalid or no 'auditCommitHash' information.\033[0m"
echo -e "\033[31mThis github action cannot complete before the audit log is complete.\033[0m"
echo -e "\033[31mAborting now.\033[0m"
echo "CONTINUE=false" >> "$GITHUB_ENV"
exit 1
else
echo "The audit log contains the commit hash that was audited in $AUDIT_ID: $AUDIT_COMMIT_HASH"
fi
echo -e "\033[32mThe audit log contains all required information for contract $FILE\033[0m"

echo "now checking if audit commit hash $AUDIT_COMMIT_HASH is associated with PR $PR_NUMBER"
##### Fetch the list of commits associated with the PR
COMMIT_LIST=$(gh pr view "$PR_NUMBER" --json commits --jq '.commits[].oid')

##### Check if the target commit is in the list
if echo "$COMMIT_LIST" | grep -q "$TARGET_COMMIT"; then
echo -e "\033[32mCommit $AUDIT_COMMIT_HASH is associated with PR #$PR_NUMBER.\033[0m"
else
echo -e "\033[31mCommit $AUDIT_COMMIT_HASH is NOT associated with PR #$PR_NUMBER.\033[0m"
echo "CONTINUE=false" >> "$GITHUB_ENV"
exit 1
fi


##### Check if the auditor git handle exists on github
echo "now checking if the auditor git handle ($AUDITOR_GIT_HANDLE) actually exists"
if gh api users/$AUDITOR_GIT_HANDLE > /dev/null 2>&1; then
echo -e "\033[32mA user with handle '$AUDITOR_GIT_HANDLE' exists on GitHub.\033[0m"
else
echo -e "\033[31mA user with handle '$AUDITOR_GIT_HANDLE' does not exist on GitHub.\033[0m"
echo -e "\033[31mPlease fix the audit log before continuing.\033[0m"
echo -e "\033[31mCheck failed.\033[0m"
echo "CONTINUE=false" >> "$GITHUB_ENV"
exit 1
fi

# ##### -----------------------------------------------------------------------------
# ##### DISABLED FOR NOW (NEED TO CHECK IF THIS IS COMPATIBLE WITH OUR FLOW)
# ##### Fetch PR reviews using the GitHub API via gh cli
# echo "now checking if the auditor ($AUDITOR_GIT_HANDLE) approved this PR ($PR_NUMBER)"
# REVIEWS=$(gh api repos/lifinance/contracts/pulls/$PR_NUMBER/reviews --jq '.[] | select(.state == "APPROVED") | @json')

# ##### Check if the output is empty or not valid JSON
# if [[ -z "$REVIEWS" ]]; then
# echo "ERROR: No reviews found or failed to fetch reviews for PR #$PR_NUMBER"
# exit 1
# fi
# ##### Flag to track if the review by the specified person is found
# FOUND_REVIEW=false

# ##### Check if the desired reviewer is present among the reviews
# echo "$REVIEWS" | jq -c '.' | while read -r REVIEW; do
# AUTHOR=$(echo "$REVIEW" | jq -r '.user.login // empty')
# STATE=$(echo "$REVIEW" | jq -r '.state // empty')

# echo "found review by $AUTHOR with state $STATE"


# ##### Check if the reviewer is the person we're looking for
# if [ "$AUTHOR" == "$REVIEWER" ]; then
# echo "Approving review found by $REVIEWER"
# FOUND_REVIEW=true
# exit 0
# fi
# done

# ##### If no matching review was found, exit with an error
# if [ "$FOUND_REVIEW" == true ]; then
# echo -e "\033[32mPR $PR_NUMBER has an approving review by $AUDITOR_GIT_HANDLE\033[0m"
# echo -e "\033[32mCheck passed\033[0m"
# exit 0
# else
# echo -e "\033[31mERROR: No review found by git user '$AUDITOR_GIT_HANDLE' (= the auditor)\033[0m"
# echo -e "\033[31mCheck failed\033[0m"
# echo "CONTINUE=false" >> "$GITHUB_ENV"
# exit 1
# fi
# ##### -----------------------------------------------------------------------------


done <<< "$PROTECTED_CONTRACTS"

echo -e "\033[32mSuccessfully verified that all contracts in this PRs are audited.\033[0m"
echo -e "\033[32mCheck passed.\033[0m"
echo "CONTINUE=true" >> "$GITHUB_ENV"
echo "Assigning label 'AuditCompleted' next"
Copy link
Contributor

Choose a reason for hiding this comment

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

Audit Log Verification Process

This section is the core of the workflow, where it checks the audit log for each protected contract affected by the PR. The detailed checks for each required piece of information in the audit log are crucial for ensuring the integrity of the audit process. However, there are several shellcheck warnings that need to be addressed to ensure the script is robust and free of common scripting errors.

Address the shellcheck warnings to improve the script's robustness and reliability. Consider using double quotes to prevent globbing and word splitting, and verify the usage of declared variables.

Tools
actionlint

144-144: shellcheck reported issue in this script: SC2034:warning:9:1: COMMIT_HASHES_FILE appears unused. Verify use (or export if used externally)

(shellcheck)


144-144: shellcheck reported issue in this script: SC2034:warning:10:1: AUDITOR_GIT_HANDLES_FILE appears unused. Verify use (or export if used externally)

(shellcheck)


144-144: shellcheck reported issue in this script: SC2027:warning:122:94: The surrounding quotes actually unquote this. Remove or escape them

(shellcheck)


144-144: shellcheck reported issue in this script: SC2086:info:122:94: Double quote to prevent globbing and word splitting

(shellcheck)


144-144: shellcheck reported issue in this script: SC2086:info:159:19: Double quote to prevent globbing and word splitting

(shellcheck)

@0xDEnYO 0xDEnYO closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants