evm: make setGuardianSetHash public

This commit is contained in:
gator-boi 2023-09-08 12:30:44 -04:00 committed by Dirk Brink
parent 7b90ea119b
commit ed86ea95f7
3 changed files with 16 additions and 7 deletions

View File

@ -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);

View File

@ -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

View File

@ -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)
);
}
}