Skip to content
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
49 changes: 28 additions & 21 deletions src/contracts/multichain/OperatorTableUpdater.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ contract OperatorTableUpdater is Initializable, OwnableUpgradeable, OperatorTabl
bytes calldata proof,
bytes calldata operatorTableBytes
) external {
(OperatorSet memory operatorSet, CurveType curveType, OperatorSetConfig memory operatorSetConfig) =
_getOperatorTableInfo(operatorTableBytes);
(
OperatorSet memory operatorSet,
CurveType curveType,
OperatorSetConfig memory operatorSetConfig,
bytes memory operatorTableInfo
) = _decodeOperatorTableBytes(operatorTableBytes);

// Check that the `referenceTimestamp` is greater than the latest reference timestamp
require(
Expand All @@ -116,11 +120,11 @@ contract OperatorTableUpdater is Initializable, OwnableUpgradeable, OperatorTabl
// Update the operator table
if (curveType == CurveType.BN254) {
bn254CertificateVerifier.updateOperatorTable(
operatorSet, referenceTimestamp, _getBN254OperatorSetInfo(operatorTableBytes), operatorSetConfig
operatorSet, referenceTimestamp, _getBN254OperatorInfo(operatorTableInfo), operatorSetConfig
);
} else if (curveType == CurveType.ECDSA) {
ecdsaCertificateVerifier.updateOperatorTable(
operatorSet, referenceTimestamp, _getECDSAOperatorSetInfo(operatorTableBytes), operatorSetConfig
operatorSet, referenceTimestamp, _getECDSAOperatorInfo(operatorTableInfo), operatorSetConfig
);
} else {
revert InvalidCurveType();
Expand Down Expand Up @@ -254,40 +258,43 @@ contract OperatorTableUpdater is Initializable, OwnableUpgradeable, OperatorTabl
* @return operatorSet The operator set
* @return curveType The curve type
* @return operatorSetInfo The operator set info
* @dev Does NOT return the operatorInfo, as that is dependent on the curve type, see `_getBN254OperatorSetInfo` and `_getECDSAOperatorSetInfo`
* @return operatorTableInfo The operator table info. This is encoded as a bytes array, and its value is dependent on the curve type, see `_getBN254OperatorInfo` and `_getECDSAOperatorInfo`
*/
function _getOperatorTableInfo(
function _decodeOperatorTableBytes(
bytes calldata operatorTable
)
internal
pure
returns (OperatorSet memory operatorSet, CurveType curveType, OperatorSetConfig memory operatorSetInfo)
returns (
OperatorSet memory operatorSet,
CurveType curveType,
OperatorSetConfig memory operatorSetInfo,
bytes memory operatorTableInfo
)
{
(operatorSet, curveType, operatorSetInfo) =
abi.decode(operatorTable, (OperatorSet, CurveType, OperatorSetConfig));
(operatorSet, curveType, operatorSetInfo, operatorTableInfo) =
abi.decode(operatorTable, (OperatorSet, CurveType, OperatorSetConfig, bytes));
}

/**
* @notice Gets the BN254 operator set info from a bytes array
* @param operatorTable The bytes containing the operator table info
* @param BN254OperatorSetInfoBytes The bytes containing the operator set info
* @return operatorSetInfo The BN254 operator set info
*/
function _getBN254OperatorSetInfo(
bytes calldata operatorTable
) internal pure returns (BN254OperatorSetInfo memory operatorSetInfo) {
(,,, operatorSetInfo) =
abi.decode(operatorTable, (OperatorSet, CurveType, OperatorSetConfig, BN254OperatorSetInfo));
function _getBN254OperatorInfo(
bytes memory BN254OperatorSetInfoBytes
) internal pure returns (BN254OperatorSetInfo memory) {
return abi.decode(BN254OperatorSetInfoBytes, (BN254OperatorSetInfo));
}

/**
* @notice Gets the ECDSA operator set info from a bytes array
* @param operatorTable The bytes containing the operator table info
* @param ECDSAOperatorInfoBytes The bytes containing the operator table info
* @return operatorSetInfo The ECDSA operator set info
*/
function _getECDSAOperatorSetInfo(
bytes calldata operatorTable
) internal pure returns (ECDSAOperatorInfo[] memory operatorSetInfo) {
(,,, operatorSetInfo) =
abi.decode(operatorTable, (OperatorSet, CurveType, OperatorSetConfig, ECDSAOperatorInfo[]));
function _getECDSAOperatorInfo(
bytes memory ECDSAOperatorInfoBytes
) internal pure returns (ECDSAOperatorInfo[] memory) {
return abi.decode(ECDSAOperatorInfoBytes, (ECDSAOperatorInfo[]));
}
}
14 changes: 10 additions & 4 deletions src/test/unit/OperatorTableUpdaterUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ contract OperatorTableUpdaterUnitTests_updateOperatorTable_BN254 is OperatorTabl
function testFuzz_BN254_correctness(Randomness r) public rand(r) {
// Generate random operatorSetInfo and operatorSetConfig
BN254OperatorSetInfo memory operatorSetInfo = _generateRandomBN254OperatorSetInfo(r);
// Encode the operatorSetInfo as bytes, as the CrossChainRegistry expects the operatorTable to be encoded as a bytes array;
bytes memory operatorSetInfoBytes = abi.encode(operatorSetInfo);
OperatorSetConfig memory operatorSetConfig = _generateRandomOperatorSetConfig(r);
bytes memory operatorTable = abi.encode(defaultOperatorSet, CurveType.BN254, operatorSetConfig, operatorSetInfo);
bytes memory operatorTable = abi.encode(defaultOperatorSet, CurveType.BN254, operatorSetConfig, operatorSetInfoBytes);
bytes32 operatorSetLeafHash = keccak256(operatorTable);

// Include the operatorSetInfo and operatorSetConfig in the global table root & set it
Expand Down Expand Up @@ -314,8 +316,10 @@ contract OperatorTableUpdaterUnitTests_updateOperatorTable_ECDSA is OperatorTabl
function testFuzz_ECDSA_correctness(Randomness r) public rand(r) {
// Generate random operatorSetInfo and operatorSetConfig
ECDSAOperatorInfo[] memory operatorInfos = _generateRandomECDSAOperatorInfos(r);
// Encode the operatorInfos as bytes, as the CrossChainRegistry expects the operatorTable to be encoded as a bytes array;
bytes memory operatorInfosBytes = abi.encode(operatorInfos);
OperatorSetConfig memory operatorSetConfig = _generateRandomOperatorSetConfig(r);
bytes memory operatorTable = abi.encode(defaultOperatorSet, CurveType.ECDSA, operatorSetConfig, operatorInfos);
bytes memory operatorTable = abi.encode(defaultOperatorSet, CurveType.ECDSA, operatorSetConfig, operatorInfosBytes);
bytes32 operatorSetLeafHash = keccak256(operatorTable);

// Include the operatorInfos and operatorSetConfig in the global table root & set it
Expand Down Expand Up @@ -346,16 +350,18 @@ contract OperatorTableUpdaterUnitTests_multipleCurveTypes is OperatorTableUpdate
bytes memory bn254OperatorTable;
{
BN254OperatorSetInfo memory bn254OperatorSetInfo = _generateRandomBN254OperatorSetInfo(r);
bytes memory bn254OperatorSetInfoBytes = abi.encode(bn254OperatorSetInfo);
OperatorSetConfig memory bn254OperatorSetConfig = _generateRandomOperatorSetConfig(r);
bn254OperatorTable = abi.encode(defaultOperatorSet, CurveType.BN254, bn254OperatorSetConfig, bn254OperatorSetInfo);
bn254OperatorTable = abi.encode(defaultOperatorSet, CurveType.BN254, bn254OperatorSetConfig, bn254OperatorSetInfoBytes);
}

// Generate random ECDSA operatorInfos and operatorSetConfig
bytes memory ecdsaOperatorTable;
{
ECDSAOperatorInfo[] memory ecdsaOperatorInfos = _generateRandomECDSAOperatorInfos(r);
bytes memory ecdsaOperatorInfosBytes = abi.encode(ecdsaOperatorInfos);
OperatorSetConfig memory ecdsaOperatorSetConfig = _generateRandomOperatorSetConfig(r);
ecdsaOperatorTable = abi.encode(defaultOperatorSet, CurveType.ECDSA, ecdsaOperatorSetConfig, ecdsaOperatorInfos);
ecdsaOperatorTable = abi.encode(defaultOperatorSet, CurveType.ECDSA, ecdsaOperatorSetConfig, ecdsaOperatorInfosBytes);
}

// Include the operatorInfos and operatorSetConfig in the global table root & set it
Expand Down