Philogy / balls

A DSL for generating optimal EVM bytecode
MIT License
184 stars 7 forks source link

Swap depth issue with `addmod` and `mulmod` #5

Closed zemse closed 5 months ago

zemse commented 5 months ago

Input code:

fn HEY(x, y) -> (z) {
    z = addmod(x, y, 3)
}

Actual output:

#define macro HEY() = takes(2) returns(1) {
    // takes:                      [y, x]
    0x3                         // [y, x, 0x3]
    swap1                       // [y, 0x3, x]
    addmod                      // [z]
    // returns:                    [z]
}

Expected output:

#define macro HEY() = takes(2) returns(1) {
    // takes:                      [y, x]
    0x3                         // [y, x, 0x3]
-   swap1                       // [y, 0x3, x]
+   swap2                       // [y, x, 0x3]
    addmod                      // [z]
    // returns:                    [z]
}
Philogy commented 5 months ago

Thanks for reporting, have confirmed and will fix later this week.

Will-Smith11 commented 5 months ago

@Philogy Crit in balls :sob:

Philogy commented 5 months ago

Fixed in df45004, thanks for reporting!