Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent invalid destination griefing for the relayer #2703

Merged
merged 30 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
45d2df6
Init immutable mailbox v3 and native hooks
yorhodes Jul 25, 2023
df69886
Simplify mailbox and make interfaces payable
yorhodes Jul 25, 2023
9ef2da3
Update version constant
yorhodes Jul 25, 2023
a78be69
Keep message ID events
yorhodes Jul 25, 2023
f56c9a4
Kunal/v3 hooks (#2580)
aroralanuk Aug 2, 2023
fba00e1
Add msg.sender to delivery mapping
yorhodes Aug 2, 2023
0f37848
Begin merge
yorhodes Aug 3, 2023
8cabf55
More mailbox changes
yorhodes Aug 3, 2023
bccc5f6
Only run core contracts CI
yorhodes Aug 14, 2023
96d8f79
Use mailbox callback to authenticate messages in hooks where necessar…
yorhodes Aug 14, 2023
b008540
Modifying IGP to be a hook (#2638)
aroralanuk Aug 15, 2023
816cc40
Converting the OP stack hooks to transient storage version (#2632)
aroralanuk Aug 15, 2023
a574665
Remove e2e and add yarn build to CI
yorhodes Aug 15, 2023
abc8b79
Adding protocol fees (#2640)
aroralanuk Aug 15, 2023
2e67868
Fix forge tests post V3 (#2661)
aroralanuk Aug 17, 2023
7323954
Add `quoteDispatch` to `IPostDispatchHook` (#2660)
aroralanuk Aug 17, 2023
a776131
Add deployed block numbers to indexable contracts (#2672)
yorhodes Aug 18, 2023
0c3f1ed
Add aggregation hook for V3 (#2667)
aroralanuk Aug 30, 2023
27cd6c9
add to event and struct
aroralanuk Sep 3, 2023
dcabfb0
add abi and test
aroralanuk Sep 4, 2023
60b2fc3
fix ci errors
aroralanuk Sep 5, 2023
115ef53
Add forge test for Mailbox (#2713)
yorhodes Sep 8, 2023
7dd2190
Warp route changes for v3 (#2721)
aroralanuk Sep 13, 2023
807ef52
merge conflicit resolved
aroralanuk Sep 13, 2023
70260cf
key as {message_id,destination}
aroralanuk Sep 14, 2023
e6d294e
Init immutable mailbox v3 and native hooks
yorhodes Jul 25, 2023
4b4e4f1
import gaspaymentkey
aroralanuk Sep 14, 2023
d3175fb
add random to LogMeta
aroralanuk Sep 15, 2023
9e23ac9
rename to _gas_payment_key
aroralanuk Sep 15, 2023
bea2b4f
Merge branch 'v3' into prevent-invalid-dest-griefing
aroralanuk Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 125 additions & 4 deletions rust/agents/relayer/src/msg/gas_payment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use tracing::{debug, error, trace};

use hyperlane_base::db::HyperlaneRocksDB;
use hyperlane_core::{
HyperlaneMessage, InterchainGasExpenditure, InterchainGasPayment, TxCostEstimate, TxOutcome,
U256,
GasPaymentKey, HyperlaneMessage, InterchainGasExpenditure, InterchainGasPayment,
TxCostEstimate, TxOutcome, U256,
};

use crate::msg::gas_payment::policies::GasPaymentPolicyOnChainFeeQuoting;
Expand Down Expand Up @@ -78,7 +78,13 @@ impl GasPaymentEnforcer {
tx_cost_estimate: &TxCostEstimate,
) -> Result<Option<U256>> {
let msg_id = message.id();
let current_payment = self.db.retrieve_gas_payment_by_message_id(msg_id)?;
let gas_payment_key = GasPaymentKey {
message_id: msg_id,
destination: message.destination,
};
let current_payment = self
.db
.retrieve_gas_payment_by_gas_payment_key(gas_payment_key)?;
let current_expenditure = self.db.retrieve_gas_expenditure_by_message_id(msg_id)?;
for (policy, whitelist) in &self.policies {
if !whitelist.msg_matches(message, true) {
Expand Down Expand Up @@ -137,7 +143,10 @@ mod test {
use std::str::FromStr;

use hyperlane_base::db::{test_utils, HyperlaneRocksDB};
use hyperlane_core::{HyperlaneDomain, HyperlaneMessage, TxCostEstimate, H160, H256, U256};
use hyperlane_core::{
HyperlaneDomain, HyperlaneMessage, InterchainGasPayment, LogMeta, TxCostEstimate, H160,
H256, U256,
};

use crate::settings::{
matching_list::MatchingList, GasPaymentEnforcementConf, GasPaymentEnforcementPolicy,
Expand Down Expand Up @@ -209,6 +218,118 @@ mod test {
.await;
}

#[tokio::test]
async fn test_different_destinations() {
#[allow(unused_must_use)]
test_utils::run_test_db(|db| async move {
let msg = HyperlaneMessage {
destination: 123,
..HyperlaneMessage::default()
};

let hyperlane_db = HyperlaneRocksDB::new(
&HyperlaneDomain::new_test_domain("test_different_destinations"),
db,
);
let enforcer = GasPaymentEnforcer::new(
vec![GasPaymentEnforcementConf {
policy: GasPaymentEnforcementPolicy::Minimum {
payment: U256::one(),
},
matching_list: MatchingList::default(),
}],
hyperlane_db.clone(),
);

let wrong_destination_payment = InterchainGasPayment {
message_id: msg.id(),
destination: 456,
payment: U256::one(),
gas_amount: U256::one(),
};
hyperlane_db.process_gas_payment(wrong_destination_payment, &LogMeta::random());
// Ensure if the gas payment was made to the incorrect destination, it does not meet
// the requirement
assert!(enforcer
.message_meets_gas_payment_requirement(&msg, &TxCostEstimate::default(),)
.await
.unwrap()
.is_none());

let correct_destination_payment = InterchainGasPayment {
message_id: msg.id(),
destination: msg.destination,
payment: U256::one(),
gas_amount: U256::one(),
};
hyperlane_db.process_gas_payment(correct_destination_payment, &LogMeta::random());
// Ensure if the gas payment was made to the correct destination, it meets the
// requirement
assert!(enforcer
.message_meets_gas_payment_requirement(&msg, &TxCostEstimate::default(),)
.await
.unwrap()
.is_some());
})
.await;
}

#[tokio::test]
async fn test_half_and_half_payment() {
#[allow(unused_must_use)]
test_utils::run_test_db(|db| async move {
let msg = HyperlaneMessage {
destination: 123,
..HyperlaneMessage::default()
};

let hyperlane_db = HyperlaneRocksDB::new(
&HyperlaneDomain::new_test_domain("test_half_and_half_payment"),
db,
);

let enforcer = GasPaymentEnforcer::new(
vec![GasPaymentEnforcementConf {
policy: GasPaymentEnforcementPolicy::Minimum {
payment: U256::from(2),
},
matching_list: MatchingList::default(),
}],
hyperlane_db.clone(),
);

let initial_payment = InterchainGasPayment {
message_id: msg.id(),
destination: msg.destination,
payment: U256::one(),
gas_amount: U256::one(),
};
hyperlane_db.process_gas_payment(initial_payment, &LogMeta::random());

// Ensure if only half gas payment was made, it does not meet the requirement
assert!(enforcer
.message_meets_gas_payment_requirement(&msg, &TxCostEstimate::default(),)
.await
.unwrap()
.is_none());

let deficit_payment = InterchainGasPayment {
message_id: msg.id(),
destination: msg.destination,
payment: U256::one(),
gas_amount: U256::one(),
};
hyperlane_db.process_gas_payment(deficit_payment, &LogMeta::random());
// Ensure if the full gas payment was made, it meets the requirement
assert!(enforcer
.message_meets_gas_payment_requirement(&msg, &TxCostEstimate::default(),)
.await
.unwrap()
.is_some());
})
.await;
}

#[tokio::test]
async fn test_non_empty_matching_list() {
test_utils::run_test_db(|db| async move {
Expand Down
2 changes: 2 additions & 0 deletions rust/agents/relayer/src/msg/gas_payment/policies/minimum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async fn test_gas_payment_policy_minimum() {
// If the payment is less than the minimum, returns false
let current_payment = InterchainGasPayment {
message_id: H256::zero(),
destination: message.destination,
payment: U256::from(999u32),
gas_amount: U256::zero(),
};
Expand Down Expand Up @@ -70,6 +71,7 @@ async fn test_gas_payment_policy_minimum() {
// If the payment is at least the minimum, returns false
let current_payment = InterchainGasPayment {
message_id: H256::zero(),
destination: message.destination,
payment: U256::from(1000u32),
gas_amount: U256::zero(),
};
Expand Down
1 change: 1 addition & 0 deletions rust/agents/relayer/src/msg/gas_payment/policies/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async fn test_gas_payment_policy_none() {

let current_payment = InterchainGasPayment {
message_id: H256::zero(),
destination: message.destination,
payment: U256::zero(),
gas_amount: U256::zero(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ mod test {
fn current_payment(gas_amount: impl Into<U256>) -> InterchainGasPayment {
InterchainGasPayment {
message_id: H256::zero(),
destination: 0,
payment: U256::zero(),
gas_amount: gas_amount.into(),
}
Expand Down
Loading