Skip to content

Commit 2c5f052

Browse files
authored
Merge branch 'master' into fix_claim_account
2 parents b2262c9 + 18e7c4b commit 2c5f052

6 files changed

Lines changed: 52 additions & 59 deletions

File tree

pallets/dispenser/src/benchmarking.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,13 @@ mod benches {
132132
s.into_bytes()
133133
};
134134

135+
// CAIP-2 chain ID format
136+
let caip2_id = alloc::format!("eip155:{}", tx.chain_id);
137+
135138
let req_id = Pallet::<T>::generate_request_id(
136139
&Pallet::<T>::account_id(),
137140
&rlp,
138-
60,
141+
&caip2_id,
139142
0,
140143
&path_bytes,
141144
b"ecdsa",

pallets/dispenser/src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,11 @@ pub mod pallet {
295295
path.extend_from_slice(b"0x");
296296
path.extend_from_slice(hex::encode(requester.encode()).as_bytes());
297297

298+
// CAIP-2 chain ID (e.g., "eip155:1" for Ethereum mainnet)
299+
let caip2_id = alloc::format!("eip155:{}", tx.chain_id);
300+
298301
// Derive canonical request ID and compare with user-supplied one.
299-
let req_id = Self::generate_request_id(&pallet_acc, &rlp, 60, 0, &path, ECDSA, ETHEREUM, b"");
302+
let req_id = Self::generate_request_id(&pallet_acc, &rlp, &caip2_id, 0, &path, ECDSA, ETHEREUM, b"");
300303
ensure!(req_id == request_id, Error::<T>::InvalidRequestId);
301304
ensure!(
302305
UsedRequestIds::<T>::get(request_id).is_none(),
@@ -328,24 +331,22 @@ pub mod pallet {
328331
Preservation::Expendable,
329332
)?;
330333

331-
let explorer_schema = Vec::<u8>::new();
332-
let callback_schema =
334+
let output_deserialization_schema = Vec::<u8>::new();
335+
let respond_serialization_schema =
333336
serde_json::to_vec(&serde_json::json!("bool")).map_err(|_| Error::<T>::Serialization)?;
334337

335338
// Submit signing request to SigNet.
336339
pallet_signet::Pallet::<T>::sign_bidirectional(
337340
frame_system::RawOrigin::Signed(pallet_acc.clone()).into(),
338-
BoundedVec::<u8, ConstU32<65536>>::try_from(rlp).map_err(|_| Error::<T>::Serialization)?,
339-
60,
341+
BoundedVec::try_from(rlp).map_err(|_| Error::<T>::Serialization)?,
342+
BoundedVec::try_from(caip2_id.into_bytes()).map_err(|_| Error::<T>::Serialization)?,
340343
0,
341344
BoundedVec::try_from(path).map_err(|_| Error::<T>::Serialization)?,
342345
BoundedVec::try_from(ECDSA.to_vec()).map_err(|_| Error::<T>::Serialization)?,
343346
BoundedVec::try_from(ETHEREUM.to_vec()).map_err(|_| Error::<T>::Serialization)?,
344-
BoundedVec::try_from(Vec::new()).map_err(|_| Error::<T>::Serialization)?,
345-
pallet_signet::SerializationFormat::AbiJson,
346-
BoundedVec::try_from(explorer_schema).map_err(|_| Error::<T>::Serialization)?,
347-
pallet_signet::SerializationFormat::Borsh,
348-
BoundedVec::try_from(callback_schema).map_err(|_| Error::<T>::Serialization)?,
347+
BoundedVec::try_from(vec![]).map_err(|_| Error::<T>::Serialization)?,
348+
BoundedVec::try_from(output_deserialization_schema).map_err(|_| Error::<T>::Serialization)?,
349+
BoundedVec::try_from(respond_serialization_schema).map_err(|_| Error::<T>::Serialization)?,
349350
)?;
350351

351352
// Mark request ID as used and update tracked faucet balance.
@@ -426,7 +427,7 @@ pub mod pallet {
426427
/// Derive a deterministic request ID from the given parameters.
427428
///
428429
/// The ID is computed as:
429-
/// - Encode `(sender_ss58, transaction_data, slip44_chain_id, key_version,
430+
/// - Encode `(sender_ss58, transaction_data, caip2_id, key_version,
430431
/// path_str, algo_str, dest_str, params_str)` using Solidity's
431432
/// `abi_encode_packed`.
432433
/// - Apply `keccak256` to the result.
@@ -437,7 +438,7 @@ pub mod pallet {
437438
pub fn generate_request_id(
438439
sender: &T::AccountId,
439440
transaction_data: &[u8],
440-
slip44_chain_id: u32,
441+
caip2_id: &str,
441442
key_version: u32,
442443
path: &[u8],
443444
algo: &[u8],
@@ -458,7 +459,7 @@ pub mod pallet {
458459
let encoded = (
459460
sender_ss58.as_str(),
460461
transaction_data,
461-
slip44_chain_id,
462+
caip2_id,
462463
key_version,
463464
core::str::from_utf8(path).unwrap_or(""),
464465
core::str::from_utf8(algo).unwrap_or(""),

pallets/dispenser/src/tests/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ pub fn compute_request_id(
7676
s
7777
};
7878

79+
// CAIP-2 chain ID format
80+
let caip2_id = format!("eip155:{}", tx_params.chain_id);
81+
7982
let packed = (
8083
sender_ss58.as_str(),
8184
rlp_encoded.as_slice(),
82-
60u32,
85+
caip2_id.as_str(),
8386
0u32,
8487
path.as_str(),
8588
"ecdsa",

pallets/signet/src/benchmarks.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ mod benches {
145145
let serialized_transaction: BoundedVec<u8, ConstU32<MAX_TRANSACTION_LENGTH>> =
146146
BoundedVec::try_from(tx_bytes).expect("tx fits");
147147

148-
let slip44_chain_id: u32 = 60;
148+
let caip2_id: BoundedVec<u8, ConstU32<64>> =
149+
BoundedVec::try_from(b"eip155:11155111".to_vec()).expect("caip2 fits");
149150
let key_version: u32 = 1;
150151

151152
let path_vec = vec![1u8; MAX_PATH_LENGTH as usize];
@@ -159,31 +160,26 @@ mod benches {
159160
let params: BoundedVec<u8, ConstU32<MAX_PARAMS_LENGTH>> =
160161
BoundedVec::try_from(params_vec).expect("params fits");
161162

162-
let explorer_schema_vec = vec![6u8; MAX_SCHEMA_LENGTH as usize];
163-
let callback_schema_vec = vec![7u8; MAX_SCHEMA_LENGTH as usize];
163+
let output_schema_vec = vec![6u8; MAX_SCHEMA_LENGTH as usize];
164+
let respond_schema_vec = vec![7u8; MAX_SCHEMA_LENGTH as usize];
164165

165-
let explorer_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
166-
BoundedVec::try_from(explorer_schema_vec).expect("explorer schema fits");
167-
let callback_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
168-
BoundedVec::try_from(callback_schema_vec).expect("callback schema fits");
169-
170-
let explorer_deserialization_format = SerializationFormat::AbiJson;
171-
let callback_serialization_format = SerializationFormat::Borsh;
166+
let output_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
167+
BoundedVec::try_from(output_schema_vec).expect("output schema fits");
168+
let respond_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
169+
BoundedVec::try_from(respond_schema_vec).expect("respond schema fits");
172170

173171
#[extrinsic_call]
174172
sign_bidirectional(
175173
RawOrigin::Signed(requester.clone()),
176174
serialized_transaction,
177-
slip44_chain_id,
175+
caip2_id,
178176
key_version,
179177
path,
180178
algo,
181179
dest,
182180
params,
183-
explorer_deserialization_format,
184-
explorer_deserialization_schema,
185-
callback_serialization_format,
186-
callback_serialization_schema,
181+
output_deserialization_schema,
182+
respond_serialization_schema,
187183
);
188184
}
189185

pallets/signet/src/lib.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,19 @@ pub mod pallet {
169169
params: Vec<u8>,
170170
},
171171

172-
/// Sign-respond request event
172+
/// Sign bidirectional request event
173173
SignBidirectionalRequested {
174174
sender: T::AccountId,
175-
transaction_data: Vec<u8>,
176-
slip44_chain_id: u32,
175+
serialized_transaction: Vec<u8>,
176+
caip2_id: Vec<u8>,
177177
key_version: u32,
178178
deposit: BalanceOf<T>,
179179
path: Vec<u8>,
180180
algo: Vec<u8>,
181181
dest: Vec<u8>,
182182
params: Vec<u8>,
183-
explorer_deserialization_format: u8,
184-
explorer_deserialization_schema: Vec<u8>,
185-
callback_serialization_format: u8,
186-
callback_serialization_schema: Vec<u8>,
183+
output_deserialization_schema: Vec<u8>,
184+
respond_serialization_schema: Vec<u8>,
187185
},
188186

189187
/// Signature response event
@@ -200,7 +198,7 @@ pub mod pallet {
200198
error: Vec<u8>,
201199
},
202200

203-
/// Read response event
201+
/// Respond bidirectional event
204202
RespondBidirectionalEvent {
205203
request_id: [u8; 32],
206204
responder: T::AccountId,
@@ -367,16 +365,14 @@ pub mod pallet {
367365
pub fn sign_bidirectional(
368366
origin: OriginFor<T>,
369367
serialized_transaction: BoundedVec<u8, ConstU32<MAX_TRANSACTION_LENGTH>>,
370-
slip44_chain_id: u32,
368+
caip2_id: BoundedVec<u8, ConstU32<64>>,
371369
key_version: u32,
372370
path: BoundedVec<u8, ConstU32<MAX_PATH_LENGTH>>,
373371
algo: BoundedVec<u8, ConstU32<MAX_ALGO_LENGTH>>,
374372
dest: BoundedVec<u8, ConstU32<MAX_DEST_LENGTH>>,
375373
params: BoundedVec<u8, ConstU32<MAX_PARAMS_LENGTH>>,
376-
explorer_deserialization_format: SerializationFormat,
377-
explorer_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
378-
callback_serialization_format: SerializationFormat,
379-
callback_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
374+
output_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
375+
respond_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
380376
) -> DispatchResult {
381377
let requester = ensure_signed(origin)?;
382378

@@ -396,18 +392,16 @@ pub mod pallet {
396392
// Emit event
397393
Self::deposit_event(Event::SignBidirectionalRequested {
398394
sender: requester,
399-
transaction_data: serialized_transaction.to_vec(),
400-
slip44_chain_id,
395+
serialized_transaction: serialized_transaction.to_vec(),
396+
caip2_id: caip2_id.to_vec(),
401397
key_version,
402398
deposit,
403399
path: path.to_vec(),
404400
algo: algo.to_vec(),
405401
dest: dest.to_vec(),
406402
params: params.to_vec(),
407-
explorer_deserialization_format: explorer_deserialization_format as u8,
408-
explorer_deserialization_schema: explorer_deserialization_schema.to_vec(),
409-
callback_serialization_format: callback_serialization_format as u8,
410-
callback_serialization_schema: callback_serialization_schema.to_vec(),
403+
output_deserialization_schema: output_deserialization_schema.to_vec(),
404+
respond_serialization_schema: respond_serialization_schema.to_vec(),
411405
});
412406

413407
Ok(())

pallets/signet/src/tests/tests.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
utils::{bounded_array, bounded_chain_id, bounded_err, bounded_sig, bounded_u8, create_test_signature},
55
Balances, MockCaller, MockCallerPalletId, RuntimeEvent, RuntimeOrigin, Signet, System, Test,
66
},
7-
Error, ErrorResponse, Event, SerializationFormat,
7+
Error, ErrorResponse, Event,
88
};
99
use frame_support::traits::Currency;
1010
use frame_support::{assert_noop, assert_ok};
@@ -26,7 +26,7 @@ const WITHDRAW_AMOUNT: u128 = 5_000;
2626
const PALLET_INITIAL_BALANCE: u128 = 10_000;
2727
const WITHDRAW_TOO_MUCH_AMOUNT: u128 = 20_000;
2828

29-
const SLIP44_ETH: u32 = 60;
29+
const CAIP2_SEPOLIA: &[u8] = b"eip155:11155111";
3030

3131
const TEST_CHAIN_ID_BYTES: &[u8] = b"test-chain";
3232
const HYDRADX_CHAIN_ID_BYTES: &[u8] = b"hydradx:polkadot:0";
@@ -486,21 +486,19 @@ fn test_sign_bidirectional_works() {
486486
));
487487

488488
let tx_data = b"mock_transaction_data".to_vec();
489-
let slip44_chain_id = SLIP44_ETH;
489+
let caip2_id = CAIP2_SEPOLIA;
490490
let balance_before = Balances::free_balance(&requester);
491491

492492
assert_ok!(Signet::sign_bidirectional(
493493
RuntimeOrigin::signed(requester),
494494
bounded_u8::<65536>(tx_data.clone()),
495-
slip44_chain_id,
495+
bounded_u8::<64>(caip2_id.to_vec()),
496496
1,
497497
bounded_u8::<256>(b"path".to_vec()),
498498
bounded_u8::<32>(b"ecdsa".to_vec()),
499499
bounded_u8::<64>(b"callback".to_vec()),
500500
bounded_u8::<1024>(b"{}".to_vec()),
501-
SerializationFormat::AbiJson,
502501
bounded_u8::<4096>(b"schema1".to_vec()),
503-
SerializationFormat::Borsh,
504502
bounded_u8::<4096>(b"schema2".to_vec())
505503
));
506504

@@ -526,15 +524,13 @@ fn test_sign_bidirectional_empty_transaction_fails() {
526524
Signet::sign_bidirectional(
527525
RuntimeOrigin::signed(requester),
528526
bounded_u8::<65536>(vec![]),
529-
60,
527+
bounded_u8::<64>(CAIP2_SEPOLIA.to_vec()),
530528
1,
531529
bounded_u8::<256>(b"path".to_vec()),
532530
bounded_u8::<32>(b"algo".to_vec()),
533531
bounded_u8::<64>(b"dest".to_vec()),
534532
bounded_u8::<1024>(b"params".to_vec()),
535-
SerializationFormat::Borsh,
536533
bounded_u8::<4096>(vec![]),
537-
SerializationFormat::Borsh,
538534
bounded_u8::<4096>(vec![])
539535
),
540536
Error::<Test>::InvalidTransaction
@@ -667,7 +663,7 @@ fn test_respond_error_batch() {
667663
}
668664

669665
#[test]
670-
fn respond_bidirectional() {
666+
fn test_respond_bidirectional() {
671667
new_test_ext().execute_with(|| {
672668
let responder = ADMIN;
673669
let request_id = [99u8; 32];

0 commit comments

Comments
 (0)