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

Fix RangeProof::clone() memory corruption and remove rustc-serialize dependency #83

Merged
merged 3 commits into from
Apr 18, 2024

Conversation

scilio
Copy link
Contributor

@scilio scilio commented Apr 12, 2024

The previous code was copying beyond the buffer, which resulted in memory corruption. I change it from copying mem::size_of::<RangeProof>() bytes, which included the additional plen field, to just self.plen bytes.

I also removed the rustc-serialize dependency, which prevents us from building with newer rust versions.

The tests all pass for me with these changes.

@yeastplume
Copy link
Member

Thank you for looking into this, I just want to take a bit of time to understand the changes, and particularly this apparent memcpy bug (and why it's gone unnoticed for so long). I think it's because it's not actually being called from anywhere in Grin, but I need to make sure.

Do you have an example of a test somewhere that calls RangeProof::Clone and causes failure?

@yeastplume
Copy link
Member

a RangeProof field is included in the Output type grin core's core/transaction.rs, and while we don't call RangeProof::clone() explicitly anywhere, some functions that operate on vectors of them, such as to_vec() and extend_from_slice() require the Clone trait to be implemented for T, however given that Clone is a supertrait of Copy they're usually both required, and a function requiring the Clone trait doesn't necessarily mean Clone is called if a copy suffices.

Also, I don't know why someone implemented an explicit Clone function here, surely it can just be auto-derived?

@yeastplume
Copy link
Member

I have been running and testing for a while, both the wallet and node, with a modded version of the clone function that simply panics when called. So far so good, so evidence is pointing to this thankfully not being an issue in the current code. I think the clone method can safely be derived though, rather than having a custom implementation in there.

@yeastplume yeastplume merged commit 15bbb7c into mimblewimble:master Apr 18, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants