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

feat: evm permit tx tags #816

Merged
merged 5 commits into from
Apr 30, 2024
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.21.0"
version = "1.21.1"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
13 changes: 8 additions & 5 deletions integration-tests/src/evm_permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,13 @@ fn evm_permit_should_validate_unsigned_correctly() {
r: H256::from(rs.r.b32()),
s: H256::from(rs.s.b32()),
};

let tag: Vec<u8> = ("EVMPermit", (U256::zero(), user_evm_address)).encode();
assert_eq!(
MultiTransactionPayment::validate_unsigned(TransactionSource::External, &call),
Ok(ValidTransaction {
priority: 0,
requires: vec![],
provides: vec![],
provides: vec![tag],
longevity: 64,
propagate: true,
})
Expand Down Expand Up @@ -611,12 +611,13 @@ fn evm_permit_set_currency_dispatch_should_pay_evm_fee_in_chosen_currency() {
s: H256::from(rs.s.b32()),
};

let tag: Vec<u8> = ("EVMPermit", (U256::zero(), user_evm_address)).encode();
assert_eq!(
MultiTransactionPayment::validate_unsigned(TransactionSource::External, &call),
Ok(ValidTransaction {
priority: 0,
requires: vec![],
provides: vec![],
provides: vec![tag],
longevity: 64,
propagate: true,
})
Expand Down Expand Up @@ -735,12 +736,13 @@ fn evm_permit_dispatch_flow_should_work() {
s: H256::from(rs.s.b32()),
};

let tag: Vec<u8> = ("EVMPermit", (U256::zero(), user_evm_address)).encode();
assert_eq!(
MultiTransactionPayment::validate_unsigned(TransactionSource::External, &call),
Ok(ValidTransaction {
priority: 0,
requires: vec![],
provides: vec![],
provides: vec![tag],
longevity: 64,
propagate: true,
})
Expand Down Expand Up @@ -865,12 +867,13 @@ fn evm_permit_should_fail_when_replayed() {
s: H256::from(rs.s.b32()),
};

let tag: Vec<u8> = ("EVMPermit", (U256::zero(), user_evm_address)).encode();
assert_eq!(
MultiTransactionPayment::validate_unsigned(TransactionSource::External, &call),
Ok(ValidTransaction {
priority: 0,
requires: vec![],
provides: vec![],
provides: vec![tag],
longevity: 64,
propagate: true,
})
Expand Down
2 changes: 1 addition & 1 deletion pallets/transaction-multi-payment/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-transaction-multi-payment"
version = "10.0.0"
version = "10.0.1"
description = "Transaction multi currency payment support module"
authors = ["GalacticCoucil"]
edition = "2021"
Expand Down
2 changes: 2 additions & 0 deletions pallets/transaction-multi-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,10 @@ pub mod pallet {
Err(e) => TransactionOutcome::Rollback(Err(e.error)),
}
});
let nonce = T::EvmPermit::permit_nonce(*from);
match result {
Ok(()) => ValidTransaction::with_tag_prefix("EVMPermit")
.and_provides((nonce, from))
.priority(0)
.longevity(64)
.propagate(true)
Expand Down
4 changes: 4 additions & 0 deletions pallets/transaction-multi-payment/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,8 @@ impl EVMPermit for PermitDispatchHandler {
fn dispatch_weight(_gas_limit: u64) -> Weight {
todo!()
}

fn permit_nonce(_account: H160) -> U256 {
U256::default()
}
}
6 changes: 6 additions & 0 deletions pallets/transaction-multi-payment/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub trait EVMPermit {
fn gas_price() -> (U256, Weight);

fn dispatch_weight(gas_limit: u64) -> Weight;

fn permit_nonce(account: H160) -> U256;
}

impl EVMPermit for () {
Expand Down Expand Up @@ -83,4 +85,8 @@ impl EVMPermit for () {
fn dispatch_weight(_gas_limit: u64) -> Weight {
Weight::zero()
}

fn permit_nonce(_account: H160) -> U256 {
U256::default()
}
}
2 changes: 1 addition & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "230.0.0"
version = "231.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down
4 changes: 4 additions & 0 deletions runtime/hydradx/src/evm/permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,8 @@ where
let without_base_extrinsic_weight = true;
<R as pallet_evm::Config>::GasWeightMapping::gas_to_weight(gas_limit, without_base_extrinsic_weight)
}

fn permit_nonce(account: H160) -> U256 {
NoncesStorage::get(account)
}
}
2 changes: 1 addition & 1 deletion runtime/hydradx/src/evm/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub const BN_ADD: H160 = H160(hex!("0000000000000000000000000000000000000006"));
pub const BN_MUL: H160 = H160(hex!("0000000000000000000000000000000000000007"));
pub const BN_PAIRING: H160 = H160(hex!("0000000000000000000000000000000000000008"));
pub const BLAKE2F: H160 = H160(hex!("0000000000000000000000000000000000000009"));
pub const CALLPERMIT: H160 = H160(hex!("0000000000000000000000000000000000000010"));
pub const CALLPERMIT: H160 = H160(hex!("000000000000000000000000000000000000080a"));

pub const ETH_PRECOMPILE_END: H160 = BLAKE2F;

Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("hydradx"),
impl_name: create_runtime_str!("hydradx"),
authoring_version: 1,
spec_version: 230,
spec_version: 231,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading