jasmin-lang / jasmin

Language for high-assurance and high-speed cryptography
MIT License
271 stars 55 forks source link

Bad errors with 128/256-bit rotations #854

Open vbgl opened 5 months ago

vbgl commented 5 months ago

Pre-typing rejects the following program:

export
fn rot(reg u128 x) -> reg u128 {
  x <<r= 4;
  return x;
}

line 3 (2-11): typing error: can not implicitly cast u64 into u128

Due to this line, pre-typing infers that the rotation operator is applied to a 64-bit value, thus produces a 64-bit value, which cannot be assigned to the 128-bit variable x.

If the rotation operator is manually annotated as <<r 128u, the error is slightly less cryptic:

typing error: invalid operator <<r128u

Note that the discrepancy with shifts (the type-checker is happy with 128-bit shifts, asm-gen complains) makes the error even more confusing.

Reported by @cos-imo.