Skip to content

Commit

Permalink
Bridge Custom Networks (#17140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bridgerz authored and patrickkuo committed May 2, 2024
1 parent 22fb9b8 commit edf900b
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 237 deletions.
4 changes: 2 additions & 2 deletions bridge/evm/test/BridgeLimiterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ contract BridgeLimiterTest is BridgeBaseTest {
messageType: BridgeUtils.UPDATE_BRIDGE_LIMIT,
version: 1,
nonce: 15,
chainID: 3,
chainID: 2,
payload: payload
});
bytes memory encodedMessage = BridgeUtils.encodeMessage(message);
bytes memory expectedEncodedMessage =
hex"5355495f4252494447455f4d4553534147450301000000000000000f030c00000002540be400";
hex"5355495f4252494447455f4d4553534147450301000000000000000f020c00000002540be400";

assertEq(encodedMessage, expectedEncodedMessage);
}
Expand Down
4 changes: 2 additions & 2 deletions bridge/evm/test/SuiBridgeTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ contract SuiBridgeTest is BridgeBaseTest, ISuiBridge {
tokenPrices[2] = 1 * USD_VALUE_MULTIPLIER; // ETH PRICE
tokenPrices[3] = 1 * USD_VALUE_MULTIPLIER; // USDC PRICE
tokenPrices[4] = 1 * USD_VALUE_MULTIPLIER; // USDT PRICE
uint8 _chainID = 3;
uint8 _chainID = 2;
uint8[] memory _supportedDestinationChains = new uint8[](1);
_supportedDestinationChains[0] = 0;
address[] memory _supportedTokens = new address[](5);
Expand Down Expand Up @@ -679,7 +679,7 @@ contract SuiBridgeTest is BridgeBaseTest, ISuiBridge {
});
bytes memory encodedMessage = BridgeUtils.encodeMessage(message);
bytes memory expectedEncodedMessage =
hex"5355495f4252494447455f4d455353414745020100000000000000370300";
hex"5355495f4252494447455f4d455353414745020100000000000000370200";

assertEq(encodedMessage, expectedEncodedMessage);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-bridge/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ mod tests {
fn test_eth_message_conversion_add_tokens_on_evm_action_regression() -> anyhow::Result<()> {
let action = AddTokensOnEvmAction {
nonce: 5,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
native: true,
token_ids: vec![99, 100, 101],
token_addresses: vec![
Expand All @@ -369,7 +369,7 @@ mod tests {
message_type: BridgeActionType::AddTokensOnEvm as u8,
version: ADD_TOKENS_ON_EVM_MESSAGE_VERSION,
nonce: 5,
chain_id: BridgeChainId::EthLocalTest as u8,
chain_id: BridgeChainId::EthCustom as u8,
payload: Hex::decode("0103636465030101010101010101010101010101010101010101020202020202020202020202020202020202020203030303030303030303030303030303030303030305060703000000003b9aca00000000007735940000000000b2d05e00").unwrap().into(),
}
);
Expand Down
28 changes: 14 additions & 14 deletions crates/sui-bridge/src/client/bridge_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {
sui_tx_digest,
sui_tx_event_index,
sui_bridge_event: EmittedSuiToEthTokenBridgeV1 {
sui_chain_id: BridgeChainId::SuiDevnet,
sui_chain_id: BridgeChainId::SuiCustom,
nonce: 1,
sui_address: SuiAddress::random_for_testing_only(),
eth_chain_id: BridgeChainId::EthSepolia,
Expand All @@ -458,7 +458,7 @@ mod tests {
eth_chain_id: BridgeChainId::EthSepolia,
nonce: 1,
eth_address: EthAddress::random(),
sui_chain_id: BridgeChainId::SuiDevnet,
sui_chain_id: BridgeChainId::SuiCustom,
sui_address: SuiAddress::random_for_testing_only(),
token_id: TOKEN_ID_USDT,
sui_adjusted_amount: 1,
Expand Down Expand Up @@ -509,28 +509,28 @@ mod tests {
);

let action = BridgeAction::EmergencyAction(crate::types::EmergencyAction {
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
nonce: 5,
action_type: crate::types::EmergencyActionType::Pause,
});
assert_eq!(
BridgeClient::bridge_action_to_path(&action),
"sign/emergency_button/3/5/0",
"sign/emergency_button/2/5/0",
);

let action = BridgeAction::LimitUpdateAction(crate::types::LimitUpdateAction {
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
nonce: 10,
sending_chain_id: BridgeChainId::EthLocalTest,
sending_chain_id: BridgeChainId::EthCustom,
new_usd_limit: 100,
});
assert_eq!(
BridgeClient::bridge_action_to_path(&action),
"sign/update_limit/3/10/12/100",
"sign/update_limit/2/10/12/100",
);

let action = BridgeAction::AssetPriceUpdateAction(crate::types::AssetPriceUpdateAction {
chain_id: BridgeChainId::SuiDevnet,
chain_id: BridgeChainId::SuiCustom,
nonce: 8,
token_id: TOKEN_ID_BTC,
new_usd_price: 100_000_000,
Expand All @@ -543,7 +543,7 @@ mod tests {
let action =
BridgeAction::EvmContractUpgradeAction(crate::types::EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data: vec![],
Expand All @@ -559,7 +559,7 @@ mod tests {
let action =
BridgeAction::EvmContractUpgradeAction(crate::types::EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data: call_data.clone(),
Expand All @@ -573,7 +573,7 @@ mod tests {
let action =
BridgeAction::EvmContractUpgradeAction(crate::types::EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data,
Expand All @@ -585,7 +585,7 @@ mod tests {

let action = BridgeAction::AddTokensOnSuiAction(crate::types::AddTokensOnSuiAction {
nonce: 3,
chain_id: BridgeChainId::SuiTestnet,
chain_id: BridgeChainId::SuiCustom,
native: false,
token_ids: vec![99, 100, 101],
token_type_names: vec![
Expand All @@ -597,12 +597,12 @@ mod tests {
});
assert_eq!(
BridgeClient::bridge_action_to_path(&action),
"sign/add_tokens_on_sui/1/3/0/99,100,101/0x0000000000000000000000000000000000000000000000000000000000000abc::my_coin::MyCoin1,0x0000000000000000000000000000000000000000000000000000000000000abc::my_coin::MyCoin2,0x0000000000000000000000000000000000000000000000000000000000000abc::my_coin::MyCoin3/1000000000,2000000000,3000000000",
"sign/add_tokens_on_sui/2/3/0/99,100,101/0x0000000000000000000000000000000000000000000000000000000000000abc::my_coin::MyCoin1,0x0000000000000000000000000000000000000000000000000000000000000abc::my_coin::MyCoin2,0x0000000000000000000000000000000000000000000000000000000000000abc::my_coin::MyCoin3/1000000000,2000000000,3000000000",
);

let action = BridgeAction::AddTokensOnEvmAction(crate::types::AddTokensOnEvmAction {
nonce: 0,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
native: true,
token_ids: vec![99, 100, 101],
token_addresses: vec![
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-bridge/src/e2e_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub async fn publish_coins_return_add_coins_on_sui_action(

BridgeAction::AddTokensOnSuiAction(AddTokensOnSuiAction {
nonce,
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
native: false,
token_ids,
token_type_names,
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-bridge/src/e2e_tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async fn test_bridge_from_eth_to_sui_to_eth() {
for _ in 0..3 {
server_ports.push(get_available_port("127.0.0.1"));
}
let eth_chain_id = BridgeChainId::EthLocalTest as u8;
let sui_chain_id = BridgeChainId::SuiLocalTest as u8;
let eth_chain_id = BridgeChainId::EthCustom as u8;
let sui_chain_id = BridgeChainId::SuiCustom as u8;
let mut test_cluster: test_cluster::TestCluster = TestClusterBuilder::new()
.with_protocol_version(BRIDGE_ENABLE_PROTOCOL_VERSION.into())
.build_with_bridge(true)
Expand Down
36 changes: 18 additions & 18 deletions crates/sui-bridge/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ mod tests {
.unwrap();
let blocklist_action = BridgeAction::BlocklistCommitteeAction(BlocklistCommitteeAction {
nonce: 129,
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
blocklist_type: BlocklistType::Blocklist,
blocklisted_members: vec![pub_key_bytes.clone()],
});
Expand All @@ -569,7 +569,7 @@ mod tests {
68b43fd906c0b8f024a18c56e06744f7c6157c65
]: blocklisted members abi-encoded
*/
assert_eq!(bytes, Hex::decode("5355495f4252494447455f4d4553534147450101000000000000008103000168b43fd906c0b8f024a18c56e06744f7c6157c65").unwrap());
assert_eq!(bytes, Hex::decode("5355495f4252494447455f4d4553534147450101000000000000008102000168b43fd906c0b8f024a18c56e06744f7c6157c65").unwrap());

let pub_key_bytes_2 = BridgeAuthorityPublicKeyBytes::from_bytes(
&Hex::decode("027f1178ff417fc9f5b8290bd8876f0a157a505a6c52db100a8492203ddd1d4279")
Expand All @@ -579,7 +579,7 @@ mod tests {
// its evem address: 0xacaef39832cb995c4e049437a3e2ec6a7bad1ab5
let blocklist_action = BridgeAction::BlocklistCommitteeAction(BlocklistCommitteeAction {
nonce: 68,
chain_id: BridgeChainId::SuiDevnet,
chain_id: BridgeChainId::SuiCustom,
blocklist_type: BlocklistType::Unblocklist,
blocklisted_members: vec![pub_key_bytes.clone(), pub_key_bytes_2.clone()],
});
Expand All @@ -601,7 +601,7 @@ mod tests {

let blocklist_action = BridgeAction::BlocklistCommitteeAction(BlocklistCommitteeAction {
nonce: 49,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
blocklist_type: BlocklistType::Blocklist,
blocklisted_members: vec![pub_key_bytes.clone()],
});
Expand Down Expand Up @@ -647,7 +647,7 @@ mod tests {
fn test_bridge_message_encoding_emergency_action() {
let action = BridgeAction::EmergencyAction(EmergencyAction {
nonce: 55,
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
action_type: EmergencyActionType::Pause,
});
let bytes = action.to_bytes();
Expand All @@ -661,7 +661,7 @@ mod tests {
*/
assert_eq!(
bytes,
Hex::decode("5355495f4252494447455f4d455353414745020100000000000000370300").unwrap()
Hex::decode("5355495f4252494447455f4d455353414745020100000000000000370200").unwrap()
);

let action = BridgeAction::EmergencyAction(EmergencyAction {
Expand All @@ -688,8 +688,8 @@ mod tests {
fn test_bridge_message_encoding_limit_update_action() {
let action = BridgeAction::LimitUpdateAction(LimitUpdateAction {
nonce: 15,
chain_id: BridgeChainId::SuiLocalTest,
sending_chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::SuiCustom,
sending_chain_id: BridgeChainId::EthCustom,
new_usd_limit: 1_000_000 * USD_MULTIPLIER, // $1M USD
});
let bytes = action.to_bytes();
Expand All @@ -705,7 +705,7 @@ mod tests {
assert_eq!(
bytes,
Hex::decode(
"5355495f4252494447455f4d4553534147450301000000000000000f030c00000002540be400"
"5355495f4252494447455f4d4553534147450301000000000000000f020c00000002540be400"
)
.unwrap()
);
Expand All @@ -715,7 +715,7 @@ mod tests {
fn test_bridge_message_encoding_asset_price_update_action() {
let action = BridgeAction::AssetPriceUpdateAction(AssetPriceUpdateAction {
nonce: 266,
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
token_id: TOKEN_ID_BTC,
new_usd_price: 100_000 * USD_MULTIPLIER, // $100k USD
});
Expand All @@ -732,7 +732,7 @@ mod tests {
assert_eq!(
bytes,
Hex::decode(
"5355495f4252494447455f4d4553534147450401000000000000010a0301000000003b9aca00"
"5355495f4252494447455f4d4553534147450401000000000000010a0201000000003b9aca00"
)
.unwrap()
);
Expand All @@ -748,7 +748,7 @@ mod tests {

let action = BridgeAction::EvmContractUpgradeAction(EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data,
Expand Down Expand Up @@ -779,7 +779,7 @@ mod tests {
);
let action = BridgeAction::EvmContractUpgradeAction(EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data,
Expand Down Expand Up @@ -814,7 +814,7 @@ mod tests {
);
let action = BridgeAction::EvmContractUpgradeAction(EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data,
Expand All @@ -839,7 +839,7 @@ mod tests {
// Empty calldate
let action = BridgeAction::EvmContractUpgradeAction(EvmContractUpgradeAction {
nonce: 123,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
proxy_address: EthAddress::repeat_byte(6),
new_impl_address: EthAddress::repeat_byte(9),
call_data: vec![],
Expand Down Expand Up @@ -919,7 +919,7 @@ mod tests {

let action = BridgeAction::AddTokensOnSuiAction(AddTokensOnSuiAction {
nonce: 0,
chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::SuiCustom,
native: false,
token_ids: vec![1, 2, 3, 4],
token_type_names: vec![
Expand All @@ -939,7 +939,7 @@ mod tests {

assert_eq!(
Hex::encode(encoded_bytes),
"5355495f4252494447455f4d4553534147450601000000000000000003000401020304044a396235653133626364306362323366663235633037363938653839643438303536633734353333386438633964626430333361343137326238373032373037333a3a6274633a3a4254434a373937306437316330333537336635343061373135376630643339373065313137656666613661653136636566643530623435633734393637306232346536613a3a6574683a3a4554484c353030653432396132343437383430356435313330323232623230663835373061373436623662633232343233663134623464346536613865613538303733363a3a757364633a3a555344434c343662666535316461316264393531313931396139326562313135343134396233366330663432313231323138303865313365336535383537643630376139633a3a757364743a3a55534454040065cd1d0000000080c3c90100000000e803000000000000e803000000000000",
"5355495f4252494447455f4d4553534147450601000000000000000002000401020304044a396235653133626364306362323366663235633037363938653839643438303536633734353333386438633964626430333361343137326238373032373037333a3a6274633a3a4254434a373937306437316330333537336635343061373135376630643339373065313137656666613661653136636566643530623435633734393637306232346536613a3a6574683a3a4554484c353030653432396132343437383430356435313330323232623230663835373061373436623662633232343233663134623464346536613865613538303733363a3a757364633a3a555344434c343662666535316461316264393531313931396139326562313135343134396233366330663432313231323138303865313365336535383537643630376139633a3a757364743a3a55534454040065cd1d0000000080c3c90100000000e803000000000000e803000000000000",
);
Ok(())
}
Expand All @@ -948,7 +948,7 @@ mod tests {
fn test_bridge_message_encoding_regression_add_coins_on_evm() -> anyhow::Result<()> {
let action = BridgeAction::AddTokensOnEvmAction(crate::types::AddTokensOnEvmAction {
nonce: 0,
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
native: true,
token_ids: vec![99, 100, 101],
token_addresses: vec![
Expand Down
8 changes: 2 additions & 6 deletions crates/sui-bridge/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ impl TryFrom<MoveTokenBridgeEvent> for EmittedSuiToEthTokenBridgeV1 {
})?;

match sui_chain_id {
BridgeChainId::SuiMainnet
| BridgeChainId::SuiTestnet
| BridgeChainId::SuiDevnet
| BridgeChainId::SuiLocalTest => {}
BridgeChainId::SuiMainnet | BridgeChainId::SuiTestnet | BridgeChainId::SuiCustom => {}
_ => {
return Err(BridgeError::Generic(format!(
"Failed to convert MoveTokenBridgeEvent to EmittedSuiToEthTokenBridgeV1. Invalid source chain {}",
Expand All @@ -90,8 +87,7 @@ impl TryFrom<MoveTokenBridgeEvent> for EmittedSuiToEthTokenBridgeV1 {
}
}
match eth_chain_id {
BridgeChainId::EthMainnet | BridgeChainId::EthSepolia | BridgeChainId::EthLocalTest => {
}
BridgeChainId::EthMainnet | BridgeChainId::EthSepolia | BridgeChainId::EthCustom => {}
_ => {
return Err(BridgeError::Generic(format!(
"Failed to convert MoveTokenBridgeEvent to EmittedSuiToEthTokenBridgeV1. Invalid target chain {}",
Expand Down
10 changes: 5 additions & 5 deletions crates/sui-bridge/src/server/governance_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ mod tests {
#[tokio::test]
async fn test_governance_verifier() {
let action_1 = BridgeAction::EmergencyAction(EmergencyAction {
chain_id: BridgeChainId::EthLocalTest,
chain_id: BridgeChainId::EthCustom,
nonce: 1,
action_type: EmergencyActionType::Pause,
});
let action_2 = BridgeAction::LimitUpdateAction(LimitUpdateAction {
chain_id: BridgeChainId::EthLocalTest,
sending_chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::EthCustom,
sending_chain_id: BridgeChainId::SuiCustom,
nonce: 1,
new_usd_limit: 10000,
});
Expand All @@ -80,8 +80,8 @@ mod tests {
);

let action_3 = BridgeAction::LimitUpdateAction(LimitUpdateAction {
chain_id: BridgeChainId::EthLocalTest,
sending_chain_id: BridgeChainId::SuiLocalTest,
chain_id: BridgeChainId::EthCustom,
sending_chain_id: BridgeChainId::SuiCustom,
nonce: 2,
new_usd_limit: 10000,
});
Expand Down
Loading

0 comments on commit edf900b

Please sign in to comment.