From 7f01d8d61f4a35e463b28404cb5b2e5ed0c73ca6 Mon Sep 17 00:00:00 2001
From: nk_ysg <nk_ysg@163.com>
Date: Thu, 2 Mar 2023 16:15:20 +0800
Subject: [PATCH] Revert "Fix sign flag for SignedInteger64 zero (#191)"

This reverts commit 722a2980fd01ee89b603235a9448fb7fa0e14351.
---
 .../bytecode_modules/SignedInteger64.mv       | Bin 506 -> 514 bytes
 .../StarcoinFramework/docs/SignedInteger64.md |  30 +++++++-------
 .../source_maps/SignedInteger64.mvsm          | Bin 5727 -> 6063 bytes
 integration-tests/signed_integer/add.exp      |   4 +-
 integration-tests/signed_integer/add.move     |  15 -------
 .../signed_integer/add_overflow.exp           |   2 +-
 integration-tests/signed_integer/divide.exp   |   2 +-
 integration-tests/signed_integer/multiply.exp |   2 +-
 integration-tests/signed_integer/sub.exp      |   4 +-
 integration-tests/signed_integer/sub.move     |  10 -----
 sources/SignedInteger64.move                  |  39 +++++++++---------
 11 files changed, 42 insertions(+), 66 deletions(-)

diff --git a/build/StarcoinFramework/bytecode_modules/SignedInteger64.mv b/build/StarcoinFramework/bytecode_modules/SignedInteger64.mv
index 366352d8adf83f798d64d8370c8e8ecd8a38e13a..d11b7f7ab288f54013bdda33c829046615de5bef 100644
GIT binary patch
delta 237
zcmYL@!41MN5CqR>Uj)uMf+!+ZzA^Ab2>((9J<tSyDge1D3ZNQZ#KxH4YHx3M-twmI
zqY7wVkNxv}YQzdUNwm{2OVK&WWV7yBY2}wKFw&T=8hR#8ei6MIS<*3QH(cq;he-^L
y$=1NA(T9uJUQPbC$x53oU?l*k5UfknZ}s2qq$O9VBEgsHP^jX1p{gaq+zlV3d=cUR

delta 229
zcmYL@y$!-Z3`TwS`2>!GqA21}I{rd~5EC!~bFcs#(9(di6a^DeaS7JZS)c9iy_^5g
zW9{!)zMs3-`8abGG{n3SNTX{yQjRu9_2Q>BDDrY#3Pfe$$q*H&#0R^aYmm^NTwAIo
vt)gImaoelf>taYoTn!i;0B3lWYYg~r?kMsq`y}|!XP<o%IQtZYkc#08fin;r

diff --git a/build/StarcoinFramework/docs/SignedInteger64.md b/build/StarcoinFramework/docs/SignedInteger64.md
index 5d4c8fc2..81d8dbda 100644
--- a/build/StarcoinFramework/docs/SignedInteger64.md
+++ b/build/StarcoinFramework/docs/SignedInteger64.md
@@ -73,7 +73,7 @@ Multiply a u64 integer by a signed integer number.
 
 <pre><code><b>public</b> <b>fun</b> <a href="SignedInteger64.md#0x1_SignedInteger64_multiply_u64">multiply_u64</a>(num: u64, multiplier: <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a>): <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> {
     <b>let</b> product = multiplier.value * num;
-    <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: product, is_negative: multiplier.is_negative }
+    <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (product <b>as</b> u64), is_negative: multiplier.is_negative }
 }
 </code></pre>
 
@@ -111,7 +111,7 @@ Divide a u64 integer by a signed integer number.
 
 <pre><code><b>public</b> <b>fun</b> <a href="SignedInteger64.md#0x1_SignedInteger64_divide_u64">divide_u64</a>(num: u64, divisor: <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a>): <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> {
     <b>let</b> quotient = num / divisor.value;
-    <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: quotient, is_negative: divisor.is_negative }
+    <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (quotient <b>as</b> u64), is_negative: divisor.is_negative }
 }
 </code></pre>
 
