Skip to content
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

Significant dyn-abi fixes :) #168

Merged
merged 17 commits into from
Jul 3, 2023
Merged

Significant dyn-abi fixes :) #168

merged 17 commits into from
Jul 3, 2023

Conversation

prestwich
Copy link
Member

@prestwich prestwich commented Jul 2, 2023

closes #167

Motivation

Branch was initially to add tests to dyn-abi. Uncovered a few bugs

Solution

  • fix indirection in dyn sequence decoding
  • fix offset propagation in DynToken::FixedSeq decoding
  • fix DynSolValue::tail_words impl for fixed and dyn sequences
  • improve code quality generally for sequences
  • cool & useful display impl for Decoder
  • feat: DynSolValue::total_words
  • tests: start migrating them to dyn-abi
  • fix: parsing of (bool,) single-element tuples in dyn sol type parser

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@prestwich prestwich added bug Something isn't working enhancement New feature or request labels Jul 2, 2023
@prestwich prestwich requested a review from DaniPopes as a code owner July 2, 2023 22:33
@prestwich prestwich self-assigned this Jul 2, 2023

self.decode_sequence_populate(&mut child)?;

if !dynamic {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: missed offset propagation resulted in bad decoding

@@ -470,16 +470,23 @@ impl DynSolValue {
}

if let Some(vals) = self.as_fixed_seq() {
return self.is_dynamic() as usize * vals.len()
return self.is_dynamic() as usize * vals.iter().map(Self::total_words).sum::<usize>()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: incorrect tail words for fixed seqs

}

if let Some(vals) = self.as_array() {
return 1 + vals.iter().map(Self::tail_words).sum::<usize>()
// 1 for the length. Then all words for all elements.
return 1 + vals.iter().map(Self::total_words).sum::<usize>()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: incorrect tail words for dyn seqs

crates/dyn-abi/src/type.rs Show resolved Hide resolved
crates/sol-types/src/coder/decoder.rs Outdated Show resolved Hide resolved
crates/sol-types/src/coder/decoder.rs Outdated Show resolved Hide resolved
crates/sol-types/src/coder/decoder.rs Outdated Show resolved Hide resolved
@prestwich prestwich changed the title fix: decode relative to first word of dyn array body Significant dyn-abi fixes :) Jul 3, 2023
@@ -202,7 +203,11 @@ impl<'a> TryFrom<&'a str> for TupleSpecifier<'a> {
_ => {}
}
}
types.push(value[start..].try_into()?);
// handle termina commas in tuples
let candidate = value[start..].trim();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bug. for (T,) it would include the blank string, which would fail parsing into a typespecifier

crates/dyn-abi/src/parser.rs Outdated Show resolved Hide resolved
crates/dyn-abi/src/parser.rs Outdated Show resolved Hide resolved
crates/dyn-abi/src/token.rs Outdated Show resolved Hide resolved
crates/dyn-abi/src/parser.rs Outdated Show resolved Hide resolved
Copy link
Member

@DaniPopes DaniPopes left a 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 test case for parsing nested tuples? rest LGTM

@prestwich prestwich merged commit ca37a23 into main Jul 3, 2023
@DaniPopes DaniPopes deleted the prestwich/test-dyn-enc branch July 10, 2023 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Certain dynamic data fails to decode
2 participants