From 919bae01dcf93394b6c2d7e3a3e09328c5779383 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Fri, 19 Jul 2024 11:36:08 +0900 Subject: [PATCH] modify client state test Signed-off-by: Naohiro Yoshida --- light-client/src/client_state.rs | 65 +++++++++--------- light-client/src/fixture/localnet.rs | 98 ++++------------------------ light-client/src/fixture/mod.rs | 17 ++++- light-client/src/header/mod.rs | 22 ++++++- 4 files changed, 80 insertions(+), 122 deletions(-) diff --git a/light-client/src/client_state.rs b/light-client/src/client_state.rs index 33de923..b11df02 100644 --- a/light-client/src/client_state.rs +++ b/light-client/src/client_state.rs @@ -275,6 +275,7 @@ mod test { use crate::fixture::*; use crate::header::epoch::Epoch; use crate::header::eth_header::ETHHeader; + use crate::header::eth_headers::ETHHeaders; use crate::header::validator_set::ValidatorSet; use crate::header::Header; use crate::misc::{keccak_256_vec, new_timestamp, ChainId, Hash}; @@ -311,58 +312,54 @@ mod test { let cons_state = ConsensusState { state_root: [0u8; 32], timestamp: new_timestamp(h.timestamp).unwrap(), - current_validators_hash: make_cs_hash(keccak_256_vec(&hp.previous_validators())), - previous_validators_hash: make_cs_hash(keccak_256_vec(&hp.previous_validators())), + current_validators_hash: hp.previous_epoch_header().epoch.unwrap().hash(), + previous_validators_hash: hp.previous_epoch_header().epoch.unwrap().hash(), }; - let raw = RawHeader { - headers: vec![h.try_into().unwrap()], - trusted_height: Some(Height { + let header = Header::new( + vec![1], + ETHHeaders { + target: hp.epoch_header(), + all: vec![], + }, + Height { revision_number: 0, revision_height: h.number - 1, - }), - account_proof: vec![], - current_validators: if h.is_epoch() { - h.epoch.clone().unwrap().validators().clone() - } else { - vec![] }, - previous_validators: hp.previous_validators(), - previous_turn_term: 1, - current_turn_term: 1, - }; + hp.previous_epoch_header().epoch.unwrap(), + hp.epoch_header().epoch.unwrap(), + ); let now = new_timestamp(h.timestamp + 1).unwrap(); - let invalid_header: Header = raw.clone().try_into().unwrap(); let err = cs - .check_header_and_update_state(now, &cons_state, invalid_header) + .check_header_and_update_state(now, &cons_state, header.clone()) .unwrap_err(); match err { Error::InvalidVerifyingHeaderLength(number, size) => { assert_eq!(number, h.number); - assert_eq!(size, raw.headers.len()); + assert_eq!(size, header.eth_header().all.len()); } err => unreachable!("{:?}", err), } // fail: resolve_account - let raw = RawHeader { - headers: vec![ - (&hp.epoch_header()).try_into().unwrap(), - (&hp.epoch_header_plus_1()).try_into().unwrap(), - (&hp.epoch_header_plus_2()).try_into().unwrap(), - ], - trusted_height: Some(Height { + let header = Header::new( + vec![1], + ETHHeaders { + target: hp.epoch_header(), + all: vec![ + hp.epoch_header(), + hp.epoch_header_plus_1(), + hp.epoch_header_plus_2(), + ], + }, + Height { revision_number: 0, revision_height: h.number - 1, - }), - account_proof: vec![1], - current_validators: hp.epoch_header().epoch.unwrap().validators().clone(), - previous_validators: hp.previous_validators(), - previous_turn_term: 1, - current_turn_term: 1, - }; - let valid_header: Header = raw.try_into().unwrap(); + }, + hp.previous_epoch_header().epoch.unwrap(), + hp.epoch_header().epoch.unwrap(), + ); let err = cs - .check_header_and_update_state(now, &cons_state, valid_header) + .check_header_and_update_state(now, &cons_state, header) .unwrap_err(); match err { Error::InvalidProofFormatError(value) => { diff --git a/light-client/src/fixture/localnet.rs b/light-client/src/fixture/localnet.rs index 95a29fc..2247fde 100644 --- a/light-client/src/fixture/localnet.rs +++ b/light-client/src/fixture/localnet.rs @@ -1,12 +1,14 @@ use crate::header::epoch::Epoch; use hex_literal::hex; +use parlia_ibc_proto::ibc::lightclients::parlia::v1::EthHeader; use std::prelude::rust_2015::Vec; use crate::header::eth_header::{get_validator_bytes, ETHHeader}; use crate::header::eth_headers::ETHHeaders; use crate::fixture::{ - Network, UpdateClientEpochInput, UpdateClientErrorInput, UpdateClientNonEpochInput, + decode_header, Network, UpdateClientEpochInput, UpdateClientErrorInput, + UpdateClientNonEpochInput, }; use crate::misc::{Address, ChainId, Validators}; @@ -22,71 +24,23 @@ impl Network for Localnet { hex!("2F5703804E29F4252FA9405B8D357220d11b3bd9") } + fn previous_epoch_header(&self) -> ETHHeader { + // height 2800 + decode_header(hex!("f903baa0a0918ed6851ba769bd1032d4756d82ab358e0a42dc717590004c9c62f6cab2f9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794a7876ea32e7a748c697d01345145485561305b24a0a71c3f989f207cf6cdc3bc68ec53af5c1b6b7f7bcae678cb63fae4fc6816e34fa09417f8f25d5e25867f33c0a18d3aa5a6782021dcaf952313c6990ea74d58973ba03cd1ebc99cd975182c58de47be968c97658cff4c465e20654185f408a851403cb901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002820af08402625a008229a8846699b127b9019bd98301040b846765746889676f312e32312e3132856c696e75780000ffcc693e028fdaaa7e6631e438625ca25c857a3727ea28e56593428ee663799df81ea82bc8445a7d93c891ef324b5f4438eb766bcf75fc405fb79d3f618fcdd17f107b374368ef512fd9a13701eafb76870cb220843b8c6476824bfa15a82968379b116362f75bdb7cc4be8ca0ceea7c0f2e74be7c8f289cda6dcbc5edbb26400e1306c2de06f52a9a583dab9901f8ae03b86094f28854a08a34767114f69a9568aedc17ef0e63b72f49db00468d6b87dd30b7c4f666d2c24658e5e114883074be80c11161bbfceeb33e378543e9b261c7f67886845d7e512458b0bada1a8e9f0f5542242a98e7272be60c660646cfb328d97cf848820aeea0b1b5ca9ca892d785f4c1839cb0e98df76de34223177a5e5585e997d70019edfa820aefa0a0918ed6851ba769bd1032d4756d82ab358e0a42dc717590004c9c62f6cab2f98040e7f9b7abb0faa3cd3eb3b72a974cf7f80124eff1ade4d8485bb62df1fae74b4a9bf46d7bf56cfad535f540dd938b579d8302c870bc90ea059d14999c536a8501a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080").to_vec()) + } + fn epoch_header(&self) -> ETHHeader { - let extra = hex!("d88301020a846765746888676f312e32302e35856c696e7578000000b19df4a2150bac492386862ad3df4b666bc096b0505bb694dab0bec348681af766751cb839576e9c515a09c8bffa30a46296ccc56612490eb480d03bf948e10005bbcc0421f90b3d4e2465176c461afb316ebc773c61faee85a6515daa8a923564c6ffd37fb2fe9f118ef88092e8762c7addb526ab7eb1e772baef85181f892c731be0c1891a50e6b06262c816295e26495cef6f69dfa69911d9d8e4f3bbadb89b977cf58294f7239d515e15b24cfeb82494056cf691eaf729b165f32c9757c429dba5051155903067e56ebe3698678e9135ebb5849518aff370ca25e19e1072cc1a9fabcaa7f3e2c0b4b16ad183c473bafe30a36e39fa4a143657e229cd23c77f8fbc8e4e4e241695dd3d248d1e51521eee6619143f349bbafec1551819b8be1efea2fc46ca749aa184248a459464eec1a21e7fc7b71a053d9644e9bb8da4853b8f872cd7c1d6b324bf1922829830646ceadfb658d3de009a61dd481a114a2e761c554b641742c973867899d38a80967d39e406a0a9642d41e9007a27fc1150a267d143a9f786cd2b5eecbdcc4036273705225b956d5e2f8f5eb95d2569c77a677c40c7fbea129d4b171a39b7a8ddabfab2317f59d86abfaf690850223d90e9e7593d91a29331dfc2f84d5adecc75fc39ecab4632c1b4400a3dd1e1298835bcca70f657164e5b75689b64b7fd1fa275f334f28e1896a26afa1295da81418593bd12814463d9f6e45c36a0e47eb4cd3e5b6af29c41e2a3a5636430155a466e216585af3ba772b61c6014342d914470ec7ac2975be345796c2b81db0422a5fd08e40db1fc2368d2245e4b18b1d0b85c921aaaafd2e341760e29fc613edd39f71254614e2055c3287a517ae2f5b9e386cd1b50a4550696d957cb4900f03ab84f83ff2df44193496793b847f64e9d6db1b3953682bb95edd096eb1e69bbd357c200992ca78050d0cbe180cfaa018e8b6c8fd93d6f4cea42bbb345dbc6f0dfdb5bec73a8a257074e82b881cfa06ef3eb4efeca060c2531359abd0eab8af1e3edfa2025fca464ac9c3fd123f6c24a0d78869485a6f79b60359f141df90a0c745125b131caaffd12b772e180fbf38a051c97dabc8aaa0126a233a9e828cdafcc7422c4bb1f4030a56ba364c54103f26bad91508b5220b741b218c5d6af1f979ac42bc68d98a5a0d796c6ab01b659ad0fbd9f515893fdd740b29ba0772dbde9b4635921dd91bd2963a0fc855e31f6338f45b211c4e9dedb7f2eb09de7b4dd66d7c2c7e57f628210187192fb89d4b99dd4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000be807dddb074639cd9fa61b47676c064fc50d62cb1f2c71577def3144fabeb75a8a1c8cb5b51d1d1b4a05eec67988b8685008baa17459ec425dbaebc852f496dc92196cdcc8e6d00c17eb431350c6c50d8b8f05176b90b11b3a3d4feb825ae9702711566df5dbf38e82add4dd1b573b95d2466fa6501ccb81e9d26a352b96150ccbf7b697fd0a419d1d6bf74282782b0b3eb1413c901d6ecf02e8e28939e8fb41b682372335be8070199ad3e8621d1743bcac4cc9d8f0f6e10f41e56461385c8eb5daac804fe3f2bca6ce739d93dbfb27e027f5e9e6da52b9e1c413ce35adc11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ea0a6e3c511bbd10f4519ece37dc24887e11b55db2d4c6283c44a1c7bd503aaba7666e9f0c830e0ff016c1c750a5e48757a713d0836b1cabfd5c281b1de3b77d1c192183ee226379db83cffc681495730c11fdde79ba4c0cae7bc6faa3f0cc3e6093b633fd7ee4f86970926958d0b7ec80437f936acf212b78f0cd095f4565fff144fd458d233a5bef0274e31810c9df02f98fafde0f841f4e66a1cd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f8b5830aefffb86097bc63a64e8d730014c39dcaac8f3309e37a11c06f0f5c233b55ba19c1f6c34d2d08de4b030ce825bb21fd884bc0fcb811336857419f5ca42a92ac149a4661a248de10f4ca6496069fdfd10d43bc74ccb81806b6ecd384617d1006b16dead7e4f84c8401dd8eaea0e61c6075d2ab24fcdc423764c21771cac6b241cbff89718f9cc8fc6459b4e7578401dd8eafa010c8358490a494a40c5c92aff8628fa770860a9d34e7fb7df38dfb208b0ddfc380ff15abfc44495e4d4605458bb485f0cac5a152b380a8d0208b3f9ff6216230ec4dd67a73b72b1d17a888c68e111f806ef0b255d012b5185b7420b5fb529c9b9300").to_vec(); - ETHHeader { - parent_hash: hex!("10c8358490a494a40c5c92aff8628fa770860a9d34e7fb7df38dfb208b0ddfc3").into(), - uncle_hash: hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").into(), - coinbase: hex!("e9ae3261a475a27bb1028f140bc2a7c843318afd").into(), - root: hex!("111504390f79560bc7fa5d1d5b8cdb109d0ee1aa76816dba43b88f1e5e152b6f"), - tx_hash: hex!("2a2eb4b95af5c879078702bfccd6147bd47162385898d8c0b81fb94ac5456a60").into(), - receipt_hash: hex!("57ed46152fe61b432e682da7f0b82273e1fee09674b2b62c64952e214e84e7e1").into(), - bloom: hex!("8035164600431418e05400edd0a9650e8238c2833980eadd35538b33d3641594dc00b06042041004a398b01d821aa232cdb11211a044e339d0440056482c6ec80e61d00aa544881a8b61c2988220042db254432900c6c8410045114b80ba0021cd6c20a23a66042b04e7971817460d6c0e52e95a00cbd4809580a4d9804e35c6998a0246256d4ad18588363010a0d89030240cc77a03158a0f4d83c0ac841cb0871050c8f73f6650e6153206369a061a0c2d90835480d12374a021a1605a2278e3209746a6555c4a32a1b8b87a629968238cf242a088ac190b51fa72f200e56c579880051b2042824b1db2e7058003c1619cfc307864e1c8fc2a690299a1864a").into(), - difficulty: 2, - number: u64::from_str_radix("1dd8eb0", 16).unwrap(), - gas_limit: u64::from_str_radix("8583b00", 16).unwrap(), - gas_used: u64::from_str_radix("a136cd", 16).unwrap(), - timestamp: u64::from_str_radix("64eee094", 16).unwrap(), - extra_data: extra.clone(), - mix_digest: hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), - nonce: hex!("0000000000000000").into(), - hash: hex!("e3439a5ce7e27a9755611e2aed8533ae2b0108ced5610f88d69fc97fd54e832d"), - epoch: Some(Epoch::new(get_validator_bytes(&extra).unwrap().into(), 1)) - } + // height 3000 + decode_header(hex!("f903baa0c0765ed6700f1cba70131930bde67d63a105c90d4918eab66592889b7982a113a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948fdaaa7e6631e438625ca25c857a3727ea28e565a0d269e8b47a345f3a77343f46943f78480a96ff82a8466963fb4a29c0e2b66091a0726fa82981fd3a7a862923f45ff454b0bc2359b8cc434d1ee9b3e544b99ad3ada03cd1ebc99cd975182c58de47be968c97658cff4c465e20654185f408a851403cb901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002820bb88402625a008229a8846699bbaeb9019bd98301040b846765746889676f312e32312e3132856c696e75780000ffcc693e028fdaaa7e6631e438625ca25c857a3727ea28e56593428ee663799df81ea82bc8445a7d93c891ef324b5f4438eb766bcf75fc405fb79d3f618fcdd17f107b374368ef512fa7876ea32e7a748c697d01345145485561305b24903201f874819815e1a3f183c4addc814b71ec0e573e07f79ee9082926d82dd1711d6c45a9cc8841916d8563c2f80baa01f8ae03b860af1a05b45fb2c711e2608c8541ba06900bce4b5567a116343de6f2f82de6bbde8b8a0546215a9733d37c497a5ec4a9ef0c60f811964169a297e1566e6747a19bcd6e78f8f8cfa72c130fd41afe0a72e116732362074122f17be19f157e265780f848820bb6a068a9cc380147ace998644ff3a6b5440e14cb4cd4d904a830fa00f2d33fc54058820bb7a0c0765ed6700f1cba70131930bde67d63a105c90d4918eab66592889b7982a11380a9ac9029f83d3dc84c11a37fed23da73d907de252c24b50d26f4863e515062f00141ec47ff19295af80b85a63452a79c5215b29044fa6e248832c6e0cb6760d600a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080").to_vec()) } fn epoch_header_plus_1(&self) -> ETHHeader { - ETHHeader { - parent_hash: hex!("e3439a5ce7e27a9755611e2aed8533ae2b0108ced5610f88d69fc97fd54e832d").into(), - uncle_hash: hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").into(), - coinbase: hex!("ea0a6e3c511bbd10f4519ece37dc24887e11b55d").into(), - root: hex!("66aa43298bddd4a09efccab7e2add00410b9af5792f0e1f803a6a2c804013a50"), - tx_hash: hex!("44f85c29cd8b6d584f06fcf870232b226a1d01165202721a1ba9226e06120f1d").into(), - receipt_hash: hex!("fc7d7246d63bf2db119fa1040bcafb763f2445373b6e60e911eb6e3712ebdf4a").into(), - bloom: hex!("c1a4d269e40cd118090c10448f04041680264225c4a58719313045e8122c3993f98116645810782282202ab2411a0834ce50d00851264a204cda822a162422d404ea68558542f4f8877b8889882410bca01a802003c60a0024c48010926418f053bf20a47a2301010157082103311a0a89013153b0a9741c09c01db1804744c4786884a6277d980e00941c184831c99c0027968ded02454c1d0949e8ab824622834300c673e92242240ab7de2aaf5a40cea80109000605c01187a162680a08fda8251c8b4108080e12032961120091243162b16a018445348133557ab021e5643274aa42165e5baa0d930862c98a81e46ab6663322206b6ae332344099035a4a").into(), - difficulty: 2, - number: u64::from_str_radix("1dd8eb1", 16).unwrap(), - gas_limit: u64::from_str_radix("8583b00", 16).unwrap(), - gas_used: u64::from_str_radix("b0b390", 16).unwrap(), - timestamp: u64::from_str_radix("64eee097", 16).unwrap(), - extra_data: hex!("d88301020b846765746888676f312e31392e38856c696e7578000000b19df4a2f8b5830aefffb8608abd3ea492829d7d47af7946a4d68eee74cf3adaa84d322d9df093b34cc5417d1210297861662a3bbe81556aa4e578b80689f641aac1fd578713ae41edc3797678eb051ebd36a7fb5922e4ce2373473bd04488277198b6c9f7129f8d1da8f74bf84c8401dd8eafa010c8358490a494a40c5c92aff8628fa770860a9d34e7fb7df38dfb208b0ddfc38401dd8eb0a0e3439a5ce7e27a9755611e2aed8533ae2b0108ced5610f88d69fc97fd54e832d80d4a280353736fd099c9f594fdf2c71ed5bab28e84720d6034dbe84fb7adeaefd1035b619ed48be9a1fb3ae24306fef5033be712a31e135e51454380685431be600").into(), - mix_digest: hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), - nonce: hex!("0000000000000000").into(), - hash: hex!("8398b4664eb55beadbbbb8ec08dbacd78322cb3274dcd8bb53999be2b784cd92"), - epoch: None - } + // height 3001 + decode_header(hex!("f9032ea003658f11880607bb5d603ac72c8dfa1e490d07d06dd232c0ea02acfbf51cf515a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794d9a13701eafb76870cb220843b8c6476824bfa15a0d269e8b47a345f3a77343f46943f78480a96ff82a8466963fb4a29c0e2b66091a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002820bb98402625a0080846699bbb1b90111d98301040b846765746889676f312e32312e3132856c696e75780000ffcc693ef8ae03b860973a79d13a61010c48d62cce671ea4d8ec94ffdd7332151665db7f10a01f14030f250afca7ad19e6574675c93e5229b30c8bcd893e0f5a9fe73552b6bb3d3b8d5c532a665a8acfeb7e26ec130ae38cf51fc2a71bd2835e7a980d3f21f852543df848820bb7a0c0765ed6700f1cba70131930bde67d63a105c90d4918eab66592889b7982a113820bb8a003658f11880607bb5d603ac72c8dfa1e490d07d06dd232c0ea02acfbf51cf5158082916d8889338c463a8de9b9a89e27d13a526e8c0fb00e264d129782b16d7b1a2b80b44be3d14a17ac451dfc8dd20b7e77550b5fca6c1384c16ff57b189eb3d400a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080").to_vec()) } fn epoch_header_plus_2(&self) -> ETHHeader { - ETHHeader { - parent_hash: hex!("8398b4664eb55beadbbbb8ec08dbacd78322cb3274dcd8bb53999be2b784cd92").into(), - uncle_hash: hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").into(), - coinbase: hex!("ef0274e31810c9df02f98fafde0f841f4e66a1cd").into(), - root: hex!("66cfd0f3112f0c1b7357852188e303cdca529e96c8f3e27d1e4eb5ac9121255c"), - tx_hash: hex!("9499b3f7096de457472373929f84036a11957a6828e5ba2c10c6965ea10928eb").into(), - receipt_hash: hex!("7604f3125509cfe0fbc0daac26ea9157249e41aabcf2d29297e6ec599e9d8468").into(), - bloom: hex!("04382bc3061d75194854024490983c43e420c0e000a06e022072c5da3e40d51bc64ff507500204244ba0ee82555e020090200028464822a0424c840a5d2320a4c744449b19c030281510944c800400b8333e300110e2669088846b15b0810699884e3e326a0625252c49034b15d26d3b6a66915a8ee965560c29ee93c1e92610108aa0040330e44336eb241f0141cacb1ca53641eb4030b8b81004f10143c926020c144b7aa4ea10064606160ba02cc2f2304094418801333220102ce054e440e010960e94900e4f118801030b851028b601b362e860191e011c546f0000e454143d83192220f31943051e03000689a220812c267738c448a91da51478fd9085").into(), - difficulty: 2, - number: u64::from_str_radix("1dd8eb2", 16).unwrap(), - gas_limit: u64::from_str_radix("8583b00", 16).unwrap(), - gas_used: u64::from_str_radix("11e66dd", 16).unwrap(), - timestamp: u64::from_str_radix("64eee09a", 16).unwrap(), - extra_data: hex!("d88301020a846765746888676f312e32302e34856c696e7578000000b19df4a2f8b5830aefffb86080da9d405971b4aa87a0cc7455c8c86f66aa6be5d85343cd2d10f15aa395b600129bf59b70041f9f985e164dcce52981001cb018d076e501ea825b8a556a90ec79ad203a8adf98ef68f7cb0ef2841a171609db72931976e3077a2f393f86c906f84c8401dd8eb0a0e3439a5ce7e27a9755611e2aed8533ae2b0108ced5610f88d69fc97fd54e832d8401dd8eb1a08398b4664eb55beadbbbb8ec08dbacd78322cb3274dcd8bb53999be2b784cd9280dbd51e8fb1a5fe0e9dd4e5d685af720ee87e267ec8b47d124abb47bbe140eb507aa1ebfd4d57d888c018552c11b7cc7d420b085412fd36b4876f9dd520ea25e700").into(), - mix_digest: hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), - nonce: hex!("0000000000000000").into(), - hash: hex!("94fd52d22bffdadbdb22f6d8f5ff8843d7bb47cc4ed34170168862437d830c79"), - epoch: None - } + decode_header(hex!("f9032ea025fd8e3985b54102fa82d1354f24d18cfaf1acb63331a26e58eadf61edde12c1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948fdaaa7e6631e438625ca25c857a3727ea28e565a0d269e8b47a345f3a77343f46943f78480a96ff82a8466963fb4a29c0e2b66091a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002820bba8402625a0080846699bbb4b90111d98301040b846765746889676f312e32312e3132856c696e75780000ffcc693ef8ae03b860b81e14b27db67a9ac759e83ee9b5b4d201ed1e3756467d554bcb637cd02b59b0a715e44bcfdb66a768bfa2f51fb7488b00716aafb5e8c361e85da10144fc25f8fc6c9644228c66cea7912ac73bb13314d0e7f44818641121850a15b89b835649f848820bb8a003658f11880607bb5d603ac72c8dfa1e490d07d06dd232c0ea02acfbf51cf515820bb9a025fd8e3985b54102fa82d1354f24d18cfaf1acb63331a26e58eadf61edde12c180440276aff523d87f925f986abc8d181782d7e10088d04e2a1f09fbb0094d321d0b50d18fdccd137333e9ebafcef30e505796ebfcec6d777c7ded9e5719ed830301a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080").to_vec()) } fn epoch_header_plus_3(&self) -> ETHHeader { @@ -123,32 +77,6 @@ impl Network for Localnet { vec![header_31297211(), header_31297212(), header_31297213()].into() } - fn previous_validators(&self) -> Validators { - vec![ - vec![hex!("0bac492386862ad3df4b666bc096b0505bb694da").to_vec(), hex!("b0bec348681af766751cb839576e9c515a09c8bffa30a46296ccc56612490eb480d03bf948e10005bbcc0421f90b3d4e").to_vec()].concat(), - vec![hex!("295e26495cef6f69dfa69911d9d8e4f3bbadb89b").to_vec(), hex!("977cf58294f7239d515e15b24cfeb82494056cf691eaf729b165f32c9757c429dba5051155903067e56ebe3698678e91").to_vec()].concat(), - vec![hex!("2d4c407bbe49438ed859fe965b140dcf1aab71a9").to_vec(), hex!("93c1f7f6929d1fe2a17b4e14614ef9fc5bdc713d6631d675403fbeefac55611bf612700b1b65f4744861b80b0f7d6ab0").to_vec()].concat(), - vec![hex!("3f349bbafec1551819b8be1efea2fc46ca749aa1").to_vec(), hex!("84248a459464eec1a21e7fc7b71a053d9644e9bb8da4853b8f872cd7c1d6b324bf1922829830646ceadfb658d3de009a").to_vec()].concat(), - vec![hex!("61dd481a114a2e761c554b641742c973867899d3").to_vec(), hex!("8a80967d39e406a0a9642d41e9007a27fc1150a267d143a9f786cd2b5eecbdcc4036273705225b956d5e2f8f5eb95d25").to_vec()].concat(), - vec![hex!("70f657164e5b75689b64b7fd1fa275f334f28e18").to_vec(), hex!("96a26afa1295da81418593bd12814463d9f6e45c36a0e47eb4cd3e5b6af29c41e2a3a5636430155a466e216585af3ba7").to_vec()].concat(), - vec![hex!("72b61c6014342d914470ec7ac2975be345796c2b").to_vec(), hex!("81db0422a5fd08e40db1fc2368d2245e4b18b1d0b85c921aaaafd2e341760e29fc613edd39f71254614e2055c3287a51").to_vec()].concat(), - vec![hex!("7ae2f5b9e386cd1b50a4550696d957cb4900f03a").to_vec(), hex!("b84f83ff2df44193496793b847f64e9d6db1b3953682bb95edd096eb1e69bbd357c200992ca78050d0cbe180cfaa018e").to_vec()].concat(), - vec![hex!("8b6c8fd93d6f4cea42bbb345dbc6f0dfdb5bec73").to_vec(), hex!("a8a257074e82b881cfa06ef3eb4efeca060c2531359abd0eab8af1e3edfa2025fca464ac9c3fd123f6c24a0d78869485").to_vec()].concat(), - vec![hex!("9f8ccdafcc39f3c7d6ebf637c9151673cbc36b88").to_vec(), hex!("8819ec5ec3e97e1f03bbb4bb6055c7a5feac8f4f259df58349a32bb5cb377e2cb1f362b77f1dd398cfd3e9dba46138c3").to_vec()].concat(), - vec![hex!("a6f79b60359f141df90a0c745125b131caaffd12").to_vec(), hex!("b772e180fbf38a051c97dabc8aaa0126a233a9e828cdafcc7422c4bb1f4030a56ba364c54103f26bad91508b5220b741").to_vec()].concat(), - vec![hex!("b218c5d6af1f979ac42bc68d98a5a0d796c6ab01").to_vec(), hex!("b659ad0fbd9f515893fdd740b29ba0772dbde9b4635921dd91bd2963a0fc855e31f6338f45b211c4e9dedb7f2eb09de7").to_vec()].concat(), - vec![hex!("b4dd66d7c2c7e57f628210187192fb89d4b99dd4").to_vec(), hex!("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec()].concat(), - vec![hex!("cc8e6d00c17eb431350c6c50d8b8f05176b90b11").to_vec(), hex!("b3a3d4feb825ae9702711566df5dbf38e82add4dd1b573b95d2466fa6501ccb81e9d26a352b96150ccbf7b697fd0a419").to_vec()].concat(), - vec![hex!("ce2fd7544e0b2cc94692d4a704debef7bcb61328").to_vec(), hex!("b64abe25614c9cfd32e456b4d521f29c8357f4af4606978296c9be93494072ac05fa86e3d27cc8d66e65000f8ba33fbb").to_vec()].concat(), - vec![hex!("d1d6bf74282782b0b3eb1413c901d6ecf02e8e28").to_vec(), hex!("939e8fb41b682372335be8070199ad3e8621d1743bcac4cc9d8f0f6e10f41e56461385c8eb5daac804fe3f2bca6ce739").to_vec()].concat(), - vec![hex!("d93dbfb27e027f5e9e6da52b9e1c413ce35adc11").to_vec(), hex!("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec()].concat(), - vec![hex!("e2d3a739effcd3a99387d015e260eefac72ebea1").to_vec(), hex!("956c470ddff48cb49300200b5f83497f3a3ccb3aeb83c5edd9818569038e61d197184f4aa6939ea5e9911e3e98ac6d21").to_vec()].concat(), - vec![hex!("e9ae3261a475a27bb1028f140bc2a7c843318afd").to_vec(), hex!("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec()].concat(), - vec![hex!("ea0a6e3c511bbd10f4519ece37dc24887e11b55d").to_vec(), hex!("b2d4c6283c44a1c7bd503aaba7666e9f0c830e0ff016c1c750a5e48757a713d0836b1cabfd5c281b1de3b77d1c192183").to_vec()].concat(), - vec![hex!("ef0274e31810c9df02f98fafde0f841f4e66a1cd").to_vec(), hex!("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec()].concat(), - ] - } - fn success_update_client_non_epoch_input(&self) -> UpdateClientNonEpochInput { UpdateClientNonEpochInput { header: hex!("0a222f6962632e6c69676874636c69656e74732e7061726c69612e76312e48656164657212de1b0ab4060ab106f9032ea04788023231ff806fc9c20db23fce4c06c3b70d9038168334ec3e2095840ce534a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948fdaaa7e6631e438625ca25c857a3727ea28e565a044a1ff3b091f2f544a4d42c0772da7a8c26265f177d0472730efa0719c157d35a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028201f68402625a00808466992e3bb90111d98301040b846765746889676f312e32312e3132856c696e75780000ffcc693ef8ae03b860a5847b013e471a925b8122c9c748725825aef5d215d1ccee2b83af041eba4cf9ee211aed07fdeac7b4c2f7b85070208505e6849508cb950b2678fd27d40fb8e8a8656c050dd44f6ec33c226f108d15c6cab19080cfffbea81cdc7b1a09bc0463f8488201f4a0b4dfd14d8766b8fa4e64335fbcb53e56699c8948cb032d0bb628fc166a9321318201f5a04788023231ff806fc9c20db23fce4c06c3b70d9038168334ec3e2095840ce53480462103279b25cbd0540468881b0b90266b9ade0a60d6a93bba8a7ae4aff1d15477df78046011f78aeebf21fe63204b5e2b9b1aa8c7e26234482902addbb62a4001a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42180800ab4060ab106f9032ea0b1270c4b2a24c6bce1d07ec610c294d4b729b0c9c02d585e33018420bd6d8f5aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794d9a13701eafb76870cb220843b8c6476824bfa15a044a1ff3b091f2f544a4d42c0772da7a8c26265f177d0472730efa0719c157d35a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028201f78402625a00808466992e3eb90111d98301040b846765746889676f312e32312e3132856c696e75780000ffcc693ef8ae03b86099624ac24cb33ea9d08bbc36916d4850fabbeea8f97d320a0493c574e4ec19f443070972f6c1737e0ca5269bdb11f16507096f009f7c1298d1ea37e22d2c0565cd5ae718284f80f5704228d6bc4d36ea63d7cd9a6077b15bf8e0c973c0b54f98f8488201f5a04788023231ff806fc9c20db23fce4c06c3b70d9038168334ec3e2095840ce5348201f6a0b1270c4b2a24c6bce1d07ec610c294d4b729b0c9c02d585e33018420bd6d8f5a80f3a3f4f618fa7a483fcc7f00b52e43e90085d5371c62a34f9a7150ad13921d805762782747f63307bee2a73980fc19c19af853800c7805fec26a3e405ea2b77500a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42180800ab4060ab106f9032ea0be1699ee1c35954f180299bc9579d59ff6d57e5205cdc35c570d83d9e647d6d1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948fdaaa7e6631e438625ca25c857a3727ea28e565a044a1ff3b091f2f544a4d42c0772da7a8c26265f177d0472730efa0719c157d35a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028201f88402625a00808466992e41b90111d98301040b846765746889676f312e32312e3132856c696e75780000ffcc693ef8ae03b860af4473d99c25cbf6cce8b3b305ec3dbccff96d7c6007f123dbbcbda8286428a69da7f9145ced0f2275b11daf1b7ad1e514938274bc4f960d25026f23c2f2f8a5d8cd3d32d87b4c66062988a657dbb5cd625bb256f328e8a4a81d92f0a2389fd1f8488201f6a0b1270c4b2a24c6bce1d07ec610c294d4b729b0c9c02d585e33018420bd6d8f5a8201f7a0be1699ee1c35954f180299bc9579d59ff6d57e5205cdc35c570d83d9e647d6d18083abf2596f14299f17a96f652981b52bb794315aee435f3e277a031b4955f4866c5179198606ef2c2f691d3352d1d6daaf2a995e75212fb413f520604e7e412001a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080120310f5031a9506f90312f901f1a094e7dcd05ddcc3923085b451330f3aa5ce5a628d6685506d99cb09b3aef0e11ea02da84052a06a138dc625b9f6b0020fa250e7b1862a9ff3db6516a7e32ff33698a0b116ef7733a93eed23f018027c116e60436a228a9f9173bb9b0c40eb71216da6a0c4514d3d96fbd80ddd21b28182a517e555c417cd7683f805860098cd28a49a4380a0a74e307420bf9966d5db9a83ce48edc32c7a8e43328c6373de6875cefa04ad7aa056f4d573349c475d8d0dd015ee77c80ccc34d5742c2a7f2c266480b61f24a050a00577e3e2c4649c5a23cbdabe0bbfed7cdf6e85c136d84d58127cdec86264ad6ea070c0f30031f40c8017dbfc2ef008e6a3aae2e3105a654e0c5439b6104752882ea08f81903ec8515875682785142e1f92bdeaf65fccd5d0cf78b1ff2905a07e5883a03052420ba2d24a04d3f830584d3dbd6907b6d82bab84ddd806d03470e2c9d51ca06fb1a1498c2c8f93944a4f672ff4e982480ad181c835c0d8078159c517c7977aa013a426820f7b7249edc97cc5c002e653ac84b437f3ac12ac940c3d4b09e09827a09fbc54eac488b27315b09a1afa8d12f168e4c4cb5aea2d9a6ab5e7266da2f7e8a077c5e5cd5bd518bc509ee5e71790f1e42e492e23875b097e565cff8e809e7c8aa0d4182165b298d7b52b0f2064d19ab8bdad2b3955fa5b3d85c00673beb97e124480f8b18080a0dc77b6ae50b675036e77b31973c79ec60c28c0d2c57b03ad99c2acfff2f0cd4e80a03f47312ca98ac1f6ae9db9752c2a33529723b64e654d87f7847cee0382edfb55a05e0f116451aaa1baab3f3abff2793c8318050eeed6bf62d464d343a11d86eb2880808080808080a0abbb1987d09a71106f586030d1ab913bae0008e2a7dec0d08f2d60cd30fb2ac8a096c706907bfc6472dd88315cb8e21ee6f60a661cd8050065e2ba387023ee96858080f869a020b1e2b1f9852058ee0aaadca3c963f77f6483a1a51c644d79386bcada360583b846f8440180a0e39304f0ec064a98e4b0a96432dfb0a9e4c7fd0f26a6bbcf9c75bff68c51a7a9a0b3d632130dcb5cb583b47ec0623e59ca3703e6e2564f144272b597f3e3511ba822448fdaaa7e6631e438625ca25c857a3727ea28e56593428ee663799df81ea82bc8445a7d93c891ef324b5f4438eb766bcf75fc405fb79d3f618fcdd17f107b374368ef512f2244d9a13701eafb76870cb220843b8c6476824bfa15a82968379b116362f75bdb7cc4be8ca0ceea7c0f2e74be7c8f289cda6dcbc5edbb26400e1306c2de06f52a9a583dab992a44a7876ea32e7a748c697d01345145485561305b24903201f874819815e1a3f183c4addc814b71ec0e573e07f79ee9082926d82dd1711d6c45a9cc8841916d8563c2f80baa2a44d9a13701eafb76870cb220843b8c6476824bfa15a82968379b116362f75bdb7cc4be8ca0ceea7c0f2e74be7c8f289cda6dcbc5edbb26400e1306c2de06f52a9a583dab9930013801").to_vec(), diff --git a/light-client/src/fixture/mod.rs b/light-client/src/fixture/mod.rs index 7bc3695..e111caf 100644 --- a/light-client/src/fixture/mod.rs +++ b/light-client/src/fixture/mod.rs @@ -1,14 +1,17 @@ use crate::fixture::localnet::Localnet; -use crate::header::eth_header::ETHHeader; +use crate::header::eth_header::{get_validator_bytes, ETHHeader}; use crate::header::eth_headers::ETHHeaders; use crate::misc::{Address, ChainId, Hash, Validators}; use alloc::boxed::Box; use alloc::vec::Vec; +use hex_literal::hex; +use parlia_ibc_proto::ibc::lightclients::parlia::v1::EthHeader; pub mod localnet; pub trait Network { fn network(&self) -> ChainId; + fn previous_epoch_header(&self) -> ETHHeader; fn epoch_header(&self) -> ETHHeader; fn epoch_header_plus_1(&self) -> ETHHeader; fn epoch_header_plus_2(&self) -> ETHHeader; @@ -16,7 +19,13 @@ pub trait Network { fn headers_before_checkpoint(&self) -> ETHHeaders; fn headers_across_checkpoint(&self) -> ETHHeaders; fn headers_after_checkpoint(&self) -> ETHHeaders; - fn previous_validators(&self) -> Validators; + fn previous_validators(&self) -> Validators { + self.previous_epoch_header() + .epoch + .unwrap() + .validators() + .clone() + } fn ibc_store_address(&self) -> Address; fn success_update_client_non_epoch_input(&self) -> UpdateClientNonEpochInput; fn success_update_client_epoch_input(&self) -> UpdateClientEpochInput; @@ -53,4 +62,8 @@ pub fn localnet() -> Box { Box::new(Localnet) } +pub fn decode_header(rlp_header: Vec) -> ETHHeader { + EthHeader { header: rlp_header }.try_into().unwrap() +} + // TODO Modify testnet / mainnet after each HF released diff --git a/light-client/src/header/mod.rs b/light-client/src/header/mod.rs index 6363b69..1df94b1 100644 --- a/light-client/src/header/mod.rs +++ b/light-client/src/header/mod.rs @@ -260,7 +260,8 @@ pub(crate) mod test { use crate::header::{verify_epoch, Header}; use crate::misc::{new_height, Hash, Validators}; use alloc::boxed::Box; - use light_client::types::Time; + use alloc::vec::Vec; + use light_client::types::{Height as LCPHeight, Time}; use parlia_ibc_proto::ibc::core::client::v1::Height; use parlia_ibc_proto::ibc::lightclients::parlia::v1::Header as RawHeader; use rstest::rstest; @@ -269,6 +270,25 @@ pub(crate) mod test { pub(crate) fn eth_header(&self) -> ÐHeaders { &self.headers } + + pub(crate) fn new( + account_proof: Vec, + headers: ETHHeaders, + trusted_height: Height, + previous_epoch: Epoch, + current_epoch: Epoch, + ) -> Self { + Self { + account_proof, + headers, + trusted_height: LCPHeight::new( + trusted_height.revision_number, + trusted_height.revision_height, + ), + previous_epoch, + current_epoch, + } + } } #[rstest]