-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add robustness to monero block extra field handling (#5826)
Description --- Added robustness to editing and parsing the extra field in a Monero block. Use cases for the extra field are: - the extra field is changed to add a merge mining hash subfield (_performed by the merge mining proxy_) - **NOT applicable, verification is not compromised** - the merge mining hash is extracted from the extra field (_performed by the merge mining proxy_) - **applicable** - a Monero block header is verified - **NOT applicable, verification is not compromised** As per Monero consensus rules, a parsing error with `ExtraField::try_parse(raw_extra_field)` will not represent a failure to de-serialize a block, as, upon error, it will just return the subfields that could be read. This means that when a Monero block template is requested by the merge mining proxy it can contain an "invalid" extra field, mainly due to the presence of a variable length `SubField::Padding(n)` with `n < 255` if not the last subfield in the extra field. If we append the merge mining tag subfield to a valid existing extra field with a variable `SubField::Padding(n)` with `n < 255` as the last subfield, the new extra field cannot be parsed successfully. To circumvent this, we insert the merge mining subfield in front of the subfield array instead of appending it at the rear. In the event that we have an invalid extra field to start with, we can now parse the extra field and clean it up in the same process before inserting the merge mining subfield. When extracting the merge mining hash we now also ignore an invalid extra field and return the merge mining hash if present. Having more than one merge mining tag subfield in a block is currently not allowed in the Tari code base, so this is now checked prior to adding the merge mining tag subfield. Motivation and Context --- See above How Has This Been Tested? --- - Pass existing tests - Extended unit test `test_duplicate_append_mm_tag` to verify that appending more than one merge mining tag will be blocked prior to validating the Monero block header and that header validation will still fail if an additional merge mining tag is present. - Added unit test `fn test_extra_field_with_parsing_error()` What process can a PR reviewer use to test or verify this change? --- Code walkthrough Familiarize the monero.rs code base <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
- Loading branch information
1 parent
61256cd
commit 597b9ef
Showing
5 changed files
with
157 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters