From ed86ea95f7462edd6a5eab0c1891b774e8d60b1b Mon Sep 17 00:00:00 2001 From: gator-boi Date: Fri, 8 Sep 2023 12:30:44 -0400 Subject: [PATCH] evm: make setGuardianSetHash public --- ethereum/contracts/Governance.sol | 2 +- ethereum/contracts/GovernanceStructs.sol | 4 ---- ethereum/contracts/Setters.sol | 17 +++++++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ethereum/contracts/Governance.sol b/ethereum/contracts/Governance.sol index adc81f1e3..a1818398f 100644 --- a/ethereum/contracts/Governance.sol +++ b/ethereum/contracts/Governance.sol @@ -108,7 +108,7 @@ abstract contract Governance is GovernanceStructs, Messages, Setters, ERC1967Upg storeGuardianSet(upgrade.newGuardianSet, upgrade.newGuardianSetIndex); // Store the guardian set hash - setGuardianSetHash(upgrade.newGuardianSetIndex, upgrade.newGuardianSetHash); + setGuardianSetHash(upgrade.newGuardianSetIndex); // Makes the new guardianSet effective updateGuardianSetIndex(upgrade.newGuardianSetIndex); diff --git a/ethereum/contracts/GovernanceStructs.sol b/ethereum/contracts/GovernanceStructs.sol index 29df2d841..612a4bfb4 100644 --- a/ethereum/contracts/GovernanceStructs.sol +++ b/ethereum/contracts/GovernanceStructs.sol @@ -31,7 +31,6 @@ contract GovernanceStructs { uint8 action; uint16 chain; - bytes32 newGuardianSetHash; Structs.GuardianSet newGuardianSet; uint32 newGuardianSetIndex; } @@ -103,9 +102,6 @@ contract GovernanceStructs { uint8 guardianLength = encodedUpgrade.toUint8(index); index += 1; - // Guardian set hash. - gsu.newGuardianSetHash = keccak256(encodedUpgrade.slice(index, guardianLength * 20 + 4)); - gsu.newGuardianSet = Structs.GuardianSet({ keys : new address[](guardianLength), expirationTime : 0 diff --git a/ethereum/contracts/Setters.sol b/ethereum/contracts/Setters.sol index d5bb65445..5be40a31a 100644 --- a/ethereum/contracts/Setters.sol +++ b/ethereum/contracts/Setters.sol @@ -56,7 +56,20 @@ contract Setters is State { _state.evmChainId = evmChainId; } - function setGuardianSetHash(uint32 index, bytes32 hash) internal { - _state.guardianSetHashes[index] = hash; + function setGuardianSetHash(uint32 index) public { + // Fetch the guardian set at the specified index. + Structs.GuardianSet memory guardianSet = _state.guardianSets[index]; + + uint256 guardianCount = guardianSet.keys.length; + bytes memory encodedGuardianSet; + for (uint256 i = 0; i < guardianCount;) { + encodedGuardianSet = abi.encodePacked(encodedGuardianSet, guardianSet.keys[i]); + unchecked { i += 1; } + } + + // Store the hash. + _state.guardianSetHashes[index] = keccak256( + abi.encodePacked(encodedGuardianSet, guardianSet.expirationTime) + ); } } \ No newline at end of file