llamaCVEVulnerability Intelligence
/
Advisory · GitHub · PyPI · vyper

GHSA-6845-XW22-FFXV

Vyper sha3 codegen bug

Parche disponible
Descargar PNG JSON
CVSS
—
low
Fuente: —
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche a 136 d de la divulgación
Exposición1.018 dDesde la divulgación, 5 feb 2024, 2:21 p. m.
Detección1.015 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Modificada
Explotación
Remediación
Parche 0.4.0
Monitoreo
Detectada
5 feb 24
20 jun 24
10 sept 26
17 nov 26
19 nov 26
5 feb 24
17 oct 24
28 jun 25
10 mar 26
19 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-6845-XW22-FFXV divulgada
Remediación Parche 0.4.0 vyper · 136 d desde divulgación
Divulgación Modificada Última actualización del registro
Monitoreo Detectada Ingresó al índice
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

### Summary
There is an error in the stack management when compiling the `IR` for `sha3_64`. 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 `sha3_64`, the `arg[0]` and `arg[1]` have to be compiled:
https://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/ir/compile_ir.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.

`sha3_64` 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:

(with _loc
	(with val 1 
		(with key 2 
			(sha3_64 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.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Versiones

Rangos afectados

Afectada Corregida Última
vyper< 0.4.0
0.4.0
0.4.3
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
pypivyper
Corregida 0.4.0 136 d 0.4.3 no afectada
Versiones corregidas0.4.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://nvd.nist.gov/vuln/detail/CVE-2024-24559
Otrahttps://github.com/vyperlang/vyper/security/advisories/GHSA-6845-xw22-ffxv
Otrahttps://github.com/vyperlang/vyper/pull/4063
Otrahttps://github.com/vyperlang/vyper/commit/d9f9fdadd81a148cbc68f02dbbbcdc0c92fad652
Otrahttps://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2024-147.yaml
Otrahttps://github.com/vyperlang/vyper
Otrahttps://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/ir/compile_ir.py#L585-L586

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.