1010import lombok .Setter ;
1111import lombok .extern .slf4j .Slf4j ;
1212import org .apache .commons .lang3 .ArrayUtils ;
13+ import org .tron .common .math .StrictMathWrapper ;
1314import org .tron .common .utils .ByteArray ;
1415import org .tron .common .zksnark .IncrementalMerkleVoucherContainer ;
1516import org .tron .common .zksnark .JLibrustzcash ;
@@ -67,7 +68,7 @@ public ZenTransactionBuilder() {
6768
6869 public void addSpend (SpendDescriptionInfo spendDescriptionInfo ) {
6970 spends .add (spendDescriptionInfo );
70- valueBalance += spendDescriptionInfo .note .getValue ();
71+ valueBalance = StrictMathWrapper . addExact ( valueBalance , spendDescriptionInfo .note .getValue () );
7172 }
7273
7374 public void addSpend (
@@ -76,7 +77,7 @@ public void addSpend(
7677 byte [] anchor ,
7778 IncrementalMerkleVoucherContainer voucher ) throws ZksnarkException {
7879 spends .add (new SpendDescriptionInfo (expsk , note , anchor , voucher ));
79- valueBalance += note .getValue ();
80+ valueBalance = StrictMathWrapper . addExact ( valueBalance , note .getValue () );
8081 }
8182
8283 public void addSpend (
@@ -86,7 +87,7 @@ public void addSpend(
8687 byte [] anchor ,
8788 IncrementalMerkleVoucherContainer voucher ) {
8889 spends .add (new SpendDescriptionInfo (expsk , note , alpha , anchor , voucher ));
89- valueBalance += note .getValue ();
90+ valueBalance = StrictMathWrapper . addExact ( valueBalance , note .getValue () );
9091 }
9192
9293 public void addSpend (
@@ -98,22 +99,22 @@ public void addSpend(
9899 byte [] anchor ,
99100 IncrementalMerkleVoucherContainer voucher ) {
100101 spends .add (new SpendDescriptionInfo (ak , nsk , ovk , note , alpha , anchor , voucher ));
101- valueBalance += note .getValue ();
102+ valueBalance = StrictMathWrapper . addExact ( valueBalance , note .getValue () );
102103 }
103104
104105 public void addOutput (byte [] ovk , PaymentAddress to , long value , byte [] memo )
105106 throws ZksnarkException {
106107 Note note = new Note (to , value );
107108 note .setMemo (memo );
108109 receives .add (new ReceiveDescriptionInfo (ovk , note ));
109- valueBalance -= value ;
110+ valueBalance = StrictMathWrapper . subtractExact ( valueBalance , value ) ;
110111 }
111112
112113 public void addOutput (byte [] ovk , DiversifierT d , byte [] pkD , long value , byte [] r , byte [] memo ) {
113114 Note note = new Note (d , pkD , value , r );
114115 note .setMemo (memo );
115116 receives .add (new ReceiveDescriptionInfo (ovk , note ));
116- valueBalance -= value ;
117+ valueBalance = StrictMathWrapper . subtractExact ( valueBalance , value ) ;
117118 }
118119
119120 public void setTransparentInput (byte [] address , long value ) {
0 commit comments