Skip to content

AnchorBase2.sol

Implementation

Description

An abstract contract that requires child classes to implement appropriate verification and processes for deposits and withdrawals.

Variables

bridge

Type: public address

admin

Type: public address

handler

Type: public address

verifier

Type: public immutable IVerifier

denomination

Type: public immutable uint256

chainID

Type: public immutable uint256

nullifierHashes

Type: public mapping(bytes32 => bool)

commitments

Type: public mapping(bytes32 => bool)

Edge

Type: struct Edge { uint256 chainID; bytes32 root; uint256 height; }

edgeIndex

Type: mapping(uint256 => uint256)

edgeExistsForChain

Type: public mapping(uint256 => bool)

edgeList

Type: public Edge[]

neighborRoots

Type: public mapping(uint256 => mapping(uint32 => bytes32))

currentNeighborRootIndex

Type: public mapping(uint256 => uint32)

Constructor

Details

Signature

constructor( IVerifier _verifier, IHasher _hasher, uint256 _denomination, uint32 _merkleTreeHeight, uint256 _chainID ) MerkleTreePoseidon(_merkleTreeHeight, _hasher)

External Functions

Calls to deposits require a commitment, which is a hash of some secret values.

deposit

Details

Signature

deposit(bytes32 _commitment)

Requires

  • require(..., "commitment has been submitted")

Emits

Deposit

withdraw

Details

Signature

withdraw( bytes calldata _proof, bytes calldata _roots, bytes32 _nullifierHash, address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund )

Requires

  • require(_fee <= denomination)
  • require(..., "The note has already been spent")
  • require(..., "Cannot find your merkle root")
  • require(..., "Incorrect root array length")
  • require(..., "Neighbor root not found")
  • require(..., "Invalid withdraw proof")

Emits

Withdraw

View Functions

isSpent

Details

Signature

isSpent(bytes32 _nullifierHash) public view returns (bool)

isSpentArray

Details

Signature

isSpentArray(bytes32[] calldata _nullifierHashes) external view returns (bool[] memory spent)

getLatestNeighborRoots

Details

Signature

getLatestNeighborRoots() public view returns (bytes32[1] memory roots)

isKnownNeighborRoot

Details

Signature

isKnownNeighborRoot(uint256 neighborChainID, bytes32 _root) public view returns (bool)

Events

Deposit

Signature: Deposit(bytes32 indexed commitment, uint32 leafIndex, uint256 timestamp)

Withdraw

Signature: Withdrawal(address to, bytes32 nullifierHash, address indexed relayer, uint256 fee)

EdgeAddition

Signature: EdgeAddition(uint256 chainID, uint256 height, bytes32 merkleRoot)

EdgeUpdate

Signature: EdgeUpdate(uint256 chainID, uint256 height, bytes32 merkleRoot)

RootHistoryRecorded

Signature: RootHistoryRecorded(uint timestamp, bytes32[1] roots)

RootHistoryUpdate

Signature: RootHistoryUpdate(uint timestamp, bytes32[1] roots)