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

Require contract addresses to be non-zero #356

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "ZeroAddressError",
"type": "error"
},
{
"anonymous": false,
"inputs": [
Expand Down
5 changes: 5 additions & 0 deletions beacon-light-client/solidity/contracts/Errors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.19;

/// @dev Proxy contract address is zero
error ZeroAddressError();
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.20;

import {PlonkVerifier} from './verifier.sol';
import {IBalanceVerifier} from './interfaces/IBalanceVerifierDiva.sol';
import {ZeroAddressError} from '../Errors.sol';
import '@openzeppelin/contracts/access/Ownable.sol';

abstract contract BalanceVerifier is Ownable, IBalanceVerifier {
Expand All @@ -28,12 +29,19 @@ abstract contract BalanceVerifier is Ownable, IBalanceVerifier {
address _verifier,
address _owner
) Ownable(_owner) {
if (_verifier == address(0)) {
revert ZeroAddressError();
}
verifier = _verifier;

VERIFIER_DIGEST = verifierDigest;
GENESIS_BLOCK_TIMESTAMP = genesisBlockTimestamp;
verifier = _verifier;
}

function setVerifier(address _verifier) external override onlyOwner {
if (_verifier == address(0)) {
revert ZeroAddressError();
}
verifier = _verifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
import {BalanceVerifier} from './BalanceVerifier.sol';
import {IBalanceVerifierDiva} from './interfaces/IBalanceVerifierDiva.sol';
import {IValidatorsAccumulator} from '../validators_accumulator/interfaces/IValidatorsAccumulator.sol';
import {ZeroAddressError} from '../Errors.sol';

contract BalanceVerifierDiva is BalanceVerifier, IBalanceVerifierDiva {
/// @notice The address of the validators accumulator contract.
Expand All @@ -18,6 +19,9 @@ contract BalanceVerifierDiva is BalanceVerifier, IBalanceVerifierDiva {
address _accumulator,
address _owner
) BalanceVerifier(verifierDigest, genesisBlockTimestamp, _verifier, _owner) {
if (_accumulator == address(0)) {
revert ZeroAddressError();
}
ACCUMULATOR = _accumulator;
}

Expand Down Expand Up @@ -80,6 +84,9 @@ contract BalanceVerifierDiva is BalanceVerifier, IBalanceVerifierDiva {
}

function setAccumulator(address _accumulator) external override onlyOwner {
if (_accumulator == address(0)) {
revert ZeroAddressError();
}
ACCUMULATOR = _accumulator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.18;

import {IDeposit} from './interfaces/IDeposit.sol';
import {IValidatorsAccumulator} from './interfaces/IValidatorsAccumulator.sol';
import {ZeroAddressError} from '../Errors.sol';

contract ValidatorsAccumulator is IValidatorsAccumulator {
// The depth of the validator accumulator tree
Expand All @@ -21,6 +22,9 @@ contract ValidatorsAccumulator is IValidatorsAccumulator {
uint256[] internal blockNumbers;

constructor(address _depositAddress) {
if (_depositAddress == address(0)) {
revert ZeroAddressError();
}
depositAddress = _depositAddress;

// Compute hashes in empty Merkle tree
Expand Down