Skip to content

Commit

Permalink
used worldid bridge interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvolear committed Mar 19, 2024
1 parent 1808165 commit 8787285
Show file tree
Hide file tree
Showing 17 changed files with 2,208 additions and 1,528 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint-fix && git add -u
55 changes: 19 additions & 36 deletions contracts/IdentityManager.sol
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
pragma solidity ^0.8.20;

import "@rarimo/evm-bridge-contracts/utils/Signers.sol";
import {Signers} from "@rarimo/evm-bridge-contracts/utils/Signers.sol";

import "./interfaces/IIdentityManager.sol";
import {WorldIDBridge} from "./vendor/worldcoin/world-id-state-bridge/WorldIDBridge.sol";

import {IIdentityManager} from "./interfaces/IIdentityManager.sol";

/**
* @title Rarimo identity manager contract that operates and accepts states from WorldID
*/
contract IdentityManager is IIdentityManager, Signers {
uint256 public constant ROOT_EXPIRATION_TIME = 1 hours;

contract IdentityManager is IIdentityManager, WorldIDBridge, Signers {
address public sourceStateContract;

uint256 internal _latestRoot;
uint256 internal _latestTimestamp;

mapping(uint256 => RootData) internal _roots;

/**
*
* @notice Init function
* @param signer_ the Rarimo TSS signer
* @param sourceStateContract_ the WorldID state contract address on mainnet
* @param chainName_ the chain name the contract is being deployed to
*/
function __IdentityManager_init(
uint8 treeDepth_,
address semaphoreVerifier_,
address signer_,
address sourceStateContract_,
string calldata chainName_
) external initializer {
__Signers_init(signer_, chainName_);
__WorldIDBridge_init(treeDepth_, semaphoreVerifier_);
__Signers_init(signer_, address(0), chainName_);

sourceStateContract = sourceStateContract_;
}
Expand All @@ -46,7 +49,7 @@ contract IdentityManager is IIdentityManager, Signers {
uint256 postRoot_,
uint256 replacedAt_,
bytes calldata proof_
) external override {
) external {
RootData storage _prevRoot = _roots[prevRoot_];

require(prevRoot_ != postRoot_, "IdentityManager: same prev and post roots");
Expand All @@ -61,7 +64,7 @@ contract IdentityManager is IIdentityManager, Signers {
if (replacedAt_ >= _latestTimestamp) {
_roots[_latestRoot].replacedBy = postRoot_;

_latestRoot = postRoot_;
_receiveRoot(postRoot_, replacedAt_);
_latestTimestamp = replacedAt_;
}

Expand All @@ -72,29 +75,18 @@ contract IdentityManager is IIdentityManager, Signers {
}

/**
* @notice The function to check whether the root is expired
* @param root_ the root to check
* @return true if root is expired
* @notice The function to update the root expiry time
* @param expiryTime_ new history root expiry time
*/
function isExpiredRoot(uint256 root_) public view override returns (bool) {
if (!rootExists(root_)) {
return true;
}

if (isLatestRoot(root_)) {
return false;
}

return block.timestamp > _roots[root_].replacedAt + ROOT_EXPIRATION_TIME;
}
function setRootHistoryExpiry(uint256 expiryTime_) public override {}

/**
* @notice The function to check whether the root exists
* @param root_ the root to check
* @return true if root exists
*/
function rootExists(uint256 root_) public view override returns (bool) {
return _roots[root_].replacedAt != 0 || isLatestRoot(root_);
return rootHistory[root_] != 0;
}

/**
Expand All @@ -103,16 +95,7 @@ contract IdentityManager is IIdentityManager, Signers {
* @return true if the root is the latest root
*/
function isLatestRoot(uint256 root) public view override returns (bool) {
return _latestRoot == root;
}

/**
* @notice The function to get the latest root
* @return the latest root
* @return the transition timestamp
*/
function getLatestRoot() external view override returns (uint256, uint256) {
return (_latestRoot, _latestTimestamp);
return latestRoot() == root;
}

/**
Expand All @@ -128,7 +111,7 @@ contract IdentityManager is IIdentityManager, Signers {
replacedBy: _root.replacedBy,
replacedAt: _root.replacedAt,
isLatest: isLatestRoot(root_),
isExpired: isExpiredRoot(root_)
isValid: isValidRoot(root_)
});
}

Expand Down
64 changes: 0 additions & 64 deletions contracts/Verifier.sol

This file was deleted.

26 changes: 2 additions & 24 deletions contracts/interfaces/IIdentityManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ interface IIdentityManager {
/// @param replacedAt the timestamp when this root has been replaced
/// @param replacedBy the root by which this root has been replaced
/// @param isCurrent the boolean flag indicating whether the queried root is the latest one
/// @param isExpired the boolean flag indicating whether the root is expired
/// @param isValid the boolean flag indicating whether the root is valid (not expired)
struct RootInfo {
uint256 replacedBy;
uint256 replacedAt;
bool isLatest;
bool isExpired;
bool isValid;
}

/// @notice The event that is emitted when the Merkle root history is updated
Expand All @@ -39,23 +39,6 @@ interface IIdentityManager {
uint256 latestRoot
);

/// @notice The function that updates the Merkle root history
/// @param prevRoot_ the root that has been replaced
/// @param postRoot_ the root by which prevRoot root has been replaced
/// @param replacedAt_ the timestamp when the prevRoot has been replaced
/// @param proof_ the proof of entry of the relevant leaf into Merkle Tree together with signature from Rarimo validators
function signedTransitRoot(
uint256 prevRoot_,
uint256 postRoot_,
uint256 replacedAt_,
bytes calldata proof_
) external;

/// @notice The function that checks whether the root is expired
/// @param root_ the root to be checked
/// @return isExpired_ the boolean flag indicating whether the `root_` is expired
function isExpiredRoot(uint256 root_) external view returns (bool isExpired_);

/// @notice The function that checks whether the root exists
/// @param root_ the root to be checked
/// @return doesExist_ the boolean flag indicating whether the `root_` exists
Expand All @@ -66,11 +49,6 @@ interface IIdentityManager {
/// @return isLatest_ the boolean flag indicating whether the `root_` is the latest root
function isLatestRoot(uint256 root_) external view returns (bool isLatest_);

/// @notice The function that returns the information about the latest recorded root
/// @return latestRoot_ the latest root
/// @return latestTimestamp_ the timestamp when the `latestRoot_` replaced the previous root
function getLatestRoot() external view returns (uint256 latestRoot_, uint256 latestTimestamp_);

/// @notice The function that returns the information about any root
/// @param root_ the root to be checked
/// @return rootInfo_ the information about the `root_`
Expand Down
23 changes: 0 additions & 23 deletions contracts/interfaces/IVerifier.sol

This file was deleted.

6 changes: 3 additions & 3 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/worldid-integration-contracts",
"version": "1.0.1",
"version": "1.1.0",
"license": "MIT",
"author": "Global Web3 Sandbox Ltd",
"description": "WorldID <> Rarimo",
Expand All @@ -14,7 +14,7 @@
"!mock/**/*"
],
"dependencies": {
"@openzeppelin/contracts-upgradeable": "5.0.0",
"@rarimo/evm-bridge-contracts": "1.0.0"
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@rarimo/evm-bridge-contracts": "1.0.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {ISemaphoreVerifier} from "./interfaces/ISemaphoreVerifier.sol";

pragma solidity 0.8.20;
pragma solidity ^0.8.20;

/// @title Groth16 verifier template.
/// @author Remco Bloemen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
pragma solidity ^0.8.20;

/// @title Tree Verifier Interface
/// @author Worldcoin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.15;

/// @title Semaphore tree depth validator
/// @author Worldcoin
library SemaphoreTreeDepthValidator {
/// @notice Checks if the provided `treeDepth` is among supported depths.
///
/// @param treeDepth The tree depth to validate.
/// @return supportedDepth Returns `true` if `treeDepth` is between 16 and 32
function validate(uint8 treeDepth) internal pure returns (bool supportedDepth) {
uint8 minDepth = 16;
uint8 maxDepth = 32;
return treeDepth >= minDepth && treeDepth <= maxDepth;
}
}
Loading

0 comments on commit 8787285

Please sign in to comment.