Skip to content

Commit 6677028

Browse files
committed
Use only wh for governance messages
1 parent 937baf5 commit 6677028

File tree

1 file changed

+8
-56
lines changed

1 file changed

+8
-56
lines changed

target_chains/ethereum/contracts/contracts/pyth/PythGovernance.sol

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,14 @@ abstract contract PythGovernance is
4545
address newVerifierAddress
4646
);
4747

48-
// Check whether the encodedVM is signed by either the Wormhole or the Verifier.
49-
function validateVm(
48+
function verifyGovernanceVM(
5049
bytes memory encodedVM
51-
) internal view returns (IWormhole.VM memory parsedVM) {
50+
) internal returns (IWormhole.VM memory parsedVM) {
5251
(IWormhole.VM memory vm, bool valid, ) = wormhole().parseAndVerifyVM(
5352
encodedVM
5453
);
55-
if (valid) return vm;
5654

57-
if (address(verifier()) != address(0)) {
58-
(IWormhole.VM memory vmv, bool validv, ) = verifier()
59-
.parseAndVerifyVM(encodedVM);
60-
if (validv) return vmv;
61-
}
62-
63-
revert PythErrors.InvalidWormholeVaa();
64-
}
65-
66-
function verifyGovernanceVM(
67-
bytes memory encodedVM
68-
) internal returns (IWormhole.VM memory parsedVM) {
69-
IWormhole.VM memory vm = validateVm(encodedVM);
55+
if (!valid) revert PythErrors.InvalidWormholeVaa();
7056

7157
if (!isValidGovernanceDataSource(vm.emitterChainId, vm.emitterAddress))
7258
revert PythErrors.InvalidGovernanceDataSource();
@@ -156,8 +142,11 @@ abstract contract PythGovernance is
156142
// Make sure the claimVaa is a valid VAA with RequestGovernanceDataSourceTransfer governance message
157143
// If it's valid then its emitter can take over the governance from the current emitter.
158144
// The VAA is checked here to ensure that the new governance data source is valid and can send message
159-
// through wormhole or verifier.
160-
IWormhole.VM memory vm = validateVm(payload.claimVaa);
145+
// through wormhole.
146+
(IWormhole.VM memory vm, bool valid, ) = wormhole().parseAndVerifyVM(
147+
payload.claimVaa
148+
);
149+
if (!valid) revert PythErrors.InvalidWormholeVaa();
161150

162151
GovernanceInstruction memory gi = parseGovernanceInstruction(
163152
vm.payload
@@ -232,8 +221,6 @@ abstract contract PythGovernance is
232221
emit ValidPeriodSet(oldValidPeriod, validTimePeriodSeconds());
233222
}
234223

235-
// If the VAA was created by Verifier, this will revert,
236-
// because it assumes that the new Wormhole is able to parse and verify the governance VAA.
237224
function setWormholeAddress(
238225
SetWormholeAddressPayload memory payload,
239226
bytes memory encodedVM
@@ -295,47 +282,12 @@ abstract contract PythGovernance is
295282
emit FeeWithdrawn(payload.targetAddress, payload.fee);
296283
}
297284

298-
// If the VAA was created by Wormhole, this will revert,
299-
// because it assumes that the new Verifier is able to parse and verify the governance VAA.
300285
function setVerifierAddress(
301286
SetVerifierAddressPayload memory payload,
302287
bytes memory encodedVM
303288
) internal {
304289
address oldVerifierAddress = address(verifier());
305290
setVerifier(payload.newVerifierAddress);
306-
307-
// We want to verify that the new verifier address is valid, so we make sure that it can
308-
// parse and verify the same governance VAA that is used to set it.
309-
(IWormhole.VM memory vm, bool valid, ) = verifier().parseAndVerifyVM(
310-
encodedVM
311-
);
312-
313-
if (!valid) revert PythErrors.InvalidGovernanceMessage();
314-
315-
if (!isValidGovernanceDataSource(vm.emitterChainId, vm.emitterAddress))
316-
revert PythErrors.InvalidGovernanceMessage();
317-
318-
if (vm.sequence != lastExecutedGovernanceSequence())
319-
revert PythErrors.InvalidVerifierAddressToSet();
320-
321-
GovernanceInstruction memory gi = parseGovernanceInstruction(
322-
vm.payload
323-
);
324-
325-
if (gi.action != GovernanceAction.SetVerifierAddress)
326-
revert PythErrors.InvalidVerifierAddressToSet();
327-
328-
// Purposefully, we don't check whether the chainId is the same as the current chainId because
329-
// we might want to change the chain id of the verifier contract.
330-
331-
// The following check is not necessary for security, but is a sanity check that the new verifier
332-
// contract parses the payload correctly.
333-
SetVerifierAddressPayload
334-
memory newPayload = parseSetVerifierAddressPayload(gi.payload);
335-
336-
if (newPayload.newVerifierAddress != payload.newVerifierAddress)
337-
revert PythErrors.InvalidVerifierAddressToSet();
338-
339291
emit VerifierAddressSet(oldVerifierAddress, address(verifier()));
340292
}
341293
}

0 commit comments

Comments
 (0)