@@ -150,14 +150,14 @@ Sub: <code>num - minus</code>
 <pre><code><b>public</b> <b>fun</b> <a href="SignedInteger64.md#0x1_SignedInteger64_sub_u64">sub_u64</a>(num: u64, minus: <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a>): <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> {
     <b>if</b> (minus.is_negative) {
         <b>let</b> result = num + minus.value;
-        <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: result, is_negative: <b>false</b> }
+        <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (result <b>as</b> u64), is_negative: <b>false</b> }
     } <b>else</b> {
-        <b>if</b> (num &gt;= minus.value) {
+        <b>if</b> (num &gt; minus.value)  {
             <b>let</b> result = num - minus.value;
-            <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: result, is_negative: <b>false</b> }
+            <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (result <b>as</b> u64), is_negative: <b>false</b> }
         }<b>else</b> {
             <b>let</b> result = minus.value - num;
-            <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: result, is_negative: <b>true</b> }
+            <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (result <b>as</b> u64), is_negative: <b>true</b> }
         }
     }
 }
@@ -197,16 +197,16 @@ Add: <code>num + addend</code>
 
 <pre><code><b>public</b> <b>fun</b> <a href="SignedInteger64.md#0x1_SignedInteger64_add_u64">add_u64</a>(num: u64, addend: <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a>): <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> {
     <b>if</b> (addend.is_negative) {
-        <b>if</b> (num &gt;= addend.value) {
-            <b>let</b> result = num - addend.value;
-            <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: result, is_negative: <b>false</b> }
-        }<b>else</b> {
-            <b>let</b> result = addend.value - num;
-            <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: result, is_negative: <b>true</b> }
-        }
+       <b>if</b> (num &gt; addend.value)  {
+           <b>let</b> result = num - addend.value;
+           <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (result <b>as</b> u64), is_negative: <b>false</b> }
+       }<b>else</b> {
+           <b>let</b> result = addend.value - num;
+           <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (result <b>as</b> u64), is_negative: <b>true</b> }
+       }
     } <b>else</b> {
-        <b>let</b> result = num + addend.value;
-        <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: result, is_negative: <b>false</b> }
+         <b>let</b> result = num + addend.value;
+         <a href="SignedInteger64.md#0x1_SignedInteger64">SignedInteger64</a> { value: (result <b>as</b> u64), is_negative: <b>false</b> }
     }
 }
 </code></pre>
diff --git a/build/StarcoinFramework/source_maps/SignedInteger64.mvsm b/build/StarcoinFramework/source_maps/SignedInteger64.mvsm
index 1c9f9d8b237a2ad3f00f554c161e477a854caeb4..61f625963ba20a0676aecb5bc518f36541f5e7fb 100644
GIT binary patch
literal 6063
zcma)<TWC~Q7)H-bGMP!nTr@QpYhpA;Z5pk&il7w=f~HhOi;x;oqjLzSPG-`~Ow!g1
zh*0rG!76Cu1ufJ>j0$R7i&Uy0q1IMGV=a9sc~E-s@}MnkQ|;Q64ZeMQV7;yR&%XWV
z?63UShx@PGI#+zAxH<i>r~OQIa(Lywy?<Wx-k)6ERl9Tce9!Y1LkOP#g-YKFT2p?a
zF_raO{f^nQ5XwcZk0@}|6bUQyGEzS%?>5dLM70_#@Vrv+!g;A&n<`v}Sq=p)iG-g@
zD19_)4Mg(lYG)`pgV@7}ac3!a3GQn##?j$ta>=aHkDwoe*#CO%boGZBjAIViKg?8r
zxQcuOyh(b=mot(k2+4gkW&-l0X%{3S%`WPF00q+AjI|A-PUa5GLTPTq+5|<?w8vqX
zG>=oS4~nIE8tXGCaWXGpmPzv@)+rb+O?wJQNb?@`?nAjW?_xcH7o?fb=`4hi(!55!
zIA(=3?H-Mi=3MH%4wX*kLd+MX`3BZv7$eO^SdCC6P22d@(tMA4TVSj-yRbfl8fosu
z+7IKTxf-h*#!J)g(FAGQcgRF(-sH)*VUjd|#QGT~JDGPe>!tYv)*X0Rn)a>SAk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cL`~&MOl*l<U<^|Bv@if-&prfPR&N@0ipxzVE(J^F>AJEb9D)nNR
zIy&0U>*zR}dR0&=`)SN-D3fLl)?(1naRJss_(ayU=b{do?bQ1YbjaL^)d@Oe)?@7k
P9Wrg_b#%1*-Sgf6*P1q>

diff --git a/integration-tests/signed_integer/add.exp b/integration-tests/signed_integer/add.exp
index f6b3dc0b..ab0e2edd 100644
--- a/integration-tests/signed_integer/add.exp
+++ b/integration-tests/signed_integer/add.exp
@@ -1,7 +1,7 @@
 processed 3 tasks
 
-task 2 'run'. lines 5-41:
+task 2 'run'. lines 5-26:
 {
-  "gas_used": 100723,
+  "gas_used": 54451,
   "status": "Executed"
 }
diff --git a/integration-tests/signed_integer/add.move b/integration-tests/signed_integer/add.move
index 12d9505f..efa879cd 100644
--- a/integration-tests/signed_integer/add.move
+++ b/integration-tests/signed_integer/add.move
@@ -22,20 +22,5 @@ fun main() {
     let i2 = SignedInteger64::create_from_raw_value(0, false);
     let z2 = SignedInteger64::add_u64(100, copy i2);
     assert!(SignedInteger64::get_value(z2) == 100, 6);
-
-    let i3 = SignedInteger64::create_from_raw_value(1, true);
-    let z3 = SignedInteger64::add_u64(1, i3);
-    assert!(SignedInteger64::get_value(copy z3) == 0, 7);
-    assert!(SignedInteger64::is_negative(z3) == false, 8);
-
-    let i4 = SignedInteger64::create_from_raw_value(0, true);
-    let z4 = SignedInteger64::add_u64(0, i4);
-    assert!(SignedInteger64::get_value(copy z4) == 0, 9);
-    assert!(SignedInteger64::is_negative(z4) == false, 10);
-
-    let i5 = SignedInteger64::create_from_raw_value(0, false);
-    let z5 = SignedInteger64::add_u64(0, i5);
-    assert!(SignedInteger64::get_value(copy z5) == 0, 11);
-    assert!(SignedInteger64::is_negative(z5) == false, 12);
 }
 }
\ No newline at end of file
diff --git a/integration-tests/signed_integer/add_overflow.exp b/integration-tests/signed_integer/add_overflow.exp
index c0510b88..c3cca6af 100644
--- a/integration-tests/signed_integer/add_overflow.exp
+++ b/integration-tests/signed_integer/add_overflow.exp
@@ -12,7 +12,7 @@ task 2 'run'. lines 5-16:
         }
       },
       "function": 0,
-      "code_offset": 40
+      "code_offset": 42
     }
   }
 }
diff --git a/integration-tests/signed_integer/divide.exp b/integration-tests/signed_integer/divide.exp
index 663ea9ce..debe8124 100644
--- a/integration-tests/signed_integer/divide.exp
+++ b/integration-tests/signed_integer/divide.exp
@@ -2,6 +2,6 @@ processed 3 tasks
 
 task 2 'run'. lines 5-26:
 {
-  "gas_used": 53253,
+  "gas_used": 53261,
   "status": "Executed"
 }
diff --git a/integration-tests/signed_integer/multiply.exp b/integration-tests/signed_integer/multiply.exp
index 4f28423f..4dd911e9 100644
--- a/integration-tests/signed_integer/multiply.exp
+++ b/integration-tests/signed_integer/multiply.exp
@@ -2,6 +2,6 @@ processed 3 tasks
 
 task 2 'run'. lines 5-23:
 {
-  "gas_used": 45720,
+  "gas_used": 45726,
   "status": "Executed"
 }
diff --git a/integration-tests/signed_integer/sub.exp b/integration-tests/signed_integer/sub.exp
index 927616f9..ab0e2edd 100644
--- a/integration-tests/signed_integer/sub.exp
+++ b/integration-tests/signed_integer/sub.exp
@@ -1,7 +1,7 @@
 processed 3 tasks
 
-task 2 'run'. lines 5-36:
+task 2 'run'. lines 5-26:
 {
-  "gas_used": 84861,
+  "gas_used": 54451,
   "status": "Executed"
 }
diff --git a/integration-tests/signed_integer/sub.move b/integration-tests/signed_integer/sub.move
index c32676cd..1cc37569 100644
--- a/integration-tests/signed_integer/sub.move
+++ b/integration-tests/signed_integer/sub.move
@@ -22,15 +22,5 @@ fun main() {
     let i2 = SignedInteger64::create_from_raw_value(100, true);
     let z2 = SignedInteger64::sub_u64(100, copy i2);
     assert!(SignedInteger64::get_value(z2) == 200, 6);
-
-    let i3 = SignedInteger64::create_from_raw_value(0, true);
-    let z3 = SignedInteger64::sub_u64(0, i3);
-    assert!(SignedInteger64::get_value(copy z3) == 0, 1);
-    assert!(SignedInteger64::is_negative(z3) == false, 2);
-
-    let i4 = SignedInteger64::create_from_raw_value(0, false);
-    let z4 = SignedInteger64::sub_u64(0, i4);
-    assert!(SignedInteger64::get_value(copy z4) == 0, 1);
-    assert!(SignedInteger64::is_negative(z4) == false, 2);
 }
 }
\ No newline at end of file
diff --git a/sources/SignedInteger64.move b/sources/SignedInteger64.move
index 5258cc78..b61c83ba 100644
--- a/sources/SignedInteger64.move
+++ b/sources/SignedInteger64.move
@@ -16,44 +16,43 @@ module SignedInteger64 {
     /// Multiply a u64 integer by a signed integer number.
     public fun multiply_u64(num: u64, multiplier: SignedInteger64): SignedInteger64 {
         let product = multiplier.value * num;
-        SignedInteger64 { value: product, is_negative: multiplier.is_negative }
+        SignedInteger64 { value: (product as u64), is_negative: multiplier.is_negative }
     }
 
     /// Divide a u64 integer by a signed integer number.
     public fun divide_u64(num: u64, divisor: SignedInteger64): SignedInteger64 {
         let quotient = num / divisor.value;
-        SignedInteger64 { value: quotient, is_negative: divisor.is_negative }
+        SignedInteger64 { value: (quotient as u64), is_negative: divisor.is_negative }
     }
 
     /// Sub: `num - minus`
     public fun sub_u64(num: u64, minus: SignedInteger64): SignedInteger64 {
         if (minus.is_negative) {
             let result = num + minus.value;
-            SignedInteger64 { value: result, is_negative: false }
+            SignedInteger64 { value: (result as u64), is_negative: false }
         } else {
-            if (num >= minus.value) {
+            if (num > minus.value)  {
                 let result = num - minus.value;
-                SignedInteger64 { value: result, is_negative: false }
+                SignedInteger64 { value: (result as u64), is_negative: false }
             }else {
                 let result = minus.value - num;
-                SignedInteger64 { value: result, is_negative: true }
+                SignedInteger64 { value: (result as u64), is_negative: true }
             }
         }
     }
-
     /// Add: `num + addend`
     public fun add_u64(num: u64, addend: SignedInteger64): SignedInteger64 {
         if (addend.is_negative) {
-            if (num >= addend.value) {
-                let result = num - addend.value;
-                SignedInteger64 { value: result, is_negative: false }
-            }else {
-                let result = addend.value - num;
-                SignedInteger64 { value: result, is_negative: true }
-            }
+           if (num > addend.value)  {
+               let result = num - addend.value;
+               SignedInteger64 { value: (result as u64), is_negative: false }
+           }else {
+               let result = addend.value - num;
+               SignedInteger64 { value: (result as u64), is_negative: true }
+           }
         } else {
-            let result = num + addend.value;
-            SignedInteger64 { value: result, is_negative: false }
+             let result = num + addend.value;
+             SignedInteger64 { value: (result as u64), is_negative: false }
         }
     }
 
@@ -74,8 +73,10 @@ module SignedInteger64 {
 
     // **************** SPECIFICATIONS ****************
 
+    
+
     spec multiply_u64 {
-        aborts_if multiplier.value * num > max_u64();
+       aborts_if multiplier.value * num > max_u64();
     }
 
     spec divide_u64 {
@@ -87,7 +88,7 @@ module SignedInteger64 {
     }
 
     spec add_u64 {
-        aborts_if !addend.is_negative && num + addend.value > max_u64();
+       aborts_if !addend.is_negative && num + addend.value > max_u64();
     }
 
     spec create_from_raw_value {
@@ -104,6 +105,6 @@ module SignedInteger64 {
         aborts_if false;
         ensures result == num.is_negative;
     }
-
 }
+
 }