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

PolicyTypeHash validation requires size check #206

Closed
Alrighttt opened this issue Sep 24, 2024 · 3 comments · Fixed by #207
Closed

PolicyTypeHash validation requires size check #206

Alrighttt opened this issue Sep 24, 2024 · 3 comments · Fixed by #207
Assignees

Comments

@Alrighttt
Copy link
Contributor

case PolicyTypeHash:

An additional check on the size of the preimage must be performed in this case.

I recommend checking that the preimage is 32 bytes. Technically you can support preimages less than 32 bytes, but there is no practical use for this.

See:
https://gist.github.com/markblundeberg/7a932c98179de2190049f5823907c016

@Alrighttt
Copy link
Contributor Author

Exact size check of length(preimage) == 32 is recommended, but if it will support a variable size, the size must be configurable.

ie,

type PolicyTypeHash struct {
	Len  uint16
	Hash Hash256
}

@lukechampine
Copy link
Member

Is 32 the recommended length because, in practice, these preimages are always 32-byte randomly-generated secrets? (Is there any atomic swap protocol that uses a different length secret?)

I suppose there's little point in making in variable-size, since you can always hash the preimage twice -- that is, you can always hash a preimage to get an exactly-32-byte preimage for use with PolicyTypeHash.

@Alrighttt
Copy link
Contributor Author

I suppose there's little point in making in variable-size, since you can always hash the preimage twice -- that is, you can always hash a preimage to get an exactly-32-byte preimage for use with PolicyTypeHash.

Yes, exactly. Thanks for the prompt fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants