Skip to content

Commit fa463ca

Browse files
committed
split verify_acocunt_storage
Signed-off-by: yoshidan <naohiro.y@gmail.com>
1 parent da496ad commit fa463ca

File tree

1 file changed

+67
-54
lines changed

1 file changed

+67
-54
lines changed

crates/ibc/src/client_state.rs

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -125,60 +125,12 @@ impl<const SYNC_COMMITTEE_SIZE: usize> ClientState<SYNC_COMMITTEE_SIZE> {
125125
state_root: H256,
126126
account_update: &AccountUpdateInfo,
127127
) -> Result<(), Error> {
128-
match self
129-
.execution_verifier
130-
.verify_account(
131-
state_root,
132-
&self.ibc_address,
133-
account_update.account_proof.clone(),
134-
)
135-
.map_err(|e| {
136-
Error::MPTVerificationError(
137-
e,
138-
state_root,
139-
hex::encode(self.ibc_address.0),
140-
account_update
141-
.account_proof
142-
.iter()
143-
.map(hex::encode)
144-
.collect(),
145-
)
146-
})? {
147-
Some(account) => {
148-
if account_update.account_storage_root == account.storage_root {
149-
Ok(())
150-
} else {
151-
Err(Error::AccountStorageRootMismatch(
152-
account_update.account_storage_root,
153-
account.storage_root,
154-
state_root,
155-
hex::encode(self.ibc_address.0),
156-
account_update
157-
.account_proof
158-
.iter()
159-
.map(hex::encode)
160-
.collect(),
161-
))
162-
}
163-
}
164-
None => {
165-
if account_update.account_storage_root.is_zero() {
166-
Ok(())
167-
} else {
168-
Err(Error::AccountStorageRootMismatch(
169-
account_update.account_storage_root,
170-
H256::default(),
171-
state_root,
172-
hex::encode(self.ibc_address.0),
173-
account_update
174-
.account_proof
175-
.iter()
176-
.map(hex::encode)
177-
.collect(),
178-
))
179-
}
180-
}
181-
}
128+
verify_account_storage(
129+
&self.ibc_address,
130+
&self.execution_verifier,
131+
state_root,
132+
account_update,
133+
)
182134
}
183135

184136
pub fn verify_membership(
@@ -1025,6 +977,67 @@ fn verify_delay_passed(
1025977
Ok(())
1026978
}
1027979

980+
pub fn verify_account_storage(
981+
ibc_address: &Address,
982+
execution_verifier: &ExecutionVerifier,
983+
state_root: H256,
984+
account_update: &AccountUpdateInfo,
985+
) -> Result<(), Error> {
986+
match execution_verifier
987+
.verify_account(
988+
state_root,
989+
ibc_address,
990+
account_update.account_proof.clone(),
991+
)
992+
.map_err(|e| {
993+
Error::MPTVerificationError(
994+
e,
995+
state_root,
996+
hex::encode(ibc_address.0),
997+
account_update
998+
.account_proof
999+
.iter()
1000+
.map(hex::encode)
1001+
.collect(),
1002+
)
1003+
})? {
1004+
Some(account) => {
1005+
if account_update.account_storage_root == account.storage_root {
1006+
Ok(())
1007+
} else {
1008+
Err(Error::AccountStorageRootMismatch(
1009+
account_update.account_storage_root,
1010+
account.storage_root,
1011+
state_root,
1012+
hex::encode(ibc_address.0),
1013+
account_update
1014+
.account_proof
1015+
.iter()
1016+
.map(hex::encode)
1017+
.collect(),
1018+
))
1019+
}
1020+
}
1021+
None => {
1022+
if account_update.account_storage_root.is_zero() {
1023+
Ok(())
1024+
} else {
1025+
Err(Error::AccountStorageRootMismatch(
1026+
account_update.account_storage_root,
1027+
H256::default(),
1028+
state_root,
1029+
hex::encode(ibc_address.0),
1030+
account_update
1031+
.account_proof
1032+
.iter()
1033+
.map(hex::encode)
1034+
.collect(),
1035+
))
1036+
}
1037+
}
1038+
}
1039+
}
1040+
10281041
#[cfg(test)]
10291042
mod tests {
10301043
use super::*;

0 commit comments

Comments
 (0)