@@ -45,28 +45,14 @@ abstract contract PythGovernance is
45
45
address newVerifierAddress
46
46
);
47
47
48
- // Check whether the encodedVM is signed by either the Wormhole or the Verifier.
49
- function validateVm (
48
+ function verifyGovernanceVM (
50
49
bytes memory encodedVM
51
- ) internal view returns (IWormhole.VM memory parsedVM ) {
50
+ ) internal returns (IWormhole.VM memory parsedVM ) {
52
51
(IWormhole.VM memory vm , bool valid , ) = wormhole ().parseAndVerifyVM (
53
52
encodedVM
54
53
);
55
- if (valid) return vm;
56
54
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 ();
70
56
71
57
if (! isValidGovernanceDataSource (vm.emitterChainId, vm.emitterAddress))
72
58
revert PythErrors.InvalidGovernanceDataSource ();
@@ -156,8 +142,11 @@ abstract contract PythGovernance is
156
142
// Make sure the claimVaa is a valid VAA with RequestGovernanceDataSourceTransfer governance message
157
143
// If it's valid then its emitter can take over the governance from the current emitter.
158
144
// 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 ();
161
150
162
151
GovernanceInstruction memory gi = parseGovernanceInstruction (
163
152
vm.payload
@@ -232,8 +221,6 @@ abstract contract PythGovernance is
232
221
emit ValidPeriodSet (oldValidPeriod, validTimePeriodSeconds ());
233
222
}
234
223
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.
237
224
function setWormholeAddress (
238
225
SetWormholeAddressPayload memory payload ,
239
226
bytes memory encodedVM
@@ -295,47 +282,12 @@ abstract contract PythGovernance is
295
282
emit FeeWithdrawn (payload.targetAddress, payload.fee);
296
283
}
297
284
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.
300
285
function setVerifierAddress (
301
286
SetVerifierAddressPayload memory payload ,
302
287
bytes memory encodedVM
303
288
) internal {
304
289
address oldVerifierAddress = address (verifier ());
305
290
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
-
339
291
emit VerifierAddressSet (oldVerifierAddress, address (verifier ()));
340
292
}
341
293
}
0 commit comments