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

PBHVerifier #74

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

PBHVerifier #74

wants to merge 20 commits into from

Conversation

0xForerunner
Copy link
Contributor

Smart contract that verifies PBH Proofs on chain.

* The paymaster will pay for the transaction instead of the sender.
* @param signature - Sender-verified signature over the entire request, the EntryPoint address and the chain ID.
*/
struct PackedUserOperation {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we inherit this type from the account-abstraction contracts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yeah for sure :) sorry this isn't even close to being ready for review haha. I just opened the PR to show the external nullifier implementation!

IWorldIDGroups internal immutable worldId;

/// @dev The World ID group ID (always 1)
uint256 internal immutable groupId = 1;
Copy link
Contributor

@0xKitsune 0xKitsune Dec 11, 2024

Choose a reason for hiding this comment

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

Nit: Consider SCREAMING_SNAKE_CASE for immutables, similar to constants. There is no hard and fast rule for this but this is a common pattern.

@0xKitsune
Copy link
Contributor

Looks great, very clean!

PackedUserOperation memory userOp,
uint256 root,
uint256 nullifierHash,
ExternalNullifier memory externalNullifier,

Choose a reason for hiding this comment

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

how are we getting the externalNullifier data here - do we need to add this with the proof in the signature

or is this determined by the builder?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@karankurbur Yes, this should be decoded from the signature on the UserOperation

Copy link
Collaborator

@0xOsiris 0xOsiris left a comment

Choose a reason for hiding this comment

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

This looks good as a first pass, very clean! One small nit would be to rename the top level directory to contracts since the PbhAggregator I'm assuming will live in the foundry workspace + different contracts, and utils.

Additionally can we simply emit the proof instead of verifying on chain after checking the uniqueness of the nullifier hash for the builder to verify during transaction validation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we also move this workflow to the root .github/workflows

/// @return The encoded PBHExternalNullifier.
function encode(uint8 pbhNonce, uint8 month, uint16 year) internal pure returns (uint256) {
require(month > 0 && month < 13, InvalidExternalNullifierMonth());
require(year <= 9999, InvalidExternalNullifierYear());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: You can use type(uint16).max here.

require(year <= type(uint16).max, InvalidExternalNullifierYear());

RUN ./script/generate_anvil_state.sh

ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--load-state", "state.json"]
CMD []

Choose a reason for hiding this comment

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

By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'.

Suggested change
CMD []
USER non-root
CMD []
Ignore this finding from missing-user.

Choose a reason for hiding this comment

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

Semgrep Assistant suggests the following fix: Add a non-root user to the Dockerfile and specify it with the USER instruction before the CMD.

View step-by-step instructions
  1. Add a new user to the Dockerfile by including the following line before the CMD instruction: RUN groupadd -r app && useradd -r -g app -u 2000 app.
  2. Change the ownership of the application directory to the new user by adding: chown app:app -R /world-id.
  3. Specify the user to run the application by adding the line USER 2000 before the CMD instruction.

Leave feedback with a 👍 / 👎. Save a memory with /remember <your custom instructions>.

# RUN ls script; exit 1
RUN ./script/generate_anvil_state.sh

ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--load-state", "state.json"]

Choose a reason for hiding this comment

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

By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'.

Suggested change
ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--load-state", "state.json"]
USER non-root
ENTRYPOINT ["anvil", "--host", "0.0.0.0", "--load-state", "state.json"]
Ignore this finding from missing-user-entrypoint.

Choose a reason for hiding this comment

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

Semgrep Assistant suggests the following fix: Switch to a non-root user in the Dockerfile to run the application with reduced privileges.

View step-by-step instructions
  1. Add a non-root user to the Dockerfile. You can do this by adding a line such as RUN useradd -m non-root after the COPY . . line.
  2. Switch to the non-root user by adding USER non-root before the ENTRYPOINT line. This ensures that the application runs with non-root privileges, reducing security risks.

Leave feedback with a 👍 / 👎. Save a memory with /remember <your custom instructions>.

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.

4 participants