-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imp(ics23): fallible conversion for ProofSpec
, LeafOp
, InnerSpec
#1160
imp(ics23): fallible conversion for ProofSpec
, LeafOp
, InnerSpec
#1160
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good ! 👍 Thanks for the PR
Requested some changes.
return Err(CommitmentError::InvalidDepthRange(spec.min_depth, spec.max_depth)); | ||
} | ||
|
||
let leaf_spec = spec.leaf_spec.map(|lop| LeafOp::from(lop)).map(|lop| lop.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let leaf_spec = spec.leaf_spec.map(|lop| LeafOp::from(lop)).map(|lop| lop.0); | |
let leaf_spec = spec.leaf_spec.map(LeafOp::from).map(|lop| lop.0); |
let mut specs = Vec::new(); | ||
for raw_spec in ics23_specs { | ||
let spec = ProofSpec::try_from(raw_spec)?; | ||
specs.push(spec); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use
let specs = ics23_specs
.into_iter()
.map(ProofSpec::try_from)
.collect::<Result<Vec<_>, _>>()?;
// Test { | ||
// name: "Invalid (empty) proof specs".to_string(), | ||
// params: ClientStateParams { | ||
// proof_specs: Vec::<Ics23ProofSpec>::new(), | ||
// ..default_params.clone() | ||
// }, | ||
// want_pass: false, | ||
// }, | ||
// Test { | ||
// name: "Invalid (empty) proof specs depth range".to_string(), | ||
// params: ClientStateParams { | ||
// proof_specs: vec![Ics23ProofSpec { | ||
// leaf_spec: None, | ||
// inner_spec: None, | ||
// min_depth: 2, | ||
// max_depth: 1, | ||
// prehash_key_before_comparison: false, | ||
// }], | ||
// ..default_params | ||
// }, | ||
// want_pass: false, | ||
// }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add these tests? I guess that these failed to be created - because of try_from
. In that case, add them as unit tests for your new TryFrom
implementations.
if inner_spec.child_size <= 0 { | ||
return Err(CommitmentError::InvalidChildSize(inner_spec.child_size)); | ||
} | ||
if inner_spec.min_prefix_length > inner_spec.max_prefix_length | ||
|| inner_spec.min_prefix_length < 0 | ||
|| inner_spec.max_prefix_length < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comments about the failure cases.
if spec.max_depth < spec.min_depth | ||
|| spec.min_depth < 0 | ||
|| spec.max_depth < 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comments about the failure case.
example: why 0
is case is allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I am not certain about this, given some thought, I guess when min_depth or max_depth is negative, it specify that no lower or upper bound is enforced on the number of allowed InnerOps(proof specs) As a result something like min_depth=2, max_depth=-1
is perfectly fine.
Would love to hear your opinion @rnbguy, I think the failure case should be limited to only if spec.max_depth>0 && spec.min_depth>0 && spec.max_depth < spec.min_depth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey sorry for not explaining myself 😅 I know the logic. I suggested adding them in the comments.
You can refer to the comments in protobuf definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rnbguy yes but do you think
spec.max_depth < spec.min_depth
|| spec.min_depth < 0
|| spec.max_depth < 0
is correct or it should be as I mention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last comment is not right. The error case should be following, as you mentioned already,
0 < spec.min_depth && 0 < spec.max_depth && spec.max_depth < spec.min_depth
So, if both of min_depth
and max_depth
are greater than zero, min_depth <= max_depth
. Add the logic in the comment to avoid confusion.
Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]>
fix for consistency Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]>
…-labs/ibc-rs into tuan/add-specs-conversion-check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few last requests 🙏
Test { | ||
name: "Invalid (empty) proof specs".to_string(), | ||
params: ClientStateParams { | ||
proof_specs: Vec::<Ics23ProofSpec>::new().into(), | ||
..default_params.clone() | ||
}, | ||
want_pass: false, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we can leave this test here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove it after disallowing empty proof specs in Vec<RawProofSpec>::try_from
.
min_depth: 2, | ||
max_depth: 1, | ||
prehash_key_before_comparison: false, | ||
}].into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm - this test is removed because min_depth: 2
and max_depth: 1
is not a valid Ics23ProofSpec
after deserialization from protobuf?
I think, it's still ok to leave them here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update: this will fail when unwrapping. so this must be removed.
if inner_spec.max_prefix_length < inner_spec.min_prefix_length | ||
|| inner_spec.min_prefix_length < 0 | ||
|| inner_spec.max_prefix_length < 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here as well?
The point here is - these values are used regardless they are negative. So they must be positive. I am not sure why this is not specified in ics23. In Go impl, they are just used as integers.
let valid_raw_proof_spec = vec![ | ||
RawProofSpec { | ||
leaf_spec: None, | ||
inner_spec: None, | ||
max_depth: 5, | ||
min_depth: 3, | ||
prehash_key_before_comparison: false, | ||
}, | ||
RawProofSpec { | ||
leaf_spec: None, | ||
inner_spec: None, | ||
max_depth: -3, | ||
min_depth: 3, | ||
prehash_key_before_comparison: false, | ||
}, | ||
RawProofSpec { | ||
leaf_spec: None, | ||
inner_spec: None, | ||
max_depth: 2, | ||
min_depth: -6, | ||
prehash_key_before_comparison: false, | ||
}, | ||
RawProofSpec { | ||
leaf_spec: None, | ||
inner_spec: None, | ||
max_depth: -2, | ||
min_depth: -6, | ||
prehash_key_before_comparison: false, | ||
}, | ||
RawProofSpec { | ||
leaf_spec: None, | ||
inner_spec: None, | ||
max_depth: -6, | ||
min_depth: -2, | ||
prehash_key_before_comparison: false, | ||
}, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please use parametrized case from rstest
here?
let invalid_raw_inner_spec = vec![ | ||
RawInnerSpec { | ||
child_order: vec![1], | ||
child_size: 2, | ||
min_prefix_length: 2, | ||
max_prefix_length: 1, | ||
empty_child: vec![], | ||
hash: 1, | ||
}, | ||
RawInnerSpec { | ||
child_order: vec![1], | ||
child_size: 2, | ||
min_prefix_length: -1, | ||
max_prefix_length: 1, | ||
empty_child: vec![], | ||
hash: 1, | ||
}, | ||
RawInnerSpec { | ||
child_order: vec![1], | ||
child_size: 2, | ||
min_prefix_length: 1, | ||
max_prefix_length: -1, | ||
empty_child: vec![], | ||
hash: 1, | ||
}, | ||
RawInnerSpec { | ||
child_order: vec![1], | ||
child_size: 2, | ||
min_prefix_length: -1, | ||
max_prefix_length: -1, | ||
empty_child: vec![], | ||
hash: 1, | ||
}, | ||
RawInnerSpec { | ||
child_order: vec![1], | ||
child_size: 2, | ||
min_prefix_length: 2, | ||
max_prefix_length: 1, | ||
empty_child: vec![], | ||
hash: 1, | ||
}, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parametrized cases from rstest
here too 🙂
hey. we had a discussion about the error scenarios for So, the error conditions for:
sorry for any confusion from my earlier comments. |
Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]>
Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]>
…-labs/ibc-rs into tuan/add-specs-conversion-check
Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]>
can you give me permission to edit your PR? I want to make some changes before we merge. |
Ah, I just noticed that |
…-labs/ibc-rs into tuan/add-specs-conversion-check
isaacs/github#1681 Yeah I guess I couldn't enable this, not able to find the option in my own PR. Could you kindly suggest the changes and I would resolve it asap.
I think there's no need to add conversion check for |
Ah, I wasn't aware. I pushed changes to my branch rano/pr/1160. It's rebased from your fork - so you can just
The enum values should be validated. I added the respective changes at my branch. |
ProofSpec
, LeafOp
, InnerSpec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tropicaldog ! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thank you!
#1160) * feat(ics23): add conversion checks * fix compiler error * comment out depth range tests * Update ibc-core/ics23-commitment/types/src/specs.rs Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]> * Update ibc-core/ics23-commitment/types/src/specs.rs fix for consistency Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]> * add tests and linting * refactor loop * Update ibc-core/ics23-commitment/types/src/specs.rs Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]> * Update ibc-core/ics23-commitment/types/src/specs.rs Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]> * add parameterized test * Update ibc-core/ics23-commitment/types/src/specs.rs Co-authored-by: Rano | Ranadeep <[email protected]> Signed-off-by: Tuan Tran <[email protected]> * update err comment * update tests * add rstest in dev-deps * code opt * add HashOp and LengthOp validations * code opt * update the range validation predicates and comments * empty proof specs are disallowed * rename test fn * update test cases --------- Signed-off-by: Tuan Tran <[email protected]> Co-authored-by: Rano | Ranadeep <[email protected]> Co-authored-by: Ranadeep Biswas <[email protected]>
Closes: #1108
Description
Add conversion checks for
ProofSpec
,LeafOp
, andInnerSpec
structs.PR author checklist:
unclog
.docs/
).Reviewer checklist:
Files changed
in the GitHub PR explorer./cc @Farhad-Shabani @rnbguy