-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
126 changed files
with
6,475 additions
and
1,624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@hyperlane-xyz/cli': minor | ||
'@hyperlane-xyz/core': minor | ||
--- | ||
|
||
Add CLI command to support AVS validator status check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@hyperlane-xyz/helloworld': minor | ||
'@hyperlane-xyz/infra': minor | ||
'@hyperlane-xyz/cli': minor | ||
--- | ||
|
||
Upgrade registry to 2.1.1 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ name: test | |
on: | ||
push: | ||
branches: [main] | ||
paths: | ||
- '*.md' | ||
- '!**/*' | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use hyperlane_core::HyperlaneMessage; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct AddressBlacklist { | ||
// A list of addresses that are blocked from being relayed. | ||
// Addresses are any length to support different address types. | ||
pub blacklist: Vec<Vec<u8>>, | ||
} | ||
|
||
impl AddressBlacklist { | ||
pub fn new(blacklist: Vec<Vec<u8>>) -> Self { | ||
Self { blacklist } | ||
} | ||
|
||
/// Returns true if the message is blocked by the blacklist. | ||
/// At the moment, this only checks if the sender, recipient, or body of the | ||
/// message contains any of the blocked addresses. | ||
pub fn find_blacklisted_address(&self, message: &HyperlaneMessage) -> Option<Vec<u8>> { | ||
self.blacklist.iter().find_map(|address| { | ||
if is_subsequence(message.sender.as_bytes(), address) | ||
|| is_subsequence(message.recipient.as_bytes(), address) | ||
|| is_subsequence(&message.body, address) | ||
{ | ||
// Return the blocked address that was found. | ||
Some(address.clone()) | ||
} else { | ||
None | ||
} | ||
}) | ||
} | ||
} | ||
|
||
/// Returns true if `needle` is a subsequence of `haystack`. | ||
fn is_subsequence<T: PartialEq>(mut haystack: &[T], needle: &[T]) -> bool { | ||
if needle.is_empty() { | ||
return true; | ||
} | ||
|
||
while !haystack.is_empty() { | ||
if needle.len() > haystack.len() { | ||
return false; | ||
} | ||
if haystack.starts_with(needle) { | ||
return true; | ||
} | ||
haystack = &haystack[1..]; | ||
} | ||
false | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use hyperlane_core::H256; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_is_subsequence() { | ||
assert!(is_subsequence(b"hello", b"hello")); | ||
assert!(is_subsequence(b"hello", b"he")); | ||
assert!(is_subsequence(b"hello", b"lo")); | ||
assert!(is_subsequence(b"hello", b"")); | ||
assert!(is_subsequence(b"hello", b"o")); | ||
|
||
assert!(!is_subsequence(b"hello", b"hello world")); | ||
assert!(!is_subsequence(b"hello", b"world")); | ||
assert!(!is_subsequence(b"hello", b"world hello")); | ||
} | ||
|
||
#[test] | ||
fn test_is_blocked() { | ||
let blocked = b"blocked"; | ||
let blocklist = AddressBlacklist::new(vec![blocked.to_vec()]); | ||
|
||
let bytes_with_subsequence = |subsequence: &[u8], index: usize, len: usize| { | ||
let mut bytes = vec![0; len]; | ||
bytes[index..index + subsequence.len()].copy_from_slice(subsequence); | ||
bytes | ||
}; | ||
|
||
let h256_with_subsequence = |subsequence: &[u8], index: usize| { | ||
let bytes = bytes_with_subsequence(subsequence, index, H256::len_bytes()); | ||
H256::from_slice(&bytes) | ||
}; | ||
|
||
// Blocked - sender includes the blocked address | ||
let message = HyperlaneMessage { | ||
sender: h256_with_subsequence(blocked, 0), | ||
..Default::default() | ||
}; | ||
assert_eq!( | ||
blocklist.find_blacklisted_address(&message), | ||
Some(blocked.to_vec()) | ||
); | ||
|
||
// Blocked - recipient includes the blocked address | ||
let message = HyperlaneMessage { | ||
recipient: h256_with_subsequence(blocked, 20), | ||
..Default::default() | ||
}; | ||
assert_eq!( | ||
blocklist.find_blacklisted_address(&message), | ||
Some(blocked.to_vec()) | ||
); | ||
|
||
// Blocked - body includes the blocked address | ||
let message = HyperlaneMessage { | ||
body: bytes_with_subsequence(blocked, 100 - blocked.len(), 100), | ||
..Default::default() | ||
}; | ||
assert_eq!( | ||
blocklist.find_blacklisted_address(&message), | ||
Some(blocked.to_vec()) | ||
); | ||
|
||
// Not blocked - sender, recipient, and body do not include the blocked address | ||
let message = HyperlaneMessage { | ||
body: vec![1; 100], | ||
..Default::default() | ||
}; | ||
assert!(blocklist.find_blacklisted_address(&message).is_none()); | ||
} | ||
} |
Oops, something went wrong.