anchor.diff:          Z   = Op(X, Y),
           Res = ?call(call_contract, Acc, C, Fun, signed_word, {X, Y}),
           Exp = case IsSafe(Z) of
  -                true  -> Z;                         %% If safe we should get back the right answer
  +                true  -> Fix(Z);                         %% If safe we should get back the right answer
                   false -> {error, <<"arithmetic_error">>}  %% otherwise out of gas (no wrap-arounds!)
                 end,
  +        ?assertMatch({_, _, _, {A, A}}, {Fun, X, Y, {Exp, Res}})
  +      end || {Fun, Op} <- Ops, X <- Values, Y <- Values ],
  +
  +    ok.
  +
  +sophia_safe_math_old() ->
  +    state(aect_test_utils:new_state()),
  +    Acc = ?call(new_account, 1000000000000),
  +    C   = ?call(create_contract, Acc, safe_math, {}),
  +
  +    <<Medium:17/unit:8>> = list_to_binary(lists:duplicate(17, $x)),
  +    <<_:1, Large:255>>   = list_to_binary(lists:duplicate(32, $o)),
  +
  +    Signed = fun(Z) -> <<Y:256/signed-integer>> = <<Z:256/unsigned-integer>>, Y end,
  +
  +    %% Reference implementation of ^
  +    Mask = fun(X) -> X rem (1 bsl 512 - 1 bsl 263 - 17) end,
  +    Pow = fun Pow(1, _, _) -> 1;
  +              Pow(_, B, _) when B < 0 -> 0;
  +              Pow(_, 0, R) -> R;                %% mask to not blow up
  +              Pow(A, B, R) when B rem 2 == 0 -> Pow(Mask(A * A), B bsr 1, R);
  +              Pow(A, B, R)                   -> Pow(Mask(A * A), B bsr 1, R * A)
  +          end,
  +
  +    %% Test vectors
  +    Values = [ Z || X <- [1, 2, 5, 173, 255, 256, 1 bsl 128 - 1, 1 bsl 128, Medium, 1 bsl 255 - 2,
  +                          1 bsl 255 - 1, 1 bsl 255, Large],
  +                    Z <- [X, -X], Z < 1 bsl 255 ],
  +    Ops    = [{add, fun erlang:'+'/2}, {sub,   fun erlang:'-'/2},
  +              {mul, fun erlang:'*'/2}, {'div', fun erlang:'div'/2},
  +              {pow, fun(X, Y) -> Pow(X, Y, 1) end}],
  +
  +    [ begin
  +        Exp = Signed(Op(X, Y)),
  +        Res = ?call(call_contract, Acc, C, Fun, signed_word, {X, Y}),
           ?assertMatch({_, _, _, {A, A}}, {Fun, X, Y, {Exp, Res}})
         end || {Fun, Op} <- Ops, X <- Values, Y <- Values ],
   
  
positive.code:                           ]}
      ].
  
  %%%===================================================================
  %%% Create contract
  %%%===================================================================
  
negative.code:                                    {tolist_s, StrList, MapS}] ],
  
      CheckSizes = fun(MI, MS) ->
              Expect1 = {maps:size(MapI), maps:size(MapS)},
              Expect2 = {maps:size(MI), maps:size(MS)},
              Actual  = {Call(size_state_i, word, {}),
                         Call(size_state_s, word, {})},
              %% Maps.size was broken i ROMA, fixed in Minerva
              ?assertMatchVM(Actual, Expect1, Expect2)
          end,
  
      %% Reset the state
  