Skip to content

Commit

Permalink
fix(contracts): Require contract addresses to be non-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Xearty authored and Dimo99 committed Sep 26, 2024
1 parent 3b26011 commit 56c80f5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
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

0 comments on commit 56c80f5

Please sign in to comment.