Skip to content

Commit 066d45d

Browse files
committed
first fixes
1 parent 946f6e5 commit 066d45d

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

target_chains/stylus/contracts/pyth-receiver/src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub enum PythReceiverError {
2727
OldGovernanceMessage,
2828
GovernanceMessageAlreadyExecuted,
2929
InvalidWormholeAddressToSet,
30+
WormholeUninitialized,
3031
}
3132

3233
impl core::fmt::Debug for PythReceiverError {
@@ -67,6 +68,9 @@ impl core::fmt::Debug for PythReceiverError {
6768
PythReceiverError::InvalidWormholeAddressToSet => {
6869
write!(f, "InvalidWormholeAddressToSet")
6970
}
71+
PythReceiverError::WormholeUninitialized => {
72+
write!(f, "Wormhole is uninitialized, please set the Wormhole address and initialize the contract first")
73+
}
7074
}
7175
}
7276
}
@@ -111,6 +115,9 @@ impl core::fmt::Display for PythReceiverError {
111115
PythReceiverError::InvalidWormholeAddressToSet => {
112116
write!(f, "Invalid Wormhole address to set")
113117
}
118+
PythReceiverError::WormholeUninitialized => {
119+
write!(f, "Wormhole is uninitialized, please set the Wormhole address and initialize the contract first")
120+
}
114121
}
115122
}
116123
}
@@ -143,6 +150,7 @@ impl From<PythReceiverError> for Vec<u8> {
143150
PythReceiverError::OldGovernanceMessage => 23,
144151
PythReceiverError::GovernanceMessageAlreadyExecuted => 24,
145152
PythReceiverError::InvalidWormholeAddressToSet => 25,
153+
PythReceiverError::WormholeUninitialized => 26,
146154
}]
147155
}
148156
}

target_chains/stylus/contracts/pyth-receiver/src/governance_structs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::structs::DataSource;
33
use alloc::vec::Vec;
44
use stylus_sdk::alloy_primitives::{Address, FixedBytes, U16};
55

6+
// Magic is `PTGM` encoded as a 4 byte data: Pyth Governance Message
67
const MAGIC: u32 = 0x5054474d;
78
const MODULE_TARGET: u8 = 1;
89

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl PythReceiver {
543543
.map_err(|_| PythReceiverError::InvalidWormholeMessage)?;
544544

545545
let vm = Vaa::read(&mut Vec::from(data.clone()).as_slice())
546-
.map_err(|_| PythReceiverError::VaaVerificationFailed)?;
546+
.map_err(|_| PythReceiverError::InvalidVaa)?;
547547

548548
verify_governance_vm(self, vm.clone())?;
549549

@@ -554,7 +554,7 @@ impl PythReceiver {
554554

555555
let wormhole_id = wormhole
556556
.chain_id(chain_id_config)
557-
.map_err(|_| PythReceiverError::InvalidWormholeMessage)?;
557+
.map_err(|_| PythReceiverError::WormholeUninitialized)?;
558558

559559
if instruction.target_chain_id != 0 && instruction.target_chain_id != wormhole_id {
560560
return Err(PythReceiverError::InvalidGovernanceTarget);
@@ -618,7 +618,7 @@ impl PythReceiver {
618618
}
619619

620620
fn set_fee(&mut self, value: u64, expo: u64) {
621-
let new_fee = U256::from(value) * U256::from(10).pow(U256::from(expo));
621+
let new_fee = U256::from(value).saturating_mul(U256::from(10).pow(U256::from(expo)));
622622
let old_fee = self.single_update_fee_in_wei.get();
623623

624624
self.single_update_fee_in_wei.set(new_fee);
@@ -649,9 +649,7 @@ impl PythReceiver {
649649
let config = Call::new();
650650
wormhole
651651
.parse_and_verify_vm(config, data.clone())
652-
.map_err(|_| PythReceiverError::InvalidGovernanceMessage)?;
653-
654-
// if !is_valid_governance_data_source()
652+
.map_err(|_| PythReceiverError::InvalidVaa)?;
655653

656654
let vm = Vaa::read(&mut data.as_slice())
657655
.map_err(|_| PythReceiverError::VaaVerificationFailed)?;
@@ -723,7 +721,7 @@ impl PythReceiver {
723721
}
724722

725723
self.governance_data_source_index.set(U32::from(new_index));
726-
let _old_data_source = self.governance_data_source_index.get();
724+
let old_data_source_emitter_address = self.governance_data_source_emitter_address.get();
727725

728726
self.governance_data_source_chain_id
729727
.set(U16::from(claim_vm.body.emitter_chain));
@@ -744,7 +742,7 @@ impl PythReceiver {
744742
self.vm(),
745743
GovernanceDataSourceSet {
746744
old_chain_id: current_index as u16,
747-
old_emitter_address: self.governance_data_source_emitter_address.get(),
745+
old_emitter_address: old_data_source_emitter_address,
748746
new_chain_id: claim_vm.body.emitter_chain,
749747
new_emitter_address: FixedBytes::from(emitter_bytes),
750748
initial_sequence: last_executed_governance_sequence,
@@ -755,7 +753,7 @@ impl PythReceiver {
755753
}
756754

757755
fn set_transaction_fee(&mut self, value: u64, expo: u64) {
758-
let new_fee = U256::from(value) * U256::from(10).pow(U256::from(expo));
756+
let new_fee = U256::from(value).saturating_mul(U256::from(10).pow(U256::from(expo)));
759757
let old_fee = self.transaction_fee_in_wei.get();
760758

761759
self.transaction_fee_in_wei.set(new_fee);
@@ -769,7 +767,8 @@ impl PythReceiver {
769767
expo: u64,
770768
target_address: Address,
771769
) -> Result<(), PythReceiverError> {
772-
let fee_to_withdraw = U256::from(value) * U256::from(10).pow(U256::from(expo));
770+
let fee_to_withdraw =
771+
U256::from(value).saturating_mul(U256::from(10).pow(U256::from(expo)));
773772
let current_balance = self.vm().balance(self.vm().contract_address());
774773

775774
if current_balance < fee_to_withdraw {

target_chains/stylus/contracts/pyth-receiver/src/pyth_governance_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ mod test {
189189
fn test_set_wormhole_address(
190190
pyth_contract: Contract<PythReceiver>,
191191
wormhole_contract: Contract<WormholeContract>,
192+
wormhole_contract_2: Contract<WormholeContract>,
192193
alice: Address,
193194
) {
194195
pyth_wormhole_init(&pyth_contract, &wormhole_contract, &alice, 0);
@@ -214,6 +215,7 @@ mod test {
214215
215216
}
216217
*/
218+
217219
#[motsu::test]
218220
fn test_authorize_governance_data_source_transfer(
219221
pyth_contract: Contract<PythReceiver>,

0 commit comments

Comments
 (0)