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

add zero address checking #327

Merged
merged 4 commits into from
Feb 6, 2025
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
10 changes: 10 additions & 0 deletions contracts/cross-chain/CrossChainProofValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract CrossChainProofValidator is Ownable, EIP712, ICrossChainProofValidator {
using ECDSA for bytes32;

error OracleSigningAddressShouldNotBeZero();

bytes32 public constant TYPE_HASH =
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
Expand All @@ -35,11 +37,18 @@ contract CrossChainProofValidator is Ownable, EIP712, ICrossChainProofValidator

address private _oracleSigningAddress;

function _checkOracleSigningAddress(address oracleSigningAddress) internal pure {
if (oracleSigningAddress == address(0)) {
revert OracleSigningAddressShouldNotBeZero();
}
}

constructor(
string memory domainName,
string memory signatureVersion,
address oracleSigningAddress
) EIP712(domainName, signatureVersion) Ownable(msg.sender) {
_checkOracleSigningAddress(oracleSigningAddress);
bytes32 hashedName = keccak256(bytes(domainName));
bytes32 hashedVersion = keccak256(bytes(signatureVersion));
uint256 chainId = 0;
Expand All @@ -63,6 +72,7 @@ contract CrossChainProofValidator is Ownable, EIP712, ICrossChainProofValidator
* @param oracleSigningAddress The new oracle signing address
**/
function setOracleSigningAddress(address oracleSigningAddress) public onlyOwner {
_checkOracleSigningAddress(oracleSigningAddress);
_oracleSigningAddress = oracleSigningAddress;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@iden3/contracts",
"description": "Smart Contract library for Solidity",
"version": "2.5.6",
"version": "2.5.7",
"files": [
"**/*.sol",
"/build/contracts/*.json",
Expand Down
50 changes: 49 additions & 1 deletion test/cross-chain/cross-chain-proof-validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from "../../helpers/helperUtils";
import {
GlobalStateMessage,
IdentityStateMessage,
Expand All @@ -6,7 +7,7 @@ import {
} from "../utils/packData";
import { expect } from "chai";
import { DeployHelper } from "../../helpers/DeployHelper";
import { Contract } from "ethers";
import { Contract, ZeroAddress } from "ethers";
import { ethers } from "hardhat";
import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers";

Expand Down Expand Up @@ -180,3 +181,50 @@ describe("State Cross Chain", function () {
);
});
});

describe("Oracle Signing Address Validation", function () {
let CrossChainProofValidatorFactory;
let crossChainProofValidator;
let otherAccount;
const oracleSigningAddress = "0x1234567890123456789012345678901234567890";
const contractName = "CrossChainProofValidator";

before(async function () {
[otherAccount] = await ethers.getSigners();
CrossChainProofValidatorFactory = await ethers.getContractFactory(contractName);
});

it("should revert when deploying with zero oracle signing address", async function () {
await expect(
CrossChainProofValidatorFactory.deploy("StateInfo", "1", ZeroAddress),
).to.be.revertedWithCustomError(
CrossChainProofValidatorFactory,
"OracleSigningAddressShouldNotBeZero",
);
});

it("should deploy with correct parameters", async function () {
crossChainProofValidator = await CrossChainProofValidatorFactory.deploy(
"StateInfo",
"1",
oracleSigningAddress,
);
await crossChainProofValidator.waitForDeployment();
Logger.success(`${contractName} deployed to: ${await crossChainProofValidator.getAddress()}`);
expect(await crossChainProofValidator.getOracleSigningAddress()).to.equal(oracleSigningAddress);
});

it("should set a new oracle signing address", async function () {
await crossChainProofValidator.setOracleSigningAddress(otherAccount.address);
expect(await crossChainProofValidator.getOracleSigningAddress()).to.equal(otherAccount.address);
});

it("should revert when setting oracle signing address to zero", async function () {
await expect(
crossChainProofValidator.setOracleSigningAddress(ZeroAddress),
).to.be.revertedWithCustomError(
crossChainProofValidator,
"OracleSigningAddressShouldNotBeZero",
);
});
});