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

pallet-referenda: Detect incorrect pre-image length #3850

Merged
merged 4 commits into from
Mar 28, 2024

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Mar 27, 2024

There has been a case that a referenda failed because the length given to submit was incorrect. The pallet can actually check the length if the pre-image already exists to ensure that these kind of issues are not happening again.

There has been a case that a referenda failed because the length given
to `submit` was incorrect. The pallet can actually check the length if
the pre-image already exists to ensure that these kind of issues are not
happening again.
@bkchr bkchr added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Mar 27, 2024
@bkchr bkchr requested a review from a team as a code owner March 27, 2024 02:42
// If the pre-image is already stored, ensure that it has the same length as given in
// `proposal`.
if let Some(hash) = proposal.lookup_hash() {
if let Some((l, r)) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if let Some((l, r)) =
if let Some((preimage_length, proposal_length)) =

😅

Copy link
Contributor

Choose a reason for hiding this comment

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

			ensure!(
				proposal.lookup_hash()
					.and_then(|hash| T::Preimages::len(&hash))
					.map(|hash_len| hash_len != proposal.lookup_len().unwrap_or(u32::MAX))
					.unwrap_or(true),
				Error::<T, I>::PreimageStoredWithDifferentLength
			)

just playing some Option API games :D

@bkchr bkchr enabled auto-merge March 27, 2024 23:27
@bkchr bkchr added this pull request to the merge queue Mar 27, 2024
Merged via the queue into master with commit 5d314eb Mar 28, 2024
127 of 132 checks passed
@bkchr bkchr deleted the bkchr-referenda-detect-wrong-length branch March 28, 2024 00:18
@Morganamilo Morganamilo mentioned this pull request Apr 4, 2024
12 tasks
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this pull request Apr 9, 2024
There has been a case that a referenda failed because the length given
to `submit` was incorrect. The pallet can actually check the length if
the pre-image already exists to ensure that these kind of issues are not
happening again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants