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

Remove gateway contract locations from Assets #986

Merged
merged 16 commits into from
Nov 3, 2023
6 changes: 3 additions & 3 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ library Assets {

_transferToAgent(assetHubAgent, token, sender, amount);
if (destinationChain == assetHubParaID) {
payload = SubstrateTypes.SendToken(address(this), token, destinationAddress, amount);
payload = SubstrateTypes.SendToken(token, destinationAddress, amount);
} else {
payload = SubstrateTypes.SendToken(address(this), token, destinationChain, destinationAddress, amount);
payload = SubstrateTypes.SendToken(token, destinationChain, destinationAddress, amount);
}
extraFee = $.sendTokenFee;

Expand Down Expand Up @@ -102,7 +102,7 @@ library Assets {
revert InvalidToken();
}

payload = SubstrateTypes.RegisterToken(address(this), token);
payload = SubstrateTypes.RegisterToken(token);
extraFee = $.registerTokenFee;

emit TokenRegistrationSent(token);
Expand Down
18 changes: 4 additions & 14 deletions contracts/src/SubstrateTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ library SubstrateTypes {
* `NativeTokensMessage::Create`
*/
// solhint-disable-next-line func-name-mixedcase
function RegisterToken(address gateway, address token) internal view returns (bytes memory) {
function RegisterToken(address token) internal view returns (bytes memory) {
return bytes.concat(
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x00),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token)
bytes1(0x00), ScaleCodec.encodeU64(uint64(block.chainid)), bytes1(0x00), SubstrateTypes.H160(token)
);
}

Expand All @@ -71,24 +67,19 @@ library SubstrateTypes {
* `NativeTokensMessage::Mint`
*/
// solhint-disable-next-line func-name-mixedcase
function SendToken(address gateway, address token, bytes32 recipient, uint128 amount)
internal
view
returns (bytes memory)
{
function SendToken(address token, bytes32 recipient, uint128 amount) internal view returns (bytes memory) {
return bytes.concat(
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x01),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token),
bytes1(0x00),
recipient,
ScaleCodec.encodeU128(amount)
);
}

function SendToken(address gateway, address token, ParaID paraID, bytes32 recipient, uint128 amount)
function SendToken(address token, ParaID paraID, bytes32 recipient, uint128 amount)
internal
view
returns (bytes memory)
Expand All @@ -97,7 +88,6 @@ library SubstrateTypes {
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x01),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token),
bytes1(0x01),
ScaleCodec.encodeU32(uint32(ParaID.unwrap(paraID))),
Expand Down
10 changes: 4 additions & 6 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ contract GatewayTest is Test {
emit TokenRegistrationSent(address(token));

vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token)));
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(token)));

IGateway(address(gateway)).registerToken{value: 2 ether}(address(token));
}
Expand All @@ -545,7 +545,7 @@ contract GatewayTest is Test {
emit TokenRegistrationSent(address(token));

vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token)));
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(token)));

uint256 totalFee = baseFee + registerNativeTokenFee;
uint256 balanceBefore = address(this).balance;
Expand All @@ -572,7 +572,7 @@ contract GatewayTest is Test {
// Expect the gateway to emit `OutboundMessageAccepted`
vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(
assetHubParaID, 1, SubstrateTypes.SendToken(address(gateway), address(token), destPara, destAddress, 1)
assetHubParaID, 1, SubstrateTypes.SendToken(address(token), destPara, destAddress, 1)
);

IGateway(address(gateway)).sendToken{value: 2 ether}(address(token), destPara, destAddress, 1);
Expand All @@ -591,9 +591,7 @@ contract GatewayTest is Test {

// Expect the gateway to emit `OutboundMessageAccepted`
vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(
assetHubParaID, 1, SubstrateTypes.SendToken(address(gateway), address(token), destAddress, 1)
);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.SendToken(address(token), destAddress, 1));

IGateway(address(gateway)).sendToken{value: 2 ether}(address(token), destPara, destAddress, 1);
}
Expand Down
22 changes: 10 additions & 12 deletions parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ pub struct InboundQueueTest {
pub fn make_create_message() -> InboundQueueTest {
InboundQueueTest{
execution_header: CompactExecutionHeader{
parent_hash: hex!("de4afc4d33a83815cde0a6dd95c8e52d9e01231d67d5b5a387ec70994a96108f").into(),
block_number: 61,
state_root: hex!("7bfc6d7a49869863d621989dad7fa26c610470e65473a7e5cab87af67fc6976c").into(),
receipts_root: hex!("a2686fe1aa2f66ada774373ced7952f3591a7830b9161eec5d16149747253779").into(),
parent_hash: hex!("9e2078694f20148b48e938a5b35a4cca79e19a05b7f27c7b3daae11a2ab57524").into(),
block_number: 55,
state_root: hex!("74865f49fe887e1b9df502282b1e99ccf563861a0ed58e9e541d966207d11f3f").into(),
receipts_root: hex!("0115ab735d37c5e4cdb0374d8bb547c6dd6ccaa996d996d1eabc5399a719219e").into(),
},
message: Message {
data: hex!("f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000").to_vec(),
data: hex!("f8db94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").to_vec(),
proof: Proof {
block_hash: hex!("565f5dc872af9351abd1ba4974753169a98f028ef2c2ef3bb6d4eea4c6519eac").into(),
block_hash: hex!("5f465744c166e9d10dc0031942a59ff82b640053253da517a1b576afdadb0363").into(),
tx_index: 0,
data: (vec![
hex!("a2686fe1aa2f66ada774373ced7952f3591a7830b9161eec5d16149747253779").to_vec(),
hex!("77cc88c126ea5be62d3caea280da54cd051a05dadc03e4ecf69621da86ff9e12").to_vec(),
hex!("61ced6f6c7533351a0e60916ee60bbe4f7c49efae74bb898d06b1ae975b38c51").to_vec(),
hex!("0115ab735d37c5e4cdb0374d8bb547c6dd6ccaa996d996d1eabc5399a719219e").to_vec(),
hex!("caf5ee6beba6a6db5e2a0714a98f65ac4365c4a24e56ce033f19c7f8a2abb06a").to_vec(),
], vec![
hex!("f90131a0697ffa69627df903e12004769f4a763d81cc2d947fa75e47996112144c7d07d1a0a755881c8727579c18865b63c20117773ddb5579acdb3ed493557bb6aa5a1117a0ba0c4975a96270e63526f20073d129931e4b1dfc4dbd477a92c7d587afaad6a1a0e2c388369c489466c7c03d0a9f3cb294c8fc659015a395f7dc7b1b28eaf18ef4a027fcb43431cd39b449624b39ceb0017fce919e14e2ca77c28f8ab981b01aa637a05f3c3aac495f2fbc982da582c8e62ac05adb1e0552a1b9e81be96028094cbcc4a0a3f115af7400065f142ec8edea4f2000a4bcf6394869df85ecb9d27d75e344daa0b5f12f70fc3e4078273e59aba72683905d11e1c4b1a68858a6e53d3c50f65b93a077cc88c126ea5be62d3caea280da54cd051a05dadc03e4ecf69621da86ff9e128080808080808080").to_vec(),
hex!("f851a061ced6f6c7533351a0e60916ee60bbe4f7c49efae74bb898d06b1ae975b38c51a0f0baa5ff24cde5e3bcc6e5394b30e10e97cca31d002d68769883293d0ebbd569808080808080808080808080808080").to_vec(),
hex!("f9026a20b9026602f902620183013defb9010000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000400000000000000000000000000000000000000000000000000000000000000000000000020200000000000000000000000000000000000040000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000000000000000000000000014f90157f85894eda338e4dc46038493b885327842fd3e301cab39e1a0f78bb28d4b1d7da699e5c0bc2be29c2b04b5aab6aacf6298fe5304f9db9c6d7ea000000000000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7df8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000034000f000000000000000057a2d4ff0c3866d96556884bf09fecdd7ccd530c87d1f7fdfee7f651fabc8bfcb6e086c278b77a7d3500000000000000000000000000").to_vec(),
hex!("5e2a0714a98f65ac4365c4a24e56ce033f19c7f8a2abb06a8080808080808080").to_vec(),
hex!("000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000").to_vec(),
]),
},
},
Expand Down
22 changes: 13 additions & 9 deletions parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,32 +238,36 @@ fn parse_dest(message: Message) -> ParaId {
}

// dest para is 1000
const OUTBOUND_QUEUE_EVENT_LOG: [u8; 253] = hex!(
const OUTBOUND_QUEUE_EVENT_LOG: [u8; 221] = hex!(
"
f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000
f8db94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000
"
);

// dest para is 1001
const OUTBOUND_QUEUE_EVENT_LOG_INVALID_DEST: [u8; 253] = hex!(
const OUTBOUND_QUEUE_EVENT_LOG_INVALID_DEST: [u8; 221] = hex!(
"
f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e9b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000
f8db94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e9b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000
"
);

// gateway in message does not match configured gateway in runtime
const BAD_OUTBOUND_QUEUE_EVENT_LOG: [u8; 253] = hex!(
const BAD_OUTBOUND_QUEUE_EVENT_LOG: [u8; 221] = hex!(
"
f8fb940000000000000000000000000000000000000000f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e9b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000
f8db940000000000000000000000000000000000000000f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000
"
);

// invalid payload with unsupported version
const BAD_OUTBOUND_QUEUE_LOG_UNSUPPORTED_VERSION: [u8; 253] = hex!("f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032010f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000");
const BAD_OUTBOUND_QUEUE_LOG_UNSUPPORTED_VERSION: [u8; 221] = hex!(
"
f8db94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e010f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000
"
);

const XCM_HASH: [u8; 32] = [
232, 213, 62, 94, 48, 47, 152, 37, 168, 162, 89, 100, 6, 74, 63, 95, 211, 11, 222, 210, 1, 209,
126, 44, 164, 122, 166, 156, 208, 228, 209, 9,
186, 27, 67, 39, 117, 164, 224, 191, 202, 232, 218, 108, 34, 65, 36, 199, 247, 19, 150, 198,
182, 180, 39, 112, 150, 64, 84, 15, 174, 213, 183, 207,
];
const ASSET_HUB_PARAID: u32 = 1000u32;
const TEMPLATE_PARAID: u32 = 1001u32;
Expand Down
Loading