Compare commits

..

No commits in common. "main" and "ghost-exodus" have entirely different histories.

18 changed files with 315 additions and 306 deletions

4
Cargo.lock generated
View File

@ -1195,7 +1195,7 @@ dependencies = [
[[package]]
name = "casper-runtime"
version = "4.0.11"
version = "4.0.10"
dependencies = [
"casper-runtime-constants",
"frame-benchmarking",
@ -4109,7 +4109,7 @@ dependencies = [
[[package]]
name = "ghost-weaver"
version = "0.0.10"
version = "0.0.8"
dependencies = [
"frame-benchmarking",
"frame-support",

View File

@ -346,7 +346,7 @@ sha256sum /etc/ghost/casper.json
You should see:
```
4645c7d39a64424d823f659d408070f8c90426117e7af147b0360697b2db7f4f /etc/ghost/casper.json
9da6045ed6d4fd844e3939573b31c013d0e564e542029330faa6d978cb4a915a
```
Create running `ghost-node` service that starts on system boot using `--unit-file` flag.

View File

@ -41,7 +41,6 @@ use ghost_networks::{
NetworkData, NetworkDataBasicHandler, NetworkDataInspectHandler, NetworkDataMutateHandler,
NetworkType,
};
use ghost_traits::evictor::StakingEvictor;
use ghost_traits::exposure::ExposureListener;
pub mod migrations;
@ -310,7 +309,6 @@ pub mod pallet {
>;
type DisabledValidators: DisabledValidators;
type ExposureListener: ExposureListener<BalanceOf<Self>, Self::AccountId>;
type StakingEvictor: StakingEvictor<Self::AccountId>;
#[pallet::constant]
type MaxAuthorities: Get<u32>;
@ -1457,15 +1455,7 @@ impl<T: Config> Pallet<T> {
let authority_index = index as AuthIndex;
if offence_bitmap.exists(&authority_index) {
weight.saturating_accrue(T::DbWeight::get().reads(2));
if let Some(account_id) = T::ExposureListener::get_account_by_index(index) {
weight.saturating_accrue(T::DbWeight::get().reads(1));
if T::StakingEvictor::try_evict_validator(&account_id) {
weight.saturating_accrue(T::DbWeight::get().writes(2));
}
}
weight.saturating_accrue(T::DbWeight::get().reads(1));
if let Some(full_id) = <T::ValidatorSet as ValidatorSetWithIdentification<
T::AccountId,
>>::IdentificationOf::convert(id.clone())
@ -1647,7 +1637,7 @@ impl<Offender: Clone> Offence<Offender> for SlowClapOffence<Offender> {
missed_percent.saturating_mul(Perbill::from_rational(1, offenders_count))
}
OffenceType::CommitmentOffence => offenders_count
.checked_sub(Perbill::from_percent(9).mul_floor(self.validator_set_count))
.checked_sub(Perbill::from_percent(9).mul_ceil(self.validator_set_count))
.map(|threshold| {
Perbill::from_rational(threshold.saturating_mul(4), self.validator_set_count)
.square()

View File

@ -5,7 +5,6 @@ use frame_support::{
traits::{ConstU32, ConstU64},
};
use frame_system::EnsureRoot;
use ghost_traits::evictor::StakingEvictor;
use pallet_session::historical as pallet_session_historical;
use sp_runtime::{
curve::PiecewiseLinear,
@ -37,7 +36,6 @@ frame_support::construct_runtime!(
);
parameter_types! {
pub static EvicatedValidators: Vec<u64> = vec![];
pub static FixedValidators: Vec<u64> = vec![0, 1, 2, 3];
}
@ -174,25 +172,6 @@ impl pallet_balances::Config for Runtime {
type Balance = u64;
pub struct TestStakingEvictor;
impl StakingEvictor<u64> for TestStakingEvictor {
fn try_evict_validator(who: &u64) -> bool {
if !FixedValidators::get().contains(who) {
return false;
}
let mut evicted_validators = EvicatedValidators::get();
match evicted_validators.iter().position(|x| x == who) {
Some(_) => false,
None => {
evicted_validators.push(*who);
EvicatedValidators::set(evicted_validators);
true
}
}
}
}
pub struct TestExposureListener;
impl ExposureListener<Balance, u64> for TestExposureListener
where
@ -238,7 +217,6 @@ impl Config for Runtime {
type ReportUnresponsiveness = OffenceHandler;
type DisabledValidators = Session;
type ExposureListener = TestExposureListener;
type StakingEvictor = TestStakingEvictor;
type MaxAuthorities = ConstU32<5>;
type ApplauseThreshold = ConstU32<500_000_000>;

View File

@ -1691,40 +1691,6 @@ fn migration_from_v2_to_v3_works_fine() {
});
}
#[test]
fn validators_are_evicted_during_offence() {
let (network_id, _, _) = generate_unique_hash(None, None, None, None, None);
new_test_ext().execute_with(|| {
let session_index = advance_session_and_get_index();
prepare_evm_network(None, None);
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
System::set_block_number(5 * EpochDuration::get() / 2);
let last_stored_block = 69;
for i in 0..3 {
assert_ok!(do_block_commitment(
session_index,
network_id,
i,
last_stored_block,
));
}
assert_eq!(EvicatedValidators::get().len(), 0);
let current_block = SlowClap::current_block_number();
SlowClap::on_initialize(current_block);
System::assert_has_event(RuntimeEvent::SlowClap(
crate::Event::SomeAuthoritiesDelayed {
delayed: vec![(3, 3)],
},
));
assert_eq!(EvicatedValidators::get().len(), 1);
});
}
fn assert_clapped_amount(
session_index: &SessionIndex,
unique_hash: &H256,

View File

@ -1,3 +0,0 @@
pub trait StakingEvictor<AccountId> {
fn try_evict_validator(who: &AccountId) -> bool;
}

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-weaver"
version = "0.0.10"
version = "0.0.8"
description = "Weaving a secure cryptographic tapestry across different external chains."
license.workspace = true
authors.workspace = true

View File

@ -8,8 +8,7 @@ use sp_std::vec;
use ghost_helpers::networks::NetworkDataBuilder;
fn prepare_pallet<T: Config>(
authorities_len: u32,
maybe_network_id: Option<u64>,
authorities_len: u32
) -> (NetworkIdOf<T>, T::AuthorityId, AuthIndex) {
let authority = T::AuthorityId::generate_pair(None);
let authorities = vec![authority.clone(); authorities_len as usize];
@ -19,9 +18,7 @@ fn prepare_pallet<T: Config>(
Authorities::<T>::put(bounded_authorities);
let network_id_u64 = maybe_network_id.unwrap_or_default();
let network_id: NetworkIdOf<T> = network_id_u64.unique_saturated_into();
let network_id = NetworkIdOf::<T>::default();
let network_data = NetworkDataBuilder::default()
.with_network_type(NetworkType::Utxo)
.with_gatekeeper(
@ -45,7 +42,7 @@ mod benchmarks {
fn extend_warp(
a: Linear<1, { T::MaxAuthorities::get() as u32 }>,
) -> Result<(), BenchmarkError> {
let (network_id, authority, authority_index) = prepare_pallet::<T>(a, None);
let (network_id, authority, authority_index) = prepare_pallet::<T>(a);
TapestryDrafts::<T>::remove(&network_id);
@ -76,7 +73,7 @@ mod benchmarks {
let next_session = weaving_session + 1;
let root_hash = H256::repeat_byte(0x69);
let (network_id, authority, authority_index) = prepare_pallet::<T>(a, None);
let (network_id, authority, authority_index) = prepare_pallet::<T>(a);
let tapestry_key = (network_id, weaving_session, next_session, root_hash);
TapestryStrands::<T>::mutate(&tapestry_key, |tapestry| {
@ -142,7 +139,7 @@ mod benchmarks {
) -> Result<(), BenchmarkError> {
let session = 69;
let max_history_depth = a as usize;
let (network_id, _, _) = prepare_pallet::<T>(1, None);
let (network_id, _, _) = prepare_pallet::<T>(1);
// Real world tx at block #481838
// Block https://blockstream.info/block/0000000000000000011bdccb39e19e942a60edffdccd9779653c5b46b337904a
@ -319,7 +316,7 @@ mod benchmarks {
);
let thread_proof = ThreadProof::UtxoThreadProof(utxo_thread_proof);
let pulled_thread_key = thread_proof.get_unique_key(session, network_id);
let pulled_thread_key = thread_proof.get_unique_key(session);
assert!(!PulledThreads::<T>::contains_key(&pulled_thread_key));
@ -333,15 +330,14 @@ mod benchmarks {
#[benchmark]
fn pull_evm_thread() -> Result<(), BenchmarkError> {
let session = 0;
let sepolia_network_id = 11155111;
let (network_id, _, _) = prepare_pallet::<T>(1, Some(sepolia_network_id));
let session = 69;
let (network_id, _, _) = prepare_pallet::<T>(1);
// https://sepolia.etherscan.io/address/0x7fec11e652f4d54e8cf11c4b52c360380332f2bd#readContract
// getRoot: session 0, atBlock 11716130
// https://sepolia.etherscan.io/address/0x81acdf2da6b50d806c96aecd9a498a5359e373c0#readContract
// getRoot: session 0, atBlock 11660400
let root_string =
hex::decode("07f4a5ba4750d9ddfc080429287cbcbde7464aa2f8ae13feaade0dcb45ca6129")
hex::decode("28d1e6b476b03a464f74d531d532572db29d6b57349e4f17f84e92843f6c4ee7")
.expect("EVM Root hex should be valid");
let expected_root = H256::from_slice(&root_string);
LoomStates::<T>::insert(&network_id, &session, expected_root);
@ -356,8 +352,8 @@ mod benchmarks {
let transfer_amount: BalanceOf<T> = 420u64.unique_saturated_into();
let proof = vec![
H256::from_slice(&hex::decode("7d831a4be9e37572687117870c3f96669a66bf07971e4fd705a36a0a4d6365b0").expect("Proof should be valid")),
H256::from_slice(&hex::decode("9f00b99751b7ccea1903949210408edb3ce50343985708c36a0b1d44e0a7628c").expect("Proof should be valid")),
H256::from_slice(&hex::decode("c5354289f0397c916949373043eb1d5ea99447f67fe014324d96c58ef02a2d11").expect("Proof should be valid")),
H256::from_slice(&hex::decode("da1fbdfefa1e9aedfedcfc48fb17cb0e731529f7a3695114e0a9caa1989dd420").expect("Proof should be valid")),
H256::from_slice(&hex::decode("1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f").expect("Proof should be valid")),
@ -366,14 +362,14 @@ mod benchmarks {
H256::from_slice(&hex::decode("de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040").expect("Proof should be valid")),
];
let slots = vec![H256::from_slice(
&hex::decode("f6182b8c276793f53d1820ad0405665177516e46e40af45e0dfea73c39a2306e")
&hex::decode("2e474dabf492786b3505d7b7cf0bf07c9dbce92c91982fa7344c77e24fd4310d")
.expect("Slot should be valid hex"),
)];
let evm_thread_proof = EvmThreadProof::new(0, 1, receiver_account, transfer_amount, proof, slots);
let thread_proof = ThreadProof::EvmThreadProof(evm_thread_proof);
let pulled_thread_key = thread_proof.get_unique_key(session, network_id);
let pulled_thread_key = thread_proof.get_unique_key(session);
assert!(!PulledThreads::<T>::contains_key(&pulled_thread_key));

View File

@ -439,7 +439,7 @@ pub mod pallet {
.ok_or(Error::<T>::NonExistentNetworkId)?;
let root_hash = LoomStates::<T>::get(&network_id, &session);
let pulled_thread_key = thread_proof.get_unique_key(session, network_id);
let pulled_thread_key = thread_proof.get_unique_key(session);
ensure!(
!PulledThreads::<T>::contains_key(&pulled_thread_key),
@ -447,7 +447,7 @@ pub mod pallet {
);
let (receiver_account, amount) = thread_proof
.verify_thread_proof(root_hash, network_id, &network_data.gatekeeper)
.verify_thread_proof(root_hash, &network_data.gatekeeper)
.ok_or(Error::<T>::InvalidMerkleProof)?;
let receiver_bytes: &[u8; 32] = receiver_account.as_ref();

View File

@ -560,7 +560,7 @@ fn offchain_worker_should_fetch_hash_and_submit_unsigned_tx() {
fn should_successfully_pull_evm_thread_and_mint_currency() {
let pair = AuthorityPair::from_string("//Alice", None).expect("Should be valid seed");
let network_id = 11155111;
let network_id = 1;
let network_data = NetworkDataBuilder::default()
.with_network_type(NetworkType::Evm)
.build();
@ -568,78 +568,204 @@ fn should_successfully_pull_evm_thread_and_mint_currency() {
let authorities = vec![pair.clone()];
let networks = vec![(network_id, network_data, Default::default())];
// Contract address: 0x7fec11e652f4d54e8cf11c4b52c360380332f2bd
// Contract address: 0x9a52C28dA655b69d8ddc430d6ebD04630BA0e845
//
// three inserts
// 69 sfJ9hc4A7r578XM35nd48B3FWcd33XjpVnAbGC5tvtwthMWdU - 0xc477f0a42fdd861485bd854c7a5851614ea163bd295f7844e1c5493d662fdc4e
// 420 sfDxNicCEPts6CVttVMPCs2eoymDpQahu1GUVyGPWu6dhwADJ - 0x0ae3ba32f8555fe3031461e2cb6feeadb67029ef7490b982824fc90751a4cb3e
// 1337 sfH6zJ63fcxrFAZ1RmiHbxgy2t3sEufY26WdsBSS359AzJd4w - 0x962a2794f66c89e55d9b9692ce59f67345b99f6fddb51d90462c7eca8b5a7e1b
// https://sepolia.etherscan.io/address/0x7fec11e652f4d54e8cf11c4b52c360380332f2bd#readContract
// getRoot: atBlock 11716130, globalIndexes from 0 to 2
// https://sepolia.etherscan.io/address/0x81acdf2da6b50d806c96aecd9a498a5359e373c0#readContract
// getRoot: atBlock 11660400, globalIndexes from 0 to 2
let inserts = vec![
(
0,
hex::decode("c477f0a42fdd861485bd854c7a5851614ea163bd295f7844e1c5493d662fdc4e").expect("Bytes32 from EVM should be valid"),
hex::decode("c477f0a42fdd861485bd854c7a5851614ea163bd295f7844e1c5493d662fdc4e")
.expect("Bytes32 from EVM should be valid"),
69u64,
vec![
H256::from_slice(&hex::decode("2d931b11b1652669a04e7b5b50418f5e1e2fabb6791dabc9a196e719ad5cf9c6").expect("Proof should be valid")),
H256::from_slice(&hex::decode("9f00b99751b7ccea1903949210408edb3ce50343985708c36a0b1d44e0a7628c").expect("Proof should be valid")),
H256::from_slice(&hex::decode("1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("d364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd071").expect("Proof should be valid")),
H256::from_slice(&hex::decode("68d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040").expect("Proof should be valid")),
H256::from_slice(
&hex::decode(
"675a2e7b05b8b3932cd0faf88f1bc29767b7462667f56d051b8d5325bda0ee73",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"da1fbdfefa1e9aedfedcfc48fb17cb0e731529f7a3695114e0a9caa1989dd420",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"d364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd071",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"68d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040",
)
.expect("Proof should be valid"),
),
],
vec![H256::from_slice(
&hex::decode("f494b2065ca61f2af007a3dd5f1f3d228a3ad09f4f7b7c5ef3eeb3aee6718ee2").expect("Slot should be valid hex"),
&hex::decode("350a78f78c810898b7c60ddba671543bfbe683ffb0ac393df0e132f607b5f738")
.expect("Slot should be valid hex"),
)],
),
(
1,
hex::decode("0ae3ba32f8555fe3031461e2cb6feeadb67029ef7490b982824fc90751a4cb3e").expect("Bytes32 from EVM should be valid"),
hex::decode("0ae3ba32f8555fe3031461e2cb6feeadb67029ef7490b982824fc90751a4cb3e")
.expect("Bytes32 from EVM should be valid"),
420u64,
vec![
H256::from_slice(&hex::decode("7d831a4be9e37572687117870c3f96669a66bf07971e4fd705a36a0a4d6365b0").expect("Proof should be valid")),
H256::from_slice(&hex::decode("9f00b99751b7ccea1903949210408edb3ce50343985708c36a0b1d44e0a7628c").expect("Proof should be valid")),
H256::from_slice(&hex::decode("1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("d364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd071").expect("Proof should be valid")),
H256::from_slice(&hex::decode("68d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040").expect("Proof should be valid")),
H256::from_slice(
&hex::decode(
"c5354289f0397c916949373043eb1d5ea99447f67fe014324d96c58ef02a2d11",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"da1fbdfefa1e9aedfedcfc48fb17cb0e731529f7a3695114e0a9caa1989dd420",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"d364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd071",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"68d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040",
)
.expect("Proof should be valid"),
),
],
vec![H256::from_slice(
&hex::decode("f6182b8c276793f53d1820ad0405665177516e46e40af45e0dfea73c39a2306e").expect("Slot should be valid hex"),
&hex::decode("2e474dabf492786b3505d7b7cf0bf07c9dbce92c91982fa7344c77e24fd4310d")
.expect("Slot should be valid hex"),
)],
),
(
2,
hex::decode("962a2794f66c89e55d9b9692ce59f67345b99f6fddb51d90462c7eca8b5a7e1b").expect("Bytes32 from EVM should be valid"),
hex::decode("962a2794f66c89e55d9b9692ce59f67345b99f6fddb51d90462c7eca8b5a7e1b")
.expect("Bytes32 from EVM should be valid"),
1337u64,
vec![
H256::from_slice(&hex::decode("f39a869f62e75cf5f0bf914688a6b289caf2049435d8e68c5c5e6d05e44913f3").expect("Proof should be valid")),
H256::from_slice(&hex::decode("385de173dc8295d4153b2de3bd705dd96556c8c316a996b3e56adce0970ffa36").expect("Proof should be valid")),
H256::from_slice(&hex::decode("1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("d364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd071").expect("Proof should be valid")),
H256::from_slice(&hex::decode("68d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849f").expect("Proof should be valid")),
H256::from_slice(&hex::decode("de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040").expect("Proof should be valid")),
H256::from_slice(
&hex::decode(
"f39a869f62e75cf5f0bf914688a6b289caf2049435d8e68c5c5e6d05e44913f3",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"e0090094ce1d7af8a81ba78bef4b137c1ab32d20d5487224a9f8df95b516c1e4",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"1c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"d364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd071",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"68d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849f",
)
.expect("Proof should be valid"),
),
H256::from_slice(
&hex::decode(
"de9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040",
)
.expect("Proof should be valid"),
),
],
vec![H256::from_slice(
&hex::decode("2f52c7d2d3f4167c436f3b6cc0a7d944a45846ba87f74998100b83122d5eb0ad").expect("Slot should be valid hex"),
&hex::decode("bde870fce92d701a7a5d6f63003e1cd2cb61c3266fc1be256844b8ca61d9c9ab")
.expect("Slot should be valid hex"),
)],
),
];
new_test_ext(authorities, networks).execute_with(|| {
// https://sepolia.etherscan.io/address/0x7fec11e652f4d54e8cf11c4b52c360380332f2bd#readContract
// getRoot: session 0, atBlock 11716130
// https://sepolia.etherscan.io/address/0x81acdf2da6b50d806c96aecd9a498a5359e373c0#readContract
// getRoot: session 0, atBlock 11660400
let session = 0;
let root_string =
hex::decode("07f4a5ba4750d9ddfc080429287cbcbde7464aa2f8ae13feaade0dcb45ca6129")
hex::decode("28d1e6b476b03a464f74d531d532572db29d6b57349e4f17f84e92843f6c4ee7")
.expect("Root hex should be valid");
let expected_root = H256::from_slice(&root_string);
LoomStates::<TestRuntime>::insert(&network_id, &session, expected_root);
@ -669,7 +795,7 @@ fn should_successfully_pull_evm_thread_and_mint_currency() {
);
let thread_info = ThreadProof::EvmThreadProof(evm_thread_proof);
let pulled_thread_key = thread_info.get_unique_key(session, network_id);
let pulled_thread_key = thread_info.get_unique_key(session);
assert_eq!(Balances::free_balance(&receiver_account), 0);
assert!(!PulledThreads::<TestRuntime>::contains_key(
@ -680,7 +806,8 @@ fn should_successfully_pull_evm_thread_and_mint_currency() {
network_id,
session,
thread_info
).is_ok());
)
.is_ok());
assert!(PulledThreads::<TestRuntime>::contains_key(
&pulled_thread_key
@ -760,7 +887,7 @@ fn should_successfully_pull_utxo_thread_and_mint_currency() {
let utxo_thread_proof = UtxoThreadProof::new(payload.0, payload.1, payload.2);
let thread_info = ThreadProof::UtxoThreadProof(utxo_thread_proof);
let pulled_thread_key = thread_info.get_unique_key(session, network_id);
let pulled_thread_key = thread_info.get_unique_key(session);
assert_eq!(Balances::free_balance(&receiver_account), 0);
assert!(!PulledThreads::<TestRuntime>::contains_key(

View File

@ -288,40 +288,31 @@ where
Balance: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u128>,
u64: UniqueSaturatedInto<Balance>,
{
pub fn verify_thread_proof<NetworkId>(
&self,
root_hash: H256,
network_id: NetworkId,
gatekeeper: &[u8]
) -> Option<(AccountId32, Balance)>
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
pub fn is_evm_proof_correct(&self) -> bool {
match self {
Self::UtxoThreadProof(utxo_thread) => {
utxo_thread.verify_thread_proof(root_hash, gatekeeper)
},
Self::EvmThreadProof(evm_thread) => {
evm_thread.verify_thread_proof(root_hash, network_id)
},
Self::EvmThreadProof(_) => true,
Self::UtxoThreadProof(_) => false,
}
}
pub fn get_unique_key<NetworkId>(
&self,
session: WeavingSession,
network_id: NetworkId,
) -> H256
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
pub fn is_utxo_proof_correct(&self) -> bool {
match self {
Self::EvmThreadProof(thread_info) => {
thread_info.get_unique_key(session, network_id)
},
Self::UtxoThreadProof(utxo_thread) => {
utxo_thread.get_unique_key(network_id)
},
Self::UtxoThreadProof(_) => true,
Self::EvmThreadProof(_) => false,
}
}
pub fn verify_thread_proof(&self, root_hash: H256, gatekeeper: &[u8]) -> Option<(AccountId32, Balance)> {
match self {
Self::UtxoThreadProof(utxo_thread) => utxo_thread.verify_thread_proof(root_hash, gatekeeper),
Self::EvmThreadProof(evm_thread) => evm_thread.verify_thread_proof(root_hash),
}
}
pub fn get_unique_key(&self, session: WeavingSession) -> H256 {
match self {
Self::EvmThreadProof(thread_info) => thread_info.get_unique_key(session),
Self::UtxoThreadProof(utxo_thread) => utxo_thread.get_unique_key(),
}
}
}
@ -340,18 +331,11 @@ impl<Balance> EvmThreadProof<Balance>
where
Balance: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u128>,
{
pub fn verify_thread_proof<NetworkId>(
&self,
root_hash: H256,
network_id: NetworkId,
) -> Option<(AccountId32, Balance)>
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
pub fn verify_thread_proof(&self, root_hash: H256) -> Option<(AccountId32, Balance)> {
if EVM_MERKLE_DEPTH as usize != self.proof.len() { return None; }
let proof_valid = verify_tree_proof::<SubstrateKeccakHasher, _>(
&self.get_preimage_slice(network_id).to_fixed_bytes(),
&self.get_preimage_slice().to_fixed_bytes(),
self.proof.as_ref(),
root_hash,
self.proof_index,
@ -362,85 +346,41 @@ where
Some((self.receiver.clone(), self.amount))
}
fn get_preimage_slice<NetworkId>(&self, network_id: NetworkId) -> H256
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
fn get_preimage_slice(&self) -> H256 {
let slot_index_usize: usize = self.slot_index.unique_saturated_into();
let mut slot_values: Vec<H256> = self.slots.to_vec();
match slot_values.get_mut(slot_index_usize) {
Some(slot) => {
*slot = self.compute_arguments_hash(network_id);
cumulative_hash::<SubstrateKeccakHasher, _>(slot_values)
}
None => {
SubstrateKeccakHasher::empty()
}
}
(slot_index_usize < self.slots.len())
.then(|| {
self.slots
.iter()
.enumerate()
.map(|(index, &preimage)| {
if index == slot_index_usize {
self.compute_arguments_hash()
} else {
preimage
}
})
.collect::<Vec<_>>()
})
.map(|slots| cumulative_hash::<SubstrateKeccakHasher, _>(slots))
.unwrap_or(SubstrateKeccakHasher::empty())
}
pub fn get_unique_key<NetworkId>(
&self,
session: WeavingSession,
network_id: NetworkId,
) -> H256
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
pub fn get_unique_key(&self, session: WeavingSession) -> H256 {
let session_bytes = (session as u64).to_be_bytes();
let slot_index_bytes = (self.slot_index as u64).to_be_bytes();
let proof_index_bytes = (self.proof_index as u64).to_be_bytes();
let network_id_u64: u64 = network_id.unique_saturated_into();
let network_id_bytes = network_id_u64.to_be_bytes();
let slot_bytes = (self.slot_index as u64).to_be_bytes();
let proof_bytes = (self.proof_index as u64).to_be_bytes();
let mut h1 = [0u8; 32]; h1[24..32].copy_from_slice(&session_bytes);
let mut h2 = [0u8; 32]; h2[24..32].copy_from_slice(&slot_index_bytes);
let mut h3 = [0u8; 32]; h3[24..32].copy_from_slice(&proof_index_bytes);
let mut h4 = [0u8; 32]; h4[24..32].copy_from_slice(&network_id_bytes);
let mut h2 = [0u8; 32]; h2[24..32].copy_from_slice(&slot_bytes);
let mut h3 = [0u8; 32]; h3[24..32].copy_from_slice(&proof_bytes);
let metadata: [H256; 4] = [
H256::from(h1),
H256::from(h2),
H256::from(h3),
H256::from(h4),
];
let metadata: [H256; 3] = [H256::from(h1), H256::from(h2), H256::from(h3)];
sequential_hash::<SubstrateBlake2Hasher, _>(metadata)
}
fn compute_arguments_hash<NetworkId>(&self, network_id: NetworkId) -> H256
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
let amount_u128: u128 = self.amount.unique_saturated_into();
let slot_index_u64: u64 = self.slot_index.unique_saturated_into();
let network_id_u64: u64 = network_id.unique_saturated_into();
let amount_u256 = U256::from(amount_u128);
let slot_index_u256 = U256::from(slot_index_u64);
let network_id_u256 = U256::from(network_id_u64);
let mut padded_amount = [0u8; 32];
amount_u256.to_big_endian(&mut padded_amount);
let mut padded_slot_index = [0u8; 32];
slot_index_u256.to_big_endian(&mut padded_slot_index);
let mut padded_network_id = [0u8; 32];
network_id_u256.to_big_endian(&mut padded_network_id);
let inputs: [&[u8]; 4] = [
padded_amount.as_ref(),
self.receiver.as_ref(),
padded_slot_index.as_ref(),
padded_network_id.as_ref(),
];
sequential_hash::<SubstrateKeccakHasher, _>(inputs)
}
pub fn new(
slot_index: ThreadId,
proof_index: ThreadId,
@ -464,6 +404,27 @@ where
slots,
}
}
fn compute_arguments_hash(&self) -> H256 {
let amount_u128: u128 = self.amount.unique_saturated_into();
let amount_u256 = U256::from(amount_u128);
let slot_index_u64: u64 = self.slot_index.unique_saturated_into();
let slot_index_u256 = U256::from(slot_index_u64);
let mut padded_amount = [0u8; 32];
amount_u256.to_big_endian(&mut padded_amount);
let mut padded_slot_index = [0u8; 32];
slot_index_u256.to_big_endian(&mut padded_slot_index);
let inputs: [&[u8]; 3] = [
padded_amount.as_ref(),
self.receiver.as_ref(),
padded_slot_index.as_ref(),
];
sequential_hash::<SubstrateKeccakHasher, _>(inputs)
}
}
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
@ -486,7 +447,7 @@ impl UtxoThreadProof {
root_hash: H256,
gatekeeper_ref: &[u8],
) -> Option<(AccountId32, Balance)>
where
where
Balance: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u128>,
u64: UniqueSaturatedInto<Balance>,
{
@ -527,17 +488,10 @@ impl UtxoThreadProof {
))
}
pub fn get_unique_key<NetworkId>(&self, network_id: NetworkId) -> H256
where
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
{
let network_id_u64: u64 = network_id.unique_saturated_into();
let network_id_bytes = network_id_u64.to_be_bytes();
pub fn get_unique_key(&self) -> H256 {
let metadata: &[&[u8]] = &[
self.gettxproof_bytes.as_ref(),
self.getrawtransaction_bytes.as_ref(),
network_id_bytes.as_ref(),
];
sequential_hash::<SubstrateBlake2Hasher, _>(metadata)

View File

@ -16,7 +16,7 @@
//! Autogenerated weights for `ghost_weaver`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2026-09-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2026-09-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
@ -69,11 +69,11 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `223 + a * (32 ±0)`
// Estimated: `3687 + a * (32 ±0)`
// Minimum execution time: 211_189_000 picoseconds.
Weight::from_parts(215_074_977, 0)
// Minimum execution time: 210_105_000 picoseconds.
Weight::from_parts(214_589_101, 0)
.saturating_add(Weight::from_parts(0, 3687))
// Standard Error: 1_505
.saturating_add(Weight::from_parts(46_499, 0).saturating_mul(a.into()))
// Standard Error: 1_420
.saturating_add(Weight::from_parts(50_124, 0).saturating_mul(a.into()))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(a.into()))
@ -95,11 +95,11 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `518 + a * (32 ±0)`
// Estimated: `3982 + a * (32 ±0)`
// Minimum execution time: 241_010_000 picoseconds.
Weight::from_parts(245_378_305, 0)
// Minimum execution time: 241_676_000 picoseconds.
Weight::from_parts(246_243_389, 0)
.saturating_add(Weight::from_parts(0, 3982))
// Standard Error: 1_583
.saturating_add(Weight::from_parts(32_330, 0).saturating_mul(a.into()))
// Standard Error: 1_686
.saturating_add(Weight::from_parts(32_125, 0).saturating_mul(a.into()))
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(a.into()))
@ -121,10 +121,10 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `346`
// Estimated: `3811`
// Minimum execution time: 170_701_000 picoseconds.
Weight::from_parts(170_150_850, 0)
// Standard Error: 4_368
.saturating_add(Weight::from_parts(3_363_930, 0).saturating_mul(a.into()))
// Minimum execution time: 170_554_000 picoseconds.
Weight::from_parts(170_660_694, 0)
// Standard Error: 4_207
.saturating_add(Weight::from_parts(3_450_120, 0).saturating_mul(a.into()))
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(3))
}
@ -144,8 +144,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `3446`
// Estimated: `3811`
// Minimum execution time: 138_215_000 picoseconds.
Weight::from_parts(140_004_000, 0)
// Minimum execution time: 136_258_000 picoseconds.
Weight::from_parts(137_856_000, 0)
.saturating_add(Weight::from_parts(0, 3811))
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(3))

View File

@ -1,6 +1,6 @@
[package]
name = "casper-runtime"
version = "4.0.11"
version = "4.0.10"
build = "build.rs"
description = "Runtime of the Casper Network"
edition.workspace = true

View File

@ -123,8 +123,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("casper"),
impl_name: create_runtime_str!("casper-svengali"),
authoring_version: 0,
spec_version: 7,
impl_version: 0,
spec_version: 6,
impl_version: 4,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,

View File

@ -16,7 +16,7 @@
//! Autogenerated weights for `ghost_weaver`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2026-09-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2026-09-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
@ -61,11 +61,11 @@ impl<T: frame_system::Config> ghost_weaver::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `223 + a * (32 ±0)`
// Estimated: `3687 + a * (32 ±0)`
// Minimum execution time: 211_189_000 picoseconds.
Weight::from_parts(215_074_977, 0)
// Minimum execution time: 210_105_000 picoseconds.
Weight::from_parts(214_589_101, 0)
.saturating_add(Weight::from_parts(0, 3687))
// Standard Error: 1_505
.saturating_add(Weight::from_parts(46_499, 0).saturating_mul(a.into()))
// Standard Error: 1_420
.saturating_add(Weight::from_parts(50_124, 0).saturating_mul(a.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(a.into()))
@ -87,11 +87,11 @@ impl<T: frame_system::Config> ghost_weaver::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `518 + a * (32 ±0)`
// Estimated: `3982 + a * (32 ±0)`
// Minimum execution time: 241_010_000 picoseconds.
Weight::from_parts(245_378_305, 0)
// Minimum execution time: 241_676_000 picoseconds.
Weight::from_parts(246_243_389, 0)
.saturating_add(Weight::from_parts(0, 3982))
// Standard Error: 1_583
.saturating_add(Weight::from_parts(32_330, 0).saturating_mul(a.into()))
// Standard Error: 1_686
.saturating_add(Weight::from_parts(32_125, 0).saturating_mul(a.into()))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(a.into()))
@ -113,11 +113,11 @@ impl<T: frame_system::Config> ghost_weaver::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `346`
// Estimated: `3811`
// Minimum execution time: 170_701_000 picoseconds.
Weight::from_parts(170_150_850, 0)
// Minimum execution time: 170_554_000 picoseconds.
Weight::from_parts(170_660_694, 0)
.saturating_add(Weight::from_parts(0, 3811))
// Standard Error: 4_368
.saturating_add(Weight::from_parts(3_363_930, 0).saturating_mul(a.into()))
// Standard Error: 4_207
.saturating_add(Weight::from_parts(3_450_120, 0).saturating_mul(a.into()))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
}
@ -137,8 +137,8 @@ impl<T: frame_system::Config> ghost_weaver::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `346`
// Estimated: `3811`
// Minimum execution time: 138_215_000 picoseconds.
Weight::from_parts(140_004_000, 0)
// Minimum execution time: 136_258_000 picoseconds.
Weight::from_parts(137_856_000, 0)
.saturating_add(Weight::from_parts(0, 3811))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))

View File

@ -1,4 +0,0 @@
[toolchain]
channel = "1.93.1"
components = ["rustfmt", "clippy", "rust-src"]
targets = ["wasm32-unknown-unknown"]

View File

@ -17,21 +17,15 @@ MORDOR_RPC=(
"https://rpc.mordor.etccooperative.org"
)
HOODI_RPC=(
"https://rpc.hoodi.ethpandaops.io"
"https://0xrpc.io/hoodi"
"https://ethereum-hoodi.gateway.tatum.io"
"https://rpc.sentio.xyz/hoodi"
)
show_help() {
cat << EOF
Usage: $(basename "$0") [OPTIONS]
Options:
--chain <name> Specify network: 'sepolia', 'hoodi' or 'mordor'. If omitted, checks all.
--chain <name> Specify network: 'sepolia' or 'mordor'. If omitted, checks both.
--output <dir> Base directory to save results. Creates a subfolder with Unix Timestamp.
--rpcs <urls> Comma-separated list of custom RPC endpoints. Disables default networks lists.
--rpcs <urls> Comma-separated list of custom RPC endpoints.
Disables default Sepolia/Mordor lists.
--help Show this help message.
Example:
@ -135,11 +129,8 @@ else
check_network "Sepolia" "${SEPOLIA_RPC[@]}"
elif [ "$CHOSEN_CHAIN" == "mordor" ]; then
check_network "Mordor" "${MORDOR_RPC[@]}"
elif [ "$CHOSEN_CHAIN" == "hoodi" ]; then
check_network "Hoodi" "${HOODI_RPC[@]}"
else
check_network "Sepolia" "${SEPOLIA_RPC[@]}"
check_network "Mordor" "${MORDOR_RPC[@]}"
check_network "Hoodi" "${HOODI_RPC[@]}"
fi
fi

View File

@ -85,16 +85,30 @@ extract_seed() {
echo $seed
}
apply_patches_if_needed() {
local PATCH_STATUS=0
upgrade_compiler_if_needed() {
UPDATE_STATUS=$(rustup check 2>&1)
"$SCRIPT_FOLDER"/patch.sh || PATCH_STATUS=$?
if [ "$PATCH_STATUS" -eq 2 ]; then
if echo "$UPDATE_STATUS" | grep -q "Update available" || [ $PATCH_STATUS -eq 2 ]; then
echo "[+] clean all cache on the current system"
cargo clean
cargo install cargo-cache
cargo clean
cargo cache --remove-dir all
echo "[+] upgrading rustc compiler version to latest"
rustup update
toolchain_name=$(rustup show | grep default | head -n 1 | cut -d' ' -f1)
if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then
echo "[+] installing wasm32-unknown-unknown target"
rustup target add wasm32-unknown-unknown
fi
if ! rustup component list --installed | grep -q "rust-src"; then
echo "[+] installing rust-src component"
rustup component add rust-src
fi
echo "[+] fetching all dependencies"
cargo fetch
@ -226,7 +240,7 @@ if [[ $HARD_RESET = true ]]; then
exit 1
fi
apply_patches_if_needed
upgrade_compiler_if_needed
echo "[+] trying to stop current ghost-node"
sudo systemctl stop ghost-node
@ -335,12 +349,12 @@ if [[ $SET_ENVIRONMENT = true ]]; then
if prompt "[?] setup the rust environment (e.g. WASM support)?"; then
rustup default stable
apply_patches_if_needed
upgrade_compiler_if_needed
fi
fi
if [[ ! -z $RELEASE ]]; then
apply_patches_if_needed
upgrade_compiler_if_needed
if prompt "[?] 'cargo build $RELEASE $FEATURES' is what you want?"; then
cd $PROJECT_FOLDER
echo "[+] starting build in 3 seconds..."