From ac84ae1bf071d62caa6526283ceb772b651b8f35 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Fri, 29 Mar 2024 15:34:11 -0700 Subject: [PATCH 1/9] add next authority set check --- contracts/src/VectorX.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index a45ef73c..4a451c0a 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -309,6 +309,13 @@ contract VectorX is IVectorX, TimelockedUpgradeable { revert AuthoritySetNotFound(); } + bytes32 nextAuthoritySetHash = authoritySetIdToHash[ + _currentAuthoritySetId + 1 + ]; + if (nextAuthoritySetHash != bytes32(0)) { + revert NextAuthoritySetExists(); + } + bytes memory input = abi.encodePacked( _currentAuthoritySetId, currentAuthoritySetHash From a229a8fce031b7037988ed8fad3c853f4f22248e Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Mon, 1 Apr 2024 12:39:15 -0700 Subject: [PATCH 2/9] fix current authority set id issue --- contracts/src/VectorX.sol | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index 4a451c0a..c88f653d 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -18,6 +18,10 @@ contract VectorX is IVectorX, TimelockedUpgradeable { /// @notice The latest block that has been committed. uint32 public latestBlock; + /// @notice The current authority set id. When a header range is committed, the current authority set id + /// is updated to the authority set id of the header range. + uint64 public currentAuthoritySetId; + /// @notice The function for requesting a header range. bytes32 public headerRangeFunctionId; @@ -60,6 +64,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { blockHeightToHeaderHash[_params.height] = _params.header; authoritySetIdToHash[_params.authoritySetId] = _params.authoritySetHash; + currentAuthoritySetId = _params.authoritySetId; latestBlock = _params.height; rotateFunctionId = _params.rotateFunctionId; @@ -215,6 +220,14 @@ contract VectorX is IVectorX, TimelockedUpgradeable { revert AuthoritySetNotFound(); } + if (_authoritySetId < currentAuthoritySetId) { + revert OldAuthoritySetId(); + } + + if (_authoritySetId > currentAuthoritySetId) { + currentAuthoritySetId = _authoritySetId; + } + require(_targetBlock > latestBlock); bytes memory input = abi.encodePacked( @@ -256,31 +269,31 @@ contract VectorX is IVectorX, TimelockedUpgradeable { latestBlock = _targetBlock; } - /// @notice Requests a rotate to the next authority set. - /// @param _currentAuthoritySetId The authority set id of the current authority set. - function requestRotate(uint64 _currentAuthoritySetId) external payable { - bytes32 currentAuthoritySetHash = authoritySetIdToHash[ - _currentAuthoritySetId + /// @notice Requests a rotate to a next authority set after the latest authority set in the contract. + /// @param _latestAuthoritySetId The authority set id of the latest authority set stored in the contract. + function requestRotate(uint64 _latestAuthoritySetId) external payable { + bytes32 latestAuthoritySetHash = authoritySetIdToHash[ + _latestAuthoritySetId ]; - if (currentAuthoritySetHash == bytes32(0)) { + if (latestAuthoritySetHash == bytes32(0)) { revert AuthoritySetNotFound(); } - bytes32 nextAuthoritySetHash = authoritySetIdToHash[ - _currentAuthoritySetId + 1 + bytes32 newAuthoritySetHash = authoritySetIdToHash[ + _latestAuthoritySetId + 1 ]; - if (nextAuthoritySetHash != bytes32(0)) { + if (newAuthoritySetHash != bytes32(0)) { revert NextAuthoritySetExists(); } bytes memory input = abi.encodePacked( - _currentAuthoritySetId, - currentAuthoritySetHash + latestAuthoritySetHash, + _latestAuthoritySetId ); bytes memory data = abi.encodeWithSelector( this.rotate.selector, - _currentAuthoritySetId + _latestAuthoritySetId ); ISuccinctGateway(gateway).requestCall{value: msg.value}( @@ -291,7 +304,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { 500000 ); - emit RotateRequested(_currentAuthoritySetId, currentAuthoritySetHash); + emit RotateRequested(_latestAuthoritySetId, latestAuthoritySetHash); } /// @notice Adds the authority set hash for the next authority set id. From a23361df847d1b92b6562d19c9283285408c2842 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Mon, 1 Apr 2024 12:39:45 -0700 Subject: [PATCH 3/9] add error --- contracts/src/interfaces/IVectorX.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/src/interfaces/IVectorX.sol b/contracts/src/interfaces/IVectorX.sol index 6802e7b7..4f64c486 100644 --- a/contracts/src/interfaces/IVectorX.sol +++ b/contracts/src/interfaces/IVectorX.sol @@ -49,4 +49,7 @@ interface IVectorX { /// @notice Authority set not found. error AuthoritySetNotFound(); + + /// @notice The authority set id is older than the authority set id of the latest commitHeaderRange. + error OldAuthoritySetId(); } From 8f7002e78b908dac542f1fc89544d7e7f53d7870 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Mon, 1 Apr 2024 14:55:48 -0700 Subject: [PATCH 4/9] mv fix to another pr --- contracts/src/VectorX.sol | 7 ------- 1 file changed, 7 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index c88f653d..4aee382c 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -322,13 +322,6 @@ contract VectorX is IVectorX, TimelockedUpgradeable { revert AuthoritySetNotFound(); } - bytes32 nextAuthoritySetHash = authoritySetIdToHash[ - _currentAuthoritySetId + 1 - ]; - if (nextAuthoritySetHash != bytes32(0)) { - revert NextAuthoritySetExists(); - } - bytes memory input = abi.encodePacked( _currentAuthoritySetId, currentAuthoritySetHash From 8db0ef7bd527b565f2e8c1306428493472337bc1 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 3 Apr 2024 16:09:16 -0700 Subject: [PATCH 5/9] revert some changes --- contracts/src/VectorX.sol | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index 4aee382c..8aa3d874 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -269,42 +269,39 @@ contract VectorX is IVectorX, TimelockedUpgradeable { latestBlock = _targetBlock; } - /// @notice Requests a rotate to a next authority set after the latest authority set in the contract. - /// @param _latestAuthoritySetId The authority set id of the latest authority set stored in the contract. - function requestRotate(uint64 _latestAuthoritySetId) external payable { - bytes32 latestAuthoritySetHash = authoritySetIdToHash[ - _latestAuthoritySetId + /// @notice Requests a rotate to the next authority set. + /// @param _currentAuthoritySetId The authority set id of the current authority set. + function requestRotate(uint64 _currentAuthoritySetId) external payable { + bytes32 currentAuthoritySetHash = authoritySetIdToHash[ + _currentAuthoritySetId ]; - if (latestAuthoritySetHash == bytes32(0)) { + if (currentAuthoritySetHash == bytes32(0)) { revert AuthoritySetNotFound(); } - bytes32 newAuthoritySetHash = authoritySetIdToHash[ - _latestAuthoritySetId + 1 + bytes32 nextAuthoritySetHash = authoritySetIdToHash[ + _currentAuthoritySetId + 1 ]; - if (newAuthoritySetHash != bytes32(0)) { + if (nextAuthoritySetHash != bytes32(0)) { revert NextAuthoritySetExists(); } bytes memory input = abi.encodePacked( - latestAuthoritySetHash, - _latestAuthoritySetId + _currentAuthoritySetId, + currentAuthoritySetHash ); bytes memory data = abi.encodeWithSelector( this.rotate.selector, - _latestAuthoritySetId + _currentAuthoritySetId ); ISuccinctGateway(gateway).requestCall{value: msg.value}( - rotateFunctionId, - input, - address(this), - data, + @@ -291,7 +304,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { 500000 ); - emit RotateRequested(_latestAuthoritySetId, latestAuthoritySetHash); + emit RotateRequested(_currentAuthoritySetId, currentAuthoritySetHash); } /// @notice Adds the authority set hash for the next authority set id. From 738d7334e45a0029413586ab415ecddece77e55d Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 3 Apr 2024 16:09:30 -0700 Subject: [PATCH 6/9] fix --- contracts/src/VectorX.sol | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index 8aa3d874..3ee5fe78 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -296,10 +296,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { _currentAuthoritySetId ); - ISuccinctGateway(gateway).requestCall{value: msg.value}( - @@ -291,7 +304,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { - 500000 - ); + ISuccinctGateway(gateway).requestCall{value: msg.value}(500000); emit RotateRequested(_currentAuthoritySetId, currentAuthoritySetHash); } From df9ce4ceb54baab181a6f80076aa7943d311d6b0 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 3 Apr 2024 16:09:49 -0700 Subject: [PATCH 7/9] fix --- contracts/src/VectorX.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index 3ee5fe78..a0873209 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -296,7 +296,13 @@ contract VectorX is IVectorX, TimelockedUpgradeable { _currentAuthoritySetId ); - ISuccinctGateway(gateway).requestCall{value: msg.value}(500000); + ISuccinctGateway(gateway).requestCall{value: msg.value}( + rotateFunctionId, + input, + address(this), + data, + 500000 + ); emit RotateRequested(_currentAuthoritySetId, currentAuthoritySetHash); } From 3ee82e38fe6f006ea841a787a906288ca698230d Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 3 Apr 2024 16:10:58 -0700 Subject: [PATCH 8/9] fix --- contracts/src/VectorX.sol | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index a0873209..dc3a8765 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -18,9 +18,8 @@ contract VectorX is IVectorX, TimelockedUpgradeable { /// @notice The latest block that has been committed. uint32 public latestBlock; - /// @notice The current authority set id. When a header range is committed, the current authority set id - /// is updated to the authority set id of the header range. - uint64 public currentAuthoritySetId; + /// @notice The latest authority set id used in commitHeaderRange. + uint64 public latestAuthoritySetId; /// @notice The function for requesting a header range. bytes32 public headerRangeFunctionId; @@ -64,7 +63,7 @@ contract VectorX is IVectorX, TimelockedUpgradeable { blockHeightToHeaderHash[_params.height] = _params.header; authoritySetIdToHash[_params.authoritySetId] = _params.authoritySetHash; - currentAuthoritySetId = _params.authoritySetId; + latestAuthoritySetId = _params.authoritySetId; latestBlock = _params.height; rotateFunctionId = _params.rotateFunctionId; @@ -220,12 +219,12 @@ contract VectorX is IVectorX, TimelockedUpgradeable { revert AuthoritySetNotFound(); } - if (_authoritySetId < currentAuthoritySetId) { + if (_authoritySetId < latestAuthoritySetId) { revert OldAuthoritySetId(); } - if (_authoritySetId > currentAuthoritySetId) { - currentAuthoritySetId = _authoritySetId; + if (_authoritySetId > latestAuthoritySetId) { + latestAuthoritySetId = _authoritySetId; } require(_targetBlock > latestBlock); From 9d0c84ee89b1e6be27a14eae9be547fccf6526f5 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 3 Apr 2024 18:08:56 -0700 Subject: [PATCH 9/9] updateBlockRangeData and updateGenesisState need to update latestAuthoritySetId --- contracts/src/VectorX.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contracts/src/VectorX.sol b/contracts/src/VectorX.sol index dc3a8765..75322791 100644 --- a/contracts/src/VectorX.sol +++ b/contracts/src/VectorX.sol @@ -99,8 +99,10 @@ contract VectorX is IVectorX, TimelockedUpgradeable { bytes32 _authoritySetHash ) external onlyGuardian { blockHeightToHeaderHash[_height] = _header; - authoritySetIdToHash[_authoritySetId] = _authoritySetHash; latestBlock = _height; + + authoritySetIdToHash[_authoritySetId] = _authoritySetHash; + latestAuthoritySetId = _authoritySetId; } /// @notice Force update the data & state commitments for a range of blocks. @@ -140,8 +142,10 @@ contract VectorX is IVectorX, TimelockedUpgradeable { _stateRootCommitments[i] ); } - authoritySetIdToHash[_endAuthoritySetId] = _endAuthoritySetHash; latestBlock = _endBlocks[_endBlocks.length - 1]; + + authoritySetIdToHash[_endAuthoritySetId] = _endAuthoritySetHash; + latestAuthoritySetId = _endAuthoritySetId; } /// @notice Request a header update and data commitment from range (latestBlock, requestedBlock].