From 1fdefb2e821c97e7a64645c0ea8e22f20e28c2a7 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 17 Jan 2024 13:02:01 -0800 Subject: [PATCH] fix --- contracts/src/VectorX.sol | 64 ++++++++++----------------------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index c66fee51..ae59093b 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -24,22 +24,19 @@ contract VectorX is IVectorX, TimelockedUpgradeable { /// @notice The maximum header range that can be requested. uint32 public constant MAX_HEADER_RANGE = 256; - /// @notice The reset counter. - uint8 public resetCounter; - /// @notice Maps block height to the header hash of the block. - mapping(uint8 => mapping(uint32 => bytes32)) public blockHeightToHeaderHash; + mapping(uint32 => bytes32) public blockHeightToHeaderHash; /// @notice Maps authority set id to the authority set hash. - mapping(uint8 => mapping(uint64 => bytes32)) public authoritySetIdToHash; + mapping(uint64 => bytes32) public authoritySetIdToHash; /// @notice Maps block ranges to data commitments. Block ranges are stored as /// keccak256(abi.encode(startBlock, endBlock)). - mapping(uint8 => mapping(bytes32 => bytes32)) public dataRootCommitments; + mapping(bytes32 => bytes32) public dataRootCommitments; /// @notice Maps block ranges to state commitments. Block ranges are stored as /// keccak256(abi.encode(startBlock, endBlock)). - mapping(uint8 => mapping(bytes32 => bytes32)) public stateRootCommitments; + mapping(bytes32 => bytes32) public stateRootCommitments; struct InitParameters { address guardian; @@ -59,27 +56,8 @@ contract VectorX is IVectorX, TimelockedUpgradeable { gateway = _params.gateway; - resetCounter = 0; - - blockHeightToHeaderHash[resetCounter][_params.height] = _params.header; - authoritySetIdToHash[resetCounter][_params.authoritySetId] = _params - .authoritySetHash; - latestBlock = _params.height; - - rotateFunctionId = _params.rotateFunctionId; - headerRangeFunctionId = _params.headerRangeFunctionId; - } - - /// @notice Update the address of the gateway contract. - function reinitializeContract( - InitParameters calldata _params - ) public onlyGuardian { - // Reset all metadata of this contract. - resetCounter++; - - blockHeightToHeaderHash[resetCounter][_params.height] = _params.header; - authoritySetIdToHash[resetCounter][_params.authoritySetId] = _params - .authoritySetHash; + blockHeightToHeaderHash[_params.height] = _params.header; + authoritySetIdToHash[_params.authoritySetId] = _params.authoritySetHash; latestBlock = _params.height; rotateFunctionId = _params.rotateFunctionId; @@ -115,17 +93,13 @@ contract VectorX is IVectorX, TimelockedUpgradeable { uint64 _authoritySetId, uint32 _requestedBlock ) external payable { - bytes32 trustedHeader = blockHeightToHeaderHash[resetCounter][ - _trustedBlock - ]; + bytes32 trustedHeader = blockHeightToHeaderHash[_trustedBlock]; if (trustedHeader == bytes32(0)) { revert("Trusted header not found"); } // Note: In the case that the trusted block is an epoch end block, the authority set id will // be the authority set id of the next epoch. - bytes32 authoritySetHash = authoritySetIdToHash[resetCounter][ - _authoritySetId - ]; + bytes32 authoritySetHash = authoritySetIdToHash[_authoritySetId]; if (authoritySetHash == bytes32(0)) { revert("Authority set hash not found"); } @@ -176,15 +150,11 @@ contract VectorX is IVectorX, TimelockedUpgradeable { uint64 _authoritySetId, uint32 _targetBlock ) external { - bytes32 trustedHeader = blockHeightToHeaderHash[resetCounter][ - _trustedBlock - ]; + bytes32 trustedHeader = blockHeightToHeaderHash[_trustedBlock]; if (trustedHeader == bytes32(0)) { revert("Trusted header not found"); } - bytes32 authoritySetHash = authoritySetIdToHash[resetCounter][ - _authoritySetId - ]; + bytes32 authoritySetHash = authoritySetIdToHash[_authoritySetId]; if (authoritySetHash == bytes32(0)) { revert("Authority set hash not found"); } @@ -213,12 +183,12 @@ contract VectorX is IVectorX, TimelockedUpgradeable { bytes32 dataRootCommitment ) = abi.decode(output, (bytes32, bytes32, bytes32)); - blockHeightToHeaderHash[resetCounter][_targetBlock] = targetHeaderHash; + blockHeightToHeaderHash[_targetBlock] = targetHeaderHash; // Store the data and state commitments for the range (trustedBlock, targetBlock]. bytes32 key = keccak256(abi.encode(_trustedBlock, _targetBlock)); - dataRootCommitments[resetCounter][key] = dataRootCommitment; - stateRootCommitments[resetCounter][key] = stateRootCommitment; + dataRootCommitments[key] = dataRootCommitment; + stateRootCommitments[key] = stateRootCommitment; // Update latest block. latestBlock = _targetBlock; @@ -246,7 +216,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { // This ensures we don't call rotate twice for the same epoch. require(_epochEndBlock >= latestBlock); - bytes32 currentAuthoritySetHash = authoritySetIdToHash[resetCounter][ + bytes32 currentAuthoritySetHash = authoritySetIdToHash[ _currentAuthoritySetId ]; if (currentAuthoritySetHash == bytes32(0)) { @@ -286,7 +256,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { uint64 _currentAuthoritySetId, uint32 _epochEndBlock ) external { - bytes32 currentAuthoritySetHash = authoritySetIdToHash[resetCounter][ + bytes32 currentAuthoritySetHash = authoritySetIdToHash[ _currentAuthoritySetId ]; // Note: Occurs if requesting a new authority set id that is not the next authority set id. @@ -308,9 +278,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { bytes32 newAuthoritySetHash = abi.decode(output, (bytes32)); // Store the authority set hash for the next authority set id. - authoritySetIdToHash[resetCounter][ - _currentAuthoritySetId + 1 - ] = newAuthoritySetHash; + authoritySetIdToHash[_currentAuthoritySetId + 1] = newAuthoritySetHash; emit AuthoritySetStored( _currentAuthoritySetId + 1,