FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Zellic Audit] Usage of semantically incorrect types in some places · Issue #340 · BitVM/BitVM · GitHub

/ BitVM Public

[Zellic Audit] Usage of semantically incorrect types in some places #340

Description

Consider the following snippet taken from verify_scr in the function hash_messages in bitvm/src/chunk/wrap_hasher.rs:
// bottom of the stack contains the calculated hash, bring it to the top
for _ in 0..Fq::N_LIMBS {
OP_DEPTH OP_1SUB OP_ROLL
}
// top of altstack contains the claimed hash for corresponding message
{Fq::fromaltstack()}
// compare hashes
{Fq::equal(1, 0)}
The purpose of this snippet is to roll a U256 (a hash) to the top, then to fetch another U256 from the altstack, and compare them. However, to obtain the number of stack elements to roll, Fq::N_LIMBS is used. Similarly, fromaltstack and equal belonging to the Fq type are used. This is correct in this case after unpacking the values, as in all three cases only the number of limbs is relevant, and both U256 and Fq consist of the same number of limbs, namely nine. However, semantically, it would be more correct to use U256::N_LIMBS, U256::fromaltstack(), and U256::equal(1, 0) rather than Fq::N_LIMBS, Fq::fromaltstack(), and Fq::equal(1, 0). Apart from making the code clearer, using the semantically correct type also prevents bugs from occuring should configurations (such as number of bits per limb) change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL