Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion pallets/dispenser/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
));

let caller: T::AccountId = whitelisted_caller();
let treasury = T::FeeDestination::get();

Check warning on line 94 in pallets/dispenser/src/benchmarking.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `treasury`

let amount: u128 = 100_000;
let to: [u8; 20] = [1u8; 20];
Expand Down Expand Up @@ -132,10 +132,13 @@
s.into_bytes()
};

// CAIP-2 chain ID format
let caip2_id = alloc::format!("eip155:{}", tx.chain_id);

let req_id = Pallet::<T>::generate_request_id(
&Pallet::<T>::account_id(),
&rlp,
60,
&caip2_id,
0,
&path_bytes,
b"ecdsa",
Expand Down
27 changes: 14 additions & 13 deletions pallets/dispenser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::pallet_prelude::*;
use frame_support::traits::fungibles::Inspect;
use frame_support::traits::{fungibles::Mutate, tokens::Preservation, Currency};

Check warning on line 22 in pallets/dispenser/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Currency`

Check warning on line 22 in pallets/dispenser/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Currency`

Check warning on line 22 in pallets/dispenser/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Currency`
use frame_support::PalletId;
use frame_support::{dispatch::DispatchResult, BoundedVec};
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -295,8 +295,11 @@
path.extend_from_slice(b"0x");
path.extend_from_slice(hex::encode(requester.encode()).as_bytes());

// CAIP-2 chain ID (e.g., "eip155:1" for Ethereum mainnet)
let caip2_id = alloc::format!("eip155:{}", tx.chain_id);

// Derive canonical request ID and compare with user-supplied one.
let req_id = Self::generate_request_id(&pallet_acc, &rlp, 60, 0, &path, ECDSA, ETHEREUM, b"");
let req_id = Self::generate_request_id(&pallet_acc, &rlp, &caip2_id, 0, &path, ECDSA, ETHEREUM, b"");
ensure!(req_id == request_id, Error::<T>::InvalidRequestId);
ensure!(
UsedRequestIds::<T>::get(request_id).is_none(),
Expand Down Expand Up @@ -328,24 +331,22 @@
Preservation::Expendable,
)?;

let explorer_schema = Vec::<u8>::new();
let callback_schema =
let output_deserialization_schema = Vec::<u8>::new();
let respond_serialization_schema =
serde_json::to_vec(&serde_json::json!("bool")).map_err(|_| Error::<T>::Serialization)?;

// Submit signing request to SigNet.
pallet_signet::Pallet::<T>::sign_bidirectional(
frame_system::RawOrigin::Signed(pallet_acc.clone()).into(),
BoundedVec::<u8, ConstU32<65536>>::try_from(rlp).map_err(|_| Error::<T>::Serialization)?,
60,
BoundedVec::try_from(rlp).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(caip2_id.into_bytes()).map_err(|_| Error::<T>::Serialization)?,
0,
BoundedVec::try_from(path).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(ECDSA.to_vec()).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(ETHEREUM.to_vec()).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(Vec::new()).map_err(|_| Error::<T>::Serialization)?,
pallet_signet::SerializationFormat::AbiJson,
BoundedVec::try_from(explorer_schema).map_err(|_| Error::<T>::Serialization)?,
pallet_signet::SerializationFormat::Borsh,
BoundedVec::try_from(callback_schema).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(vec![]).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(output_deserialization_schema).map_err(|_| Error::<T>::Serialization)?,
BoundedVec::try_from(respond_serialization_schema).map_err(|_| Error::<T>::Serialization)?,
)?;

// Mark request ID as used and update tracked faucet balance.
Expand Down Expand Up @@ -426,7 +427,7 @@
/// Derive a deterministic request ID from the given parameters.
///
/// The ID is computed as:
/// - Encode `(sender_ss58, transaction_data, slip44_chain_id, key_version,
/// - Encode `(sender_ss58, transaction_data, caip2_id, key_version,
/// path_str, algo_str, dest_str, params_str)` using Solidity's
/// `abi_encode_packed`.
/// - Apply `keccak256` to the result.
Expand All @@ -437,7 +438,7 @@
pub fn generate_request_id(
sender: &T::AccountId,
transaction_data: &[u8],
slip44_chain_id: u32,
caip2_id: &str,
key_version: u32,
path: &[u8],
algo: &[u8],
Expand All @@ -458,7 +459,7 @@
let encoded = (
sender_ss58.as_str(),
transaction_data,
slip44_chain_id,
caip2_id,
key_version,
core::str::from_utf8(path).unwrap_or(""),
core::str::from_utf8(algo).unwrap_or(""),
Expand Down
5 changes: 4 additions & 1 deletion pallets/dispenser/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ pub fn compute_request_id(
s
};

// CAIP-2 chain ID format
let caip2_id = format!("eip155:{}", tx_params.chain_id);

let packed = (
sender_ss58.as_str(),
rlp_encoded.as_slice(),
60u32,
caip2_id.as_str(),
0u32,
path.as_str(),
"ecdsa",
Expand Down
26 changes: 11 additions & 15 deletions pallets/signet/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "runtime-benchmarks")]

Check warning on line 1 in pallets/signet/src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / build

duplicated attribute

use super::*;
use frame_benchmarking::v2::*;
Expand All @@ -12,7 +12,7 @@
BoundedVec::try_from(v).expect("bench-chain fits MaxChainIdLength")
}

#[benchmarks(where T: Config)]

Check warning on line 15 in pallets/signet/src/benchmarks.rs

View workflow job for this annotation

GitHub Actions / build

bound is defined in more than one place
mod benches {
use super::*;

Expand Down Expand Up @@ -145,7 +145,8 @@
let serialized_transaction: BoundedVec<u8, ConstU32<MAX_TRANSACTION_LENGTH>> =
BoundedVec::try_from(tx_bytes).expect("tx fits");

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

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

let explorer_schema_vec = vec![6u8; MAX_SCHEMA_LENGTH as usize];
let callback_schema_vec = vec![7u8; MAX_SCHEMA_LENGTH as usize];
let output_schema_vec = vec![6u8; MAX_SCHEMA_LENGTH as usize];
let respond_schema_vec = vec![7u8; MAX_SCHEMA_LENGTH as usize];

let explorer_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
BoundedVec::try_from(explorer_schema_vec).expect("explorer schema fits");
let callback_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
BoundedVec::try_from(callback_schema_vec).expect("callback schema fits");

let explorer_deserialization_format = SerializationFormat::AbiJson;
let callback_serialization_format = SerializationFormat::Borsh;
let output_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
BoundedVec::try_from(output_schema_vec).expect("output schema fits");
let respond_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>> =
BoundedVec::try_from(respond_schema_vec).expect("respond schema fits");

#[extrinsic_call]
sign_bidirectional(
RawOrigin::Signed(requester.clone()),
serialized_transaction,
slip44_chain_id,
caip2_id,
key_version,
path,
algo,
dest,
params,
explorer_deserialization_format,
explorer_deserialization_schema,
callback_serialization_format,
callback_serialization_schema,
output_deserialization_schema,
respond_serialization_schema,
);
}

Expand Down
32 changes: 13 additions & 19 deletions pallets/signet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
#[cfg(test)]
pub mod tests;

#[frame_support::pallet]

Check warning on line 47 in pallets/signet/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

this function has too many arguments (10/7)
pub mod pallet {
use super::*;

#[pallet::pallet]

Check warning on line 51 in pallets/signet/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

using `map_err` over `inspect_err`
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down Expand Up @@ -169,21 +169,19 @@
params: Vec<u8>,
},

/// Sign-respond request event
/// Sign bidirectional request event
SignBidirectionalRequested {
sender: T::AccountId,
transaction_data: Vec<u8>,
slip44_chain_id: u32,
serialized_transaction: Vec<u8>,
caip2_id: Vec<u8>,
key_version: u32,
deposit: BalanceOf<T>,
path: Vec<u8>,
algo: Vec<u8>,
dest: Vec<u8>,
params: Vec<u8>,
explorer_deserialization_format: u8,
explorer_deserialization_schema: Vec<u8>,
callback_serialization_format: u8,
callback_serialization_schema: Vec<u8>,
output_deserialization_schema: Vec<u8>,
respond_serialization_schema: Vec<u8>,
},

/// Signature response event
Expand All @@ -200,7 +198,7 @@
error: Vec<u8>,
},

/// Read response event
/// Respond bidirectional event
RespondBidirectionalEvent {
request_id: [u8; 32],
responder: T::AccountId,
Expand Down Expand Up @@ -243,7 +241,7 @@
// Extrinsics
// ========================================

#[pallet::call]

Check warning on line 244 in pallets/signet/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

this function has too many arguments (9/7)
impl<T: Config> Pallet<T> {
/// Initialize the pallet with admin, deposit, and chain ID
#[pallet::call_index(0)]
Expand Down Expand Up @@ -284,7 +282,7 @@
ensure!(who == admin, Error::<T>::Unauthorized);

ensure!(
new_deposit < T::MaxSignatureDeposit::get().into(),

Check warning on line 285 in pallets/signet/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

useless conversion to the same type: `<<T as pallet::Config>::Currency as frame_support::traits::Currency<<T as frame_system::Config>::AccountId>>::Balance`
Error::<T>::MaxDepositExceeded
);

Expand Down Expand Up @@ -367,16 +365,14 @@
pub fn sign_bidirectional(
origin: OriginFor<T>,
serialized_transaction: BoundedVec<u8, ConstU32<MAX_TRANSACTION_LENGTH>>,
slip44_chain_id: u32,
caip2_id: BoundedVec<u8, ConstU32<64>>,
key_version: u32,
path: BoundedVec<u8, ConstU32<MAX_PATH_LENGTH>>,
algo: BoundedVec<u8, ConstU32<MAX_ALGO_LENGTH>>,
dest: BoundedVec<u8, ConstU32<MAX_DEST_LENGTH>>,
params: BoundedVec<u8, ConstU32<MAX_PARAMS_LENGTH>>,
explorer_deserialization_format: SerializationFormat,
explorer_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
callback_serialization_format: SerializationFormat,
callback_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
output_deserialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
respond_serialization_schema: BoundedVec<u8, ConstU32<MAX_SCHEMA_LENGTH>>,
) -> DispatchResult {
let requester = ensure_signed(origin)?;

Expand All @@ -396,18 +392,16 @@
// Emit event
Self::deposit_event(Event::SignBidirectionalRequested {
sender: requester,
transaction_data: serialized_transaction.to_vec(),
slip44_chain_id,
serialized_transaction: serialized_transaction.to_vec(),
caip2_id: caip2_id.to_vec(),
key_version,
deposit,
path: path.to_vec(),
algo: algo.to_vec(),
dest: dest.to_vec(),
params: params.to_vec(),
explorer_deserialization_format: explorer_deserialization_format as u8,
explorer_deserialization_schema: explorer_deserialization_schema.to_vec(),
callback_serialization_format: callback_serialization_format as u8,
callback_serialization_schema: callback_serialization_schema.to_vec(),
output_deserialization_schema: output_deserialization_schema.to_vec(),
respond_serialization_schema: respond_serialization_schema.to_vec(),
});

Ok(())
Expand Down Expand Up @@ -504,7 +498,7 @@
///
/// # Returns
/// RLP-encoded transaction data with EIP-2718 type prefix (0x02 for EIP-1559)
pub fn build_evm_tx(

Check warning on line 501 in pallets/signet/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

this function has too many arguments (10/7)
origin: OriginFor<T>,
to_address: Option<H160>,
value: u128,
Expand Down
16 changes: 6 additions & 10 deletions pallets/signet/src/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
utils::{bounded_array, bounded_chain_id, bounded_err, bounded_sig, bounded_u8, create_test_signature},
Balances, MockCaller, MockCallerPalletId, RuntimeEvent, RuntimeOrigin, Signet, System, Test,
},
Error, ErrorResponse, Event, SerializationFormat,
Error, ErrorResponse, Event,
};
use frame_support::traits::Currency;
use frame_support::{assert_noop, assert_ok};
Expand All @@ -26,7 +26,7 @@
const PALLET_INITIAL_BALANCE: u128 = 10_000;
const WITHDRAW_TOO_MUCH_AMOUNT: u128 = 20_000;

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

const TEST_CHAIN_ID_BYTES: &[u8] = b"test-chain";
const HYDRADX_CHAIN_ID_BYTES: &[u8] = b"hydradx:polkadot:0";
Expand All @@ -38,7 +38,7 @@
/// Initialize Signet with the default "test-chain" chain id.
fn init_signet(admin: u64, deposit: u128) {
assert_ok!(Signet::initialize(
RuntimeOrigin::root().into(),

Check warning on line 41 in pallets/signet/src/tests/tests.rs

View workflow job for this annotation

GitHub Actions / build

useless conversion to the same type: `tests::RuntimeOrigin`
admin,
deposit,
bounded_chain_id(TEST_CHAIN_ID_BYTES.to_vec()),
Expand Down Expand Up @@ -66,7 +66,7 @@
assert_eq!(Signet::admin(), None);

assert_ok!(Signet::initialize(
RuntimeOrigin::root().into(),

Check warning on line 69 in pallets/signet/src/tests/tests.rs

View workflow job for this annotation

GitHub Actions / build

useless conversion to the same type: `tests::RuntimeOrigin`
admin_account,
deposit,
chain_id.clone()
Expand Down Expand Up @@ -486,21 +486,19 @@
));

let tx_data = b"mock_transaction_data".to_vec();
let slip44_chain_id = SLIP44_ETH;
let caip2_id = CAIP2_SEPOLIA;
let balance_before = Balances::free_balance(&requester);

assert_ok!(Signet::sign_bidirectional(
RuntimeOrigin::signed(requester),
bounded_u8::<65536>(tx_data.clone()),
slip44_chain_id,
bounded_u8::<64>(caip2_id.to_vec()),
1,
bounded_u8::<256>(b"path".to_vec()),
bounded_u8::<32>(b"ecdsa".to_vec()),
bounded_u8::<64>(b"callback".to_vec()),
bounded_u8::<1024>(b"{}".to_vec()),
SerializationFormat::AbiJson,
bounded_u8::<4096>(b"schema1".to_vec()),
SerializationFormat::Borsh,
bounded_u8::<4096>(b"schema2".to_vec())
));

Expand All @@ -526,15 +524,13 @@
Signet::sign_bidirectional(
RuntimeOrigin::signed(requester),
bounded_u8::<65536>(vec![]),
60,
bounded_u8::<64>(CAIP2_SEPOLIA.to_vec()),
1,
bounded_u8::<256>(b"path".to_vec()),
bounded_u8::<32>(b"algo".to_vec()),
bounded_u8::<64>(b"dest".to_vec()),
bounded_u8::<1024>(b"params".to_vec()),
SerializationFormat::Borsh,
bounded_u8::<4096>(vec![]),
SerializationFormat::Borsh,
bounded_u8::<4096>(vec![])
),
Error::<Test>::InvalidTransaction
Expand Down Expand Up @@ -667,7 +663,7 @@
}

#[test]
fn respond_bidirectional() {
fn test_respond_bidirectional() {
new_test_ext().execute_with(|| {
let responder = ADMIN;
let request_id = [99u8; 32];
Expand Down
Loading