Skip to content

Commit 016b36b

Browse files
committed
fix(pyth): remove stale migration entrypoint
The router verifier contract is intended for fresh deployment, so keeping a migrate entrypoint implied an unsupported in-place legacy state conversion path. Removing it avoids a broken migration surface and aligns the contract with the deployment plan. Router signature validation now reports out-of-range signer indexes separately from payloads that carry more signatures than the configured router set. Signed-off-by: Joseph Chalabi <chalabi.joseph@gmail.com>
1 parent 6717339 commit 016b36b

5 files changed

Lines changed: 40 additions & 51 deletions

File tree

contracts/pyth/src/contract.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cosmwasm_std::{
66
use crate::accumulator::{parse_accumulator_update, verify_merkle_proof};
77
use crate::error::ContractError;
88
use crate::msg::{
9-
ConfigResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, PriceFeedIdResponse, PriceFeedResponse,
9+
ConfigResponse, ExecuteMsg, InstantiateMsg, PriceFeedIdResponse, PriceFeedResponse,
1010
PriceResponse, QueryMsg, RouterVerifierConfigMsg,
1111
};
1212
use crate::oracle::{pyth_price_to_decimal, MsgAddPriceEntry};
@@ -357,23 +357,6 @@ fn query_price_feed_id(deps: Deps) -> StdResult<PriceFeedIdResponse> {
357357
})
358358
}
359359

360-
#[cfg_attr(not(feature = "library"), entry_point)]
361-
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
362-
let mut response = Response::new()
363-
.add_attribute("method", "migrate")
364-
.add_attribute("version", "3.0.0");
365-
366-
if let Some(router_config) = msg.router_verifier {
367-
let mut config = CONFIG.load(deps.storage)?;
368-
config.router_verifier = router::parse_config(router_config)?;
369-
CONFIG.save(deps.storage, &config)?;
370-
371-
response = response.add_attribute("router_verifier", "configured");
372-
}
373-
374-
Ok(response)
375-
}
376-
377360
#[cfg(test)]
378361
mod tests {
379362
use super::*;
@@ -482,31 +465,6 @@ mod tests {
482465
assert_eq!(26, response.router_verifier.expected_emitter_chain);
483466
}
484467

485-
#[test]
486-
fn test_migrate_can_update_router_verifier() {
487-
let mut deps = mock_deps();
488-
setup_config(&mut deps);
489-
490-
let mut router_config = production_router_config_msg();
491-
router_config.router_set_index = 1;
492-
let res = migrate(
493-
deps.as_mut(),
494-
mock_env(),
495-
MigrateMsg {
496-
router_verifier: Some(router_config),
497-
},
498-
)
499-
.unwrap();
500-
501-
assert!(res
502-
.attributes
503-
.iter()
504-
.any(|attr| attr.key == "router_verifier" && attr.value == "configured"));
505-
506-
let config = CONFIG.load(&deps.storage).unwrap();
507-
assert_eq!(1, config.router_verifier.router_set_index);
508-
}
509-
510468
#[test]
511469
fn test_update_price_feed_with_router_verified_pnau() {
512470
let mut deps = mock_deps();

contracts/pyth/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub enum ContractError {
4545
#[error("WrongRouterIndexOrder")]
4646
WrongRouterIndexOrder,
4747

48+
#[error("InvalidRouterIndex")]
49+
InvalidRouterIndex,
50+
4851
#[error("TooManySignatures")]
4952
TooManySignatures,
5053

contracts/pyth/src/integration_tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Note: Price update execution requires router-signed PNAU data. Those flows are
77
// tested via the contract's unit tests and actual chain integration tests.
88

9-
#![cfg(test)]
10-
119
use cosmwasm_std::testing::{message_info, mock_env, MockApi, MockQuerier, MockStorage};
1210
use cosmwasm_std::{from_json, Addr, Binary, Empty, OwnedDeps, Uint128, Uint256};
1311

contracts/pyth/src/msg.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,3 @@ pub struct ConfigResponse {
9797
pub struct PriceFeedIdResponse {
9898
pub price_feed_id: String,
9999
}
100-
101-
#[cw_serde]
102-
pub struct MigrateMsg {
103-
pub router_verifier: Option<RouterVerifierConfigMsg>,
104-
}

contracts/pyth/src/router.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn verify_router_signatures(
104104

105105
let router_index = router_index as usize;
106106
if router_index >= config.routers.len() {
107-
return Err(ContractError::TooManySignatures);
107+
return Err(ContractError::InvalidRouterIndex);
108108
}
109109

110110
let signature = Signature::try_from(
@@ -239,6 +239,41 @@ mod tests {
239239
assert!(err.to_string().contains("InvalidConfig"));
240240
}
241241

242+
#[test]
243+
fn rejects_invalid_router_index() {
244+
let keys = router_keys();
245+
let config = setup(&keys);
246+
let vaa = signed_vaa_with_keys(
247+
&[keys[0].clone(), keys[1].clone(), keys[4].clone()],
248+
&[0, 1, 5],
249+
ROUTER_SET_INDEX,
250+
EMITTER_CHAIN,
251+
EMITTER_ADDRESS,
252+
vec![],
253+
);
254+
255+
let err = verify_vaa(&config, &vaa).unwrap_err();
256+
assert!(matches!(err, ContractError::InvalidRouterIndex));
257+
}
258+
259+
#[test]
260+
fn rejects_too_many_signatures() {
261+
let mut keys = router_keys();
262+
keys.push(SigningKey::from_bytes((&[6u8; 32]).into()).unwrap());
263+
let config = setup(&keys[..ROUTER_COUNT]);
264+
let vaa = signed_vaa_with_keys(
265+
&keys,
266+
&[0, 1, 2, 3, 4, 5],
267+
ROUTER_SET_INDEX,
268+
EMITTER_CHAIN,
269+
EMITTER_ADDRESS,
270+
vec![],
271+
);
272+
273+
let err = verify_vaa(&config, &vaa).unwrap_err();
274+
assert!(matches!(err, ContractError::TooManySignatures));
275+
}
276+
242277
#[test]
243278
fn verifies_live_upgraded_hermes_akt_vaa_fixture() {
244279
let config = setup_production();

0 commit comments

Comments
 (0)