CVE-2024-24559: Vyper SHA3 code generation bug

Published Feb 5, 2024
·
Updated

Summary There is an error in the stack management when compiling the IR for sha364. Concretely, the height variable is miscalculated. The vulnerability can't be triggered without writing the IR by hand. That is, it cannot be triggered from regular vyper code, it can only be triggered by using the fang binary directly (this binary used to be called vyper-ir prior to v0.3.4).

Details To compile sha364, the arg[0] and arg[1] have to be compiled: https://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/ir/compileir.py#L585-L586

As can be seen, after compiling the 0th arg, the height variable isn't increased. If new withargs are defined in the inner scope, they are manipulated correctly, because both their height is off and also the global height is off and thus their placement on the stack is computed correctly.

sha364 is used for retrieval in mappings. No flow that would cache the key was found, the issue shouldn't be possible to trigger when compiling the compiler-generated IR.

PoC Suppose the following hand-written IR: lisp (with loc (with val 1 (with key 2 (sha364 val key))) (seq (sstore loc (with x (sload loc) (with ans (add x 1) (seq (assert (ge ans x)) ans)))))) after compilation: the generated bytecode: 6001600281806020525f5260405f2090509050805460018101818110610026579050815550005b5f80fd

0000 60 PUSH1 0x01 0002 60 PUSH1 0x02 0004 81 DUP2 0005 80 DUP1 bad code here!!!!!! 0006 60 PUSH1 0x20 0008 52 MSTORE

It can be seen that the second DUP will dup the item on the top of the stack which is incorrect.

Patches Patched in https://github.com/vyperlang/vyper/pull/4063.

Impact Versions v0.2.0-v0.3.10 were evaluated, and access of the variable with the invalid height is not reachable from IR generated by the vyper front-end. Because the issue isn't triggered during normal compilation of vyper code, the impact is considered low.

Other sources

Vyper is a Pythonic Smart Contract Language for the EVM. There is an error in the stack management when compiling the IR for sha364. Concretely, the height variable is miscalculated. The vulnerability can't be triggered without writing the IR by hand (that is, it cannot be triggered from regular vyper code). sha364 is used for retrieval in mappings. No flow that would cache the key was found so the issue shouldn't be possible to trigger when compiling the compiler-generated IR. This issue isn't triggered during normal compilation of vyper code so the impact is low. At the time of publication there is no patch available.

— MITRE

Affected Software

2 affected componentsFixes available
pip/vyper<0.4.0
0.4.0
vyperlang Vyper Python<=0.3.10

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/vyper to a version that resolves this vulnerability.

    Fixed in 0.4.0
  2. Upgrade

    Upgrade vyper to a version that resolves this vulnerability.

    Patch https://github.com/vyperlang/vyper/pull/4063

Event History

Feb 5, 2024
Advisory Published
via GitHub·07:21 PM
CVE Published
via MITRE·09:04 PM
Data Sourced
via MITRE·09:04 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·09:15 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2024-24559?

The severity of CVE-2024-24559 is considered moderate due to the specific conditions required to exploit it.

2

How do I fix CVE-2024-24559?

To fix CVE-2024-24559, upgrade to Vyper version 0.4.0 or later.

3

Which versions of Vyper are affected by CVE-2024-24559?

CVE-2024-24559 affects Vyper versions up to 0.4.0, including all versions prior to 0.4.0.

4

Can CVE-2024-24559 be exploited through regular Vyper code?

No, CVE-2024-24559 cannot be triggered through standard Vyper code and requires manual IR writing.

5

What is the nature of the vulnerability in CVE-2024-24559?

CVE-2024-24559 is a stack management error related to the miscalculation of the 'height' variable when compiling the IR for sha3_64.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203