madfish-solutions / sol2ligo

⌨️ 🔮 Transpiler from Solidity to PascalLIGO language
https://madfish-solutions.github.io/sol2ligo/
MIT License
70 stars 4 forks source link

Subtraction being translated as abs(a - b), consider more adequate translation #304

Open machulen opened 4 years ago

machulen commented 4 years ago

Sample:

pragma solidity ^0.5.0;

contract C {
 function f() public {
  uint8 a = 2;
  uint8 b = 5;
  uint8 c = a - b;
 }
}

Translated:

type state is unit;

function f (const res__unit : unit) : (unit) is
  block {
    const a : nat = 2n;
    const b : nat = 5n;
    const c : nat = abs(a - b);
  } with (unit);

This preserves the type (nat) but produces wrong value 3, whereas in Solidity it would be 253