diff --git a/Cargo.lock b/Cargo.lock index e39665fd3..61ad260a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2358,7 +2358,7 @@ checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "async-trait", "fp-storage", @@ -2370,7 +2370,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "async-trait", "fp-consensus", @@ -2386,7 +2386,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "async-trait", "ethereum", @@ -2416,7 +2416,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "fc-db", "fc-storage", @@ -2439,7 +2439,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "ethereum-types", @@ -2493,7 +2493,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "ethereum-types", @@ -2508,7 +2508,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "ethereum-types", @@ -2691,7 +2691,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "hex", "impl-serde", @@ -2710,7 +2710,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "parity-scale-codec", @@ -2721,7 +2721,7 @@ dependencies = [ [[package]] name = "fp-dynamic-fee" version = "1.0.0" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "async-trait", "sp-core", @@ -2731,7 +2731,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "ethereum-types", @@ -2743,7 +2743,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "evm", "frame-support", @@ -2758,7 +2758,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "ethereum-types", @@ -2774,7 +2774,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "frame-support", "parity-scale-codec", @@ -2786,7 +2786,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "parity-scale-codec", "serde", @@ -6059,7 +6059,7 @@ dependencies = [ [[package]] name = "pallet-base-fee" version = "1.0.0" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "fp-evm", "frame-support", @@ -6141,7 +6141,7 @@ dependencies = [ [[package]] name = "pallet-dynamic-fee" version = "4.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "fp-dynamic-fee", "fp-evm", @@ -6156,7 +6156,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "ethereum", "ethereum-types", @@ -6178,7 +6178,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "environmental", "evm", @@ -6201,7 +6201,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "frame-support", "frame-system", @@ -6212,7 +6212,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "fp-evm", "num", @@ -6221,7 +6221,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "fp-evm", "tiny-keccak", @@ -6230,7 +6230,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "fp-evm", "ripemd", @@ -6262,7 +6262,7 @@ dependencies = [ [[package]] name = "pallet-hotfix-sufficients" version = "1.0.0" -source = "git+https://github.com/gztensor/frontier?rev=b9c606f9#b9c606f9baac5f3111f73c3bb857aa6ea862d7b8" +source = "git+https://github.com/opentensor/frontier?rev=635bdac882#635bdac882333afed827053f31ef56ab739f7a2e" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index 132533d80..00a5734a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -166,32 +166,32 @@ sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk.git", tag substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false } # Frontier -fp-evm = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fp-rpc = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fp-self-contained = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false, features = [ +fp-evm = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fp-rpc = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fp-self-contained = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false, features = [ "serde", ] } -fp-account = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-storage = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-db = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-consensus = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fp-consensus = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fp-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-api = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-rpc = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-rpc-core = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -fc-mapping-sync = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } +fp-account = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-storage = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-db = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-consensus = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fp-consensus = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fp-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-api = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-rpc-core = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +fc-mapping-sync = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } # Frontier FRAME -pallet-base-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-ethereum = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-evm = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-evm-chain-id = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-evm-precompile-modexp = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-evm-precompile-sha3fips = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-evm-precompile-simple = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } -pallet-hotfix-sufficients = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false } +pallet-base-fee = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-ethereum = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-evm = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-evm-chain-id = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } +pallet-hotfix-sufficients = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false } #DRAND pallet-drand = { path = "pallets/drand", default-features = false } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 77fc9415e..952bb6e53 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1194,37 +1194,57 @@ parameter_types! { /// The difference between EVM decimals and Substrate decimals. /// Substrate balances has 9 decimals, while EVM has 18, so the /// difference factor is 9 decimals, or 10^9 -const EVM_DECIMALS_FACTOR: u64 = 1_000_000_000_u64; +const EVM_TO_SUBSTRATE_DECIMALS: u64 = 1_000_000_000_u64; pub struct SubtensorEvmBalanceConverter; impl BalanceConverter for SubtensorEvmBalanceConverter { /// Convert from Substrate balance (u64) to EVM balance (U256) fn into_evm_balance(value: U256) -> Option { - value - .checked_mul(U256::from(EVM_DECIMALS_FACTOR)) - .and_then(|evm_value| { - // Ensure the result fits within the maximum U256 value - if evm_value <= U256::MAX { - Some(evm_value) - } else { - None - } - }) + if let Some(evm_value) = value.checked_mul(U256::from(EVM_TO_SUBSTRATE_DECIMALS)) { + // Ensure the result fits within the maximum U256 value + if evm_value <= U256::MAX { + Some(evm_value) + } else { + // Log value too large + log::debug!( + "SubtensorEvmBalanceConverter::into_evm_balance( {:?} ) larger than U256::MAX", + value + ); + None + } + } else { + // Log overflow + log::debug!( + "SubtensorEvmBalanceConverter::into_evm_balance( {:?} ) overflow", + value + ); + None + } } /// Convert from EVM balance (U256) to Substrate balance (u64) fn into_substrate_balance(value: U256) -> Option { - value - .checked_div(U256::from(EVM_DECIMALS_FACTOR)) - .and_then(|substrate_value| { - // Ensure the result fits within the TAO balance type (u64) - if substrate_value <= U256::from(u64::MAX) { - Some(substrate_value) - } else { - None - } - }) + if let Some(substrate_value) = value.checked_div(U256::from(EVM_TO_SUBSTRATE_DECIMALS)) { + // Ensure the result fits within the TAO balance type (u64) + if substrate_value <= U256::from(u64::MAX) { + Some(substrate_value) + } else { + // Log value too large + log::debug!( + "SubtensorEvmBalanceConverter::into_substrate_balance( {:?} ) larger than u64::MAX", + value + ); + None + } + } else { + // Log overflow + log::debug!( + "SubtensorEvmBalanceConverter::into_substrate_balance( {:?} ) overflow", + value + ); + None + } } } @@ -2141,7 +2161,7 @@ fn test_into_substrate_balance_valid() { #[test] fn test_into_substrate_balance_large_value() { // Maximum valid balance for u64 - let evm_balance = U256::from(u64::MAX) * U256::from(EVM_DECIMALS_FACTOR); // Max u64 TAO in EVM + let evm_balance = U256::from(u64::MAX) * U256::from(EVM_TO_SUBSTRATE_DECIMALS); // Max u64 TAO in EVM let expected_substrate_balance = U256::from(u64::MAX); let result = SubtensorEvmBalanceConverter::into_substrate_balance(evm_balance); @@ -2151,7 +2171,8 @@ fn test_into_substrate_balance_large_value() { #[test] fn test_into_substrate_balance_exceeds_u64() { // EVM balance that exceeds u64 after conversion - let evm_balance = (U256::from(u64::MAX) + U256::from(1)) * U256::from(EVM_DECIMALS_FACTOR); + let evm_balance = + (U256::from(u64::MAX) + U256::from(1)) * U256::from(EVM_TO_SUBSTRATE_DECIMALS); let result = SubtensorEvmBalanceConverter::into_substrate_balance(evm_balance); assert_eq!(result, None); // Exceeds u64, should return None @@ -2191,7 +2212,7 @@ fn test_into_evm_balance_valid() { fn test_into_evm_balance_overflow() { // Substrate balance larger than u64::MAX but valid within U256 let substrate_balance = U256::from(u64::MAX) + U256::from(1); // Large balance - let expected_evm_balance = substrate_balance * U256::from(EVM_DECIMALS_FACTOR); + let expected_evm_balance = substrate_balance * U256::from(EVM_TO_SUBSTRATE_DECIMALS); let result = SubtensorEvmBalanceConverter::into_evm_balance(substrate_balance); assert_eq!(result, Some(expected_evm_balance)); // Should return the scaled value