François
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # NM-0131 WorldCoin - INTERNAL NOTES **Repo** https://github.com/worldcoin/world-id-state-bridge/tree/9edc22a94d38870e175c14d0058c4b15bf09bc35 **Commit**: 9edc22a94d38870e175c14d0058c4b15bf09bc35 --- ### [Medium] Wrong state variable is set in the function `setGasLimitSendRoot(...)` **File(s)**: [`OpStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/OpStateBridge.sol#L171) **Description**: The `OpStateBridge` contract allows the owner to customize the gas limit for different methods. The value of `_gasLimitSendRoot` can be set by calling the function `setGasLimitSendRoot(...)`. However, in the current codebase, it sets the value for the wrong variable `_gasLimitSetRootHistoryExpiry` instead. ```solidity= function setGasLimitSendRoot(uint32 _opGasLimit) external onlyOwner { // @audit Should set _gasLimitSendRoot instead of _gasLimitSetRootHistoryExpiry _gasLimitSetRootHistoryExpiry = _opGasLimit; emit SetGasLimitSendRoot(_opGasLimit); } ``` **Recommendation(s)**: In the function `setGasLimitSendRoot(...)`, set the value for `_gasLimitSendRoot` instead of `_gasLimitSetRootHistoryExpiry`. **Status**: Fixed **Update from the client**: Fixed, [current state](https://github.com/worldcoin/world-id-state-bridge/blob/fd56d7b1096143f82e1f5e356422e12c63517b1a/src/OpStateBridge.sol#L192-L200). --- ### [Best Practices] Avoid using magic numbers **File(s)**: [`OpStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/OpStateBridge.sol#L98), [`PolygonWorldID.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonWorldID.sol#L80) **Description**: Enhancing code readability can be achieved by replacing magic numbers with meaningful constants. The code snippet below shows an example: ```solidity constructor( address _worldIDIdentityManager, address _opWorldIDAddress, address _crossDomainMessenger ) { opWorldIDAddress = _opWorldIDAddress; worldIDAddress = _worldIDIdentityManager; crossDomainMessengerAddress = _crossDomainMessenger; // @audit Avoid using magic number _gasLimitSendRoot = 100000; _gasLimitSetRootHistoryExpiry = 100000; _gasLimitTransferOwnership = 100000; } ``` **Recommendation(s)**: Consider replacing these magic numbers with named constants or variables that provide meaningful names and context for these values. **Status**: Fixed **Update from the client**: Fixed in commits [364826209](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/36482620947101eb2fef37995f962075f2c27f9a), [33df6b53](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/33df6b53fde9f542b81716dd87ce9557ab7ceb63) --- ### [Best Practices] Lack of event emission when updating state variables **File(s)**: [`PolygonStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonStateBridge.sol#L104), [`PolygonWorldID.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonWorldID.sol#L115) **Description**: It is best practice to emit an event when changing important state variables. The code snippet below shows an example where the function sets the address for `fxRootTunnel`, but does not emit an event. ```solidity function setFxRootTunnel(address _fxRootTunnel) external virtual override onlyOwner { require(fxRootTunnel == address(0x0), "FxBaseChildTunnel: ROOT_TUNNEL_ALREADY_SET"); // @audit Should emit event fxRootTunnel = _fxRootTunnel; } ``` **Recommendation(s)**: Consider emitting a suitable event when updating state variables. **Status**: Fixed **Update from the client**: Fixed in commits [33df6b53](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/33df6b53fde9f542b81716dd87ce9557ab7ceb63), [c3c25679](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/c3c256793ec086a748765370c81574228cc65d5f) --- ### [Best Practices] Inconsistent usage of custom errors **File(s)**: [`PolygonStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonStateBridge.sol), [`PolygonWorldID.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonWorldID.sol) **Description**: Within these contract, both `require()/revert()` and custom errors are employed. It is recommended to adopt a consistent approach and use only one error-handling method within each file. **Recommendation(s)**: Consider adopting a uniform error-handling method throughout the codebase. **Status**: Fixed **Update from the client**: Fixed in commit [52f2c77](https://github.com/worldcoin/world-id-state-bridge/pull/108/commits/52f2c776ee18c23595ad205aec693b0b986b2438) --- ### [Best Practices] Missing input validation in some functions **File(s)**: [`OpStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/OpStateBridge.sol), [`PolygonStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonStateBridge.sol), [`PolygonWorldID.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonWorldID.sol) **Description**: Some functions do not check for the validity of their input before utilizing them: - `OpStateBridge.transferOwnershipOp(...)` does not check if `_owner` is different than `address(0)`. Note that a check is [implemented](https://github.com/ethereum-optimism/optimism/blob/2f745cb53cfeb94e4fa0d9760232415c2ebacd80/packages/contracts-bedrock/src/L2/CrossDomainOwnable3.sol#L29) in `transferOwnership` function of `CrossDomainOwnable3` contract, but it can be endorsed at the protocol contract level. - gas limit setters (`setGasLimitSendRoot(...)`,`setGasLimitSetRootHistoryExpiry(...)`,`setGasLimitTransferOwnershipOp(...)` .. ) does not check for the validity of the gas limit (i.e., whether it differs from 0). - `PolygonStateBridge` constructor function lacks validation for inputs `_checkpointManager` `_fxRoot` and `_worldIDIdentityManager`, allowing them to be set as `address(0)`. - `PolygonWorldID` contract constructor lacks validation of `_fxChild` address. It is a good practice to include input validation in order to enhance code robustness and prevent unexpected errors. **Recommendation(s)**: We recommend implementing a check for inputs in different functions. **Status**: Fixed **Update from the client**: Fixed in commits [c3c25679](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/c3c256793ec086a748765370c81574228cc65d5f), [0c08228](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/0c08228457efbd652d01635da3bef73cd656b5aa) --- ### [Best Practices] Remove the testing library from the code base **File(s)**: [`WorldIDBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/abstract/WorldIDBridge.sol#L9) **Description**: The `WorldIdBridge` abstract contract imports the `forge-std` console library. ```solidity= import "forge-std/console.sol"; ``` **Recommendation(s)**: Consider removing the testing library in the production code base. **Status**: Fixed **Update from the client**: Fixed in commit [88beb2e](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/88beb2ed4b8a2a424abb25b9f0597056d765de43) --- ### [Best Practices] Incorrect NatSpec description in `_receiveRoot(...)` function **File(s)**: [`WorldIDBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/abstract/WorldIDBridge.sol#L109) **Description**: The `_receiveRoot(...)` function contains incorrect custom NatSpec. It specifies that the function may revert if the caller is not the owner. However, the function does not have this logic. ```solidity= /// @custom:reverts string If the caller is not the owner. function _receiveRoot(uint256 newRoot) internal { [...] } ``` **Recommendation(s)**: Consider correcting the NatSpec documentation to reflect the function's implementation. **Status**: Fixed **Update from the client**: Fixed in commit [844da90](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/844da908d748f2bff4d37aba5ea9f9a5689560eb) --- ### [Best Practices] Typos in the code base **File(s)**: [`WorldIDBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/abstract/WorldIDBridge.sol#L161), [`OpStateBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/OpStateBridge.sol#L66-L67) **Description**: The code base contains the following typos: - The NatSpec documentation from the `verifyProof(...)` function of the `WorldIDBridge` contract. ```solidity= /// @param root The of the Merkle tree ``` - The NatSpec documentation from the `OpStateBridge` contract: ```solidity= /// @notice Emmitted when the the StateBridge sets the gas limit for SetRootHistoryExpiryt /// @param _opGasLimit The new opGasLimit for SetRootHistoryExpirytimism ``` **Recommendation(s)**: Consider correcting the typos to improve code quality. **Status**: Fixed **Update from the client**: Fixed in commits [d89e337](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/d89e337b5c75188fc2bd69999ea5738eb5f80736), [399dec2](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/399dec2d8048cc84333fdfa855ca41371c6ee0b2), [e986574](https://github.com/worldcoin/world-id-state-bridge/pull/107/commits/e986574f41d10f132723e682cdb6e7535ea1c03c) --- ### [Best Practices] Optimization of `WorldIdBridge` **File(s)**: [`WorldIDBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/abstract/WorldIDBridge.sol) **Description**: The `treeDepth` state variable from the `WorldIDBridge` abstract contract is never updated. This value is only set within the `constructor`. ```solidity= /// @notice Constructs a new instance of the state bridge. /// /// @param _treeDepth The depth of the identities merkle tree. constructor(uint8 _treeDepth) { if (!SemaphoreTreeDepthValidator.validate(_treeDepth)) { revert UnsupportedTreeDepth(_treeDepth); } treeDepth = _treeDepth; } ``` **Recommendation(s)**: Gas optimization can be done following these steps: - change `treedepth` to an immutable variable (initialization in constructor) - change type of `getTreeDepth()` function to `pure` **Status**: Fixed **Update from the client**: `getTreeDepth()` needs to remain a `view` function for the contract to compile. The solidity compiler considers immutable variables to be non-pure because it is possible to initialize them with some state [link](https://docs.soliditylang.org/en/latest/contracts.html#pure-functions). Fixed in commits [12d09df](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/12d09dfea213785435dcbb3b1b267f7818fdf489), [8e0e5b4](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/8e0e5b4b4273abebf2974a1aefce7831ef4337f4) --- ### [Best Practices] Remove unused imports **File(s)**: [`PolygonWorldID.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/PolygonWorldID.sol#L7) **Description**: `PolygonWorldID` contract has the following imports that are not being used. ```solidity= import {SemaphoreTreeDepthValidator} from "./utils/SemaphoreTreeDepthValidator.sol"; import {SemaphoreVerifier} from "semaphore/base/SemaphoreVerifier.sol"; ``` **Recommendation(s)**: Consider removing unused imports from the contract. **Status**: Fixed **Update from the client**: Fixed in commit [33df6b5](https://github.com/worldcoin/world-id-state-bridge/pull/106/commits/33df6b53fde9f542b81716dd87ce9557ab7ceb63) --- ### [Info] Transaction ordering in L2 may leave `_latestRoot` in the wrong state after root hash expiration **File(s)**: [`WorldIDBridge.sol`](https://github.com/worldcoin/world-id-state-bridge/blob/9edc22a94d38870e175c14d0058c4b15bf09bc35/src/abstract/WorldIDBridge.sol#L135) **Description**: The propagation of `latestRoot` between L1 and L2 is done via messaging. The message data contains the new root hash but does not include the timestamp indicating the time of emission from L1. Depending on the different L1-L2 messaging mechanisms, the ordering of transactions cannot be ensured, and it could be possible that two messages sent from L1 to L2 to propagate root get validated in the reverse order on L2. This scenario has a limited impact since the user on L2 would just need to specify the root hash that contains its identity. However, there is an edge case when the root hash is not updated and expiration time (`ROOT_HISTORY_EXPIRY`) is reached for all root hashes. The only valid root hash is the latest one (`_latestRoot`) which could be the second to last one sent from L1. ```solidity= function requireValidRoot(uint256 root) internal view { // The latest root is always valid. if (root == _latestRoot) { return; } ``` All users registered between these two root hash propagations would not be able to create valid proofs on L2 until a new root hash is propagated. **Recommendation(s)**: Consider sending the timestamp from L1 to ensure the latest root hash is correctly updated. **Status**: Acknowledged **Update from the client**: Acknowledged, ordering of transactions doesn't impact the correct functioning of bridged World IDs. The [`signup-sequencer`](https://github.com/worldcoin/signup-sequencer/) is the one that takes care providing roots against the latest root on the L2, which solves the edge case mentioned above.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully