Skip to content

Commit af91eb4

Browse files
authored
Merge pull request #3250 from tronprotocol/fix/release_4.0_sonar_check
fix sonar check in release_vm_4.0_shielded
2 parents a759c87 + d6edc6b commit af91eb4

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ protected int parseInt(byte[] data, int idx) {
932932

933933
private int getFrontierSlot(long leafIndex) {
934934
int slot = 0;
935-
if (leafIndex % 2 == 1) {
935+
if (leafIndex % 2 != 0) {
936936
int exp1 = 1;
937937
long pow1 = 2;
938938
long pow2 = pow1 << 1;
@@ -1240,7 +1240,8 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
12401240
signHash, spendCvs, spendCount * 32, receiveCvs, receiveCount * 32));
12411241
futures.add(futureCheckBindingSig);
12421242

1243-
countDownLatch.await(getCPUTimeLeftInNanoSecond(), TimeUnit.NANOSECONDS);
1243+
boolean withNoTimeout = countDownLatch.await(getCPUTimeLeftInNanoSecond(),
1244+
TimeUnit.NANOSECONDS);
12441245
boolean checkResult = true;
12451246
for (Future<Boolean> future : futures) {
12461247
boolean eachTaskResult = future.get();
@@ -1341,9 +1342,9 @@ public Boolean call() throws ZksnarkException {
13411342

13421343
private static class SaplingCheckBingdingSig implements Callable<Boolean> {
13431344

1344-
long valueBalance;
1345-
int spendCvLen;
1346-
int receiveCvLen;
1345+
private long valueBalance;
1346+
private int spendCvLen;
1347+
private int receiveCvLen;
13471348
private byte[] bindingSig;
13481349
private byte[] signHash;
13491350
private byte[] spendCvs;

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ public class Wallet {
214214

215215
private static final String SHIELDED_ID_NOT_ALLOWED = "ShieldedTransactionApi is not allowed";
216216
private static final String PAYMENT_ADDRESS_FORMAT_WRONG = "paymentAddress format is wrong";
217+
private static final String SHIELDED_TRANSACTION_SCAN_RANGE =
218+
"request requires start_block_index >= 0 && end_block_index > "
219+
+ "start_block_index && end_block_index - start_block_index <= 1000";
217220
private static String addressPreFixString = Constant.ADD_PRE_FIX_STRING_MAINNET;//default testnet
218221
private static final byte[] SHIELDED_TRC20_LOG_TOPICS_MINT = Hash.sha3(ByteArray.fromString(
219222
"MintNewLeaf(uint256,bytes32,bytes32,bytes32,bytes32[21])"));
@@ -2555,8 +2558,7 @@ private GrpcAPI.DecryptNotes queryNoteByIvk(long startNum, long endNum, byte[] i
25552558
GrpcAPI.DecryptNotes.Builder builder = GrpcAPI.DecryptNotes.newBuilder();
25562559
if (!(startNum >= 0 && endNum > startNum && endNum - startNum <= 1000)) {
25572560
throw new BadItemException(
2558-
"request requires start_block_index >= 0 && end_block_index > start_block_index "
2559-
+ "&& end_block_index - start_block_index <= 1000");
2561+
SHIELDED_TRANSACTION_SCAN_RANGE);
25602562
}
25612563
BlockList blockList = this.getBlocksByLimitNext(startNum, endNum - startNum);
25622564
for (Block block : blockList.getBlockList()) {
@@ -2669,8 +2671,7 @@ public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum,
26692671
GrpcAPI.DecryptNotes.Builder builder = GrpcAPI.DecryptNotes.newBuilder();
26702672
if (!(startNum >= 0 && endNum > startNum && endNum - startNum <= 1000)) {
26712673
throw new BadItemException(
2672-
"request require start_block_index >= 0 && end_block_index > start_block_index "
2673-
+ "&& end_block_index - start_block_index <= 1000");
2674+
SHIELDED_TRANSACTION_SCAN_RANGE);
26742675
}
26752676
BlockList blockList = this.getBlocksByLimitNext(startNum, endNum - startNum);
26762677
for (Block block : blockList.getBlockList()) {
@@ -2914,7 +2915,7 @@ public ShieldedTRC20Parameters createShieldedContractParameters(
29142915

29152916
private void buildShieldedTRC20InputWithAK(
29162917
ShieldedTRC20ParametersBuilder builder, GrpcAPI.SpendNoteTRC20 spendNote,
2917-
byte[] ak, byte[] nsk, byte[] ovk) throws ZksnarkException {
2918+
byte[] ak, byte[] nsk) throws ZksnarkException {
29182919
GrpcAPI.Note note = spendNote.getNote();
29192920
PaymentAddress paymentAddress = KeyIo.decodePaymentAddress(note.getPaymentAddress());
29202921
if (Objects.isNull(paymentAddress)) {
@@ -2925,7 +2926,6 @@ private void buildShieldedTRC20InputWithAK(
29252926
paymentAddress.getPkD(), note.getValue(), note.getRcm().toByteArray());
29262927
builder.addSpend(ak,
29272928
nsk,
2928-
ovk,
29292929
baseNote,
29302930
spendNote.getAlpha().toByteArray(),
29312931
spendNote.getRoot().toByteArray(),
@@ -2997,7 +2997,7 @@ public ShieldedTRC20Parameters createShieldedContractParametersWithoutAsk(
29972997
throw new ContractValidateException("No shielded TRC-20 ak, nsk or ovk");
29982998
}
29992999
for (GrpcAPI.SpendNoteTRC20 spendNote : shieldedSpends) {
3000-
buildShieldedTRC20InputWithAK(builder, spendNote, ak, nsk, ovk);
3000+
buildShieldedTRC20InputWithAK(builder, spendNote, ak, nsk);
30013001
}
30023002
for (ReceiveNote receiveNote : shieldedReceives) {
30033003
buildShieldedTRC20Output(builder, receiveNote, ovk);
@@ -3023,7 +3023,7 @@ public ShieldedTRC20Parameters createShieldedContractParametersWithoutAsk(
30233023
.encryptBurnMessageByOvk(ovk, toAmount, transparentToAddress);
30243024
cipher.ifPresent(builder::setBurnCiphertext);
30253025
GrpcAPI.SpendNoteTRC20 spendNote = shieldedSpends.get(0);
3026-
buildShieldedTRC20InputWithAK(builder, spendNote, ak, nsk, ovk);
3026+
buildShieldedTRC20InputWithAK(builder, spendNote, ak, nsk);
30273027
if (receiveSize == 1) {
30283028
buildShieldedTRC20Output(builder, shieldedReceives.get(0), ovk);
30293029
}
@@ -3128,8 +3128,7 @@ private DecryptNotesTRC20 queryTRC20NoteByIvk(long startNum, long endNum,
31283128
throws BadItemException, ZksnarkException, ContractExeException {
31293129
if (!(startNum >= 0 && endNum > startNum && endNum - startNum <= 1000)) {
31303130
throw new BadItemException(
3131-
"request requires start_block_index >= 0 && end_block_index > start_block_index "
3132-
+ "&& end_block_index - start_block_index <= 1000");
3131+
SHIELDED_TRANSACTION_SCAN_RANGE);
31333132
}
31343133

31353134
DecryptNotesTRC20.Builder builder = DecryptNotesTRC20.newBuilder();
@@ -3215,7 +3214,7 @@ private boolean isShieldedTRC20NoteSpent(GrpcAPI.Note note, long pos, byte[] ak,
32153214
}
32163215

32173216
String code = trxExt.getResult().getCode().toString();
3218-
if (code.equals("SUCCESS")) {
3217+
if ("SUCCESS".equals(code)) {
32193218
List<ByteString> list = trxExt.getConstantResultList();
32203219
byte[] listBytes = new byte[0];
32213220
for (ByteString bs : list) {
@@ -3316,8 +3315,7 @@ public DecryptNotesTRC20 scanShieldedTRC20NotesByOvk(long startNum, long endNum,
33163315
DecryptNotesTRC20.Builder builder = DecryptNotesTRC20.newBuilder();
33173316
if (!(startNum >= 0 && endNum > startNum && endNum - startNum <= 1000)) {
33183317
throw new BadItemException(
3319-
"request requires start_block_index >= 0 && end_block_index > start_block_index "
3320-
+ "&& end_block_index - start_block_index <= 1000");
3318+
SHIELDED_TRANSACTION_SCAN_RANGE);
33213319
}
33223320
BlockList blockList = this.getBlocksByLimitNext(startNum, endNum - startNum);
33233321
for (Block block : blockList.getBlockList()) {
@@ -3480,7 +3478,7 @@ private byte[] getShieldedContractScalingFactor(byte[] contractAddress)
34803478
}
34813479

34823480
String code = trxExt.getResult().getCode().toString();
3483-
if (code.equals("SUCCESS")) {
3481+
if ("SUCCESS".equals(code)) {
34843482
List<ByteString> list = trxExt.getConstantResultList();
34853483
byte[] listBytes = new byte[0];
34863484
for (ByteString bs : list) {

framework/src/main/java/org/tron/core/services/RpcApiService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
import org.tron.core.config.args.Args;
103103
import org.tron.core.db.Manager;
104104
import org.tron.core.exception.BadItemException;
105-
import org.tron.core.exception.ContractExeException;
106105
import org.tron.core.exception.ContractValidateException;
107106
import org.tron.core.exception.ItemNotFoundException;
108107
import org.tron.core.exception.NonUniqueObjectException;
@@ -2003,7 +2002,7 @@ public void createShieldedTransaction(PrivateParameters request,
20032002
} catch (Exception e) {
20042003
retBuilder.setResult(false).setCode(response_code.OTHER_ERROR)
20052004
.setMessage(ByteString.copyFromUtf8(e.getClass() + " : " + e.getMessage()));
2006-
logger.info("exception caught: " + e.getMessage());
2005+
logger.info("createShieldedTransaction exception caught: " + e.getMessage());
20072006
}
20082007

20092008
trxExtBuilder.setResult(retBuilder);
@@ -2033,7 +2032,8 @@ public void createShieldedTransactionWithoutSpendAuthSig(PrivateParametersWithou
20332032
} catch (Exception e) {
20342033
retBuilder.setResult(false).setCode(response_code.OTHER_ERROR)
20352034
.setMessage(ByteString.copyFromUtf8(e.getClass() + " : " + e.getMessage()));
2036-
logger.info("exception caught: " + e.getMessage());
2035+
logger.info(
2036+
"createShieldedTransactionWithoutSpendAuthSig exception caught: " + e.getMessage());
20372037
}
20382038

20392039
trxExtBuilder.setResult(retBuilder);
@@ -2323,7 +2323,7 @@ public void createShieldedContractParameters(
23232323
responseObserver.onNext(shieldedTRC20Parameters);
23242324
} catch (Exception e) {
23252325
responseObserver.onError(getRunTimeException(e));
2326-
logger.info("exception caught: " + e.getMessage());
2326+
logger.info("createShieldedContractParameters exception caught: " + e.getMessage());
23272327
return;
23282328
}
23292329
responseObserver.onCompleted();
@@ -2341,7 +2341,8 @@ public void createShieldedContractParametersWithoutAsk(
23412341
responseObserver.onNext(shieldedTRC20Parameters);
23422342
} catch (Exception e) {
23432343
responseObserver.onError(getRunTimeException(e));
2344-
logger.info("exception caught: " + e.getMessage());
2344+
logger
2345+
.info("createShieldedContractParametersWithoutAsk exception caught: " + e.getMessage());
23452346
return;
23462347
}
23472348
responseObserver.onCompleted();
@@ -2365,7 +2366,7 @@ public void scanShieldedTRC20NotesByIvk(
23652366
responseObserver.onNext(decryptNotes);
23662367
} catch (Exception e) {
23672368
responseObserver.onError(getRunTimeException(e));
2368-
logger.info("exception caught: " + e.getMessage());
2369+
logger.info("scanShieldedTRC20NotesByIvk exception caught: " + e.getMessage());
23692370
return;
23702371
}
23712372
responseObserver.onCompleted();
@@ -2387,7 +2388,7 @@ public void scanShieldedTRC20NotesByOvk(
23872388
responseObserver.onNext(decryptNotes);
23882389
} catch (Exception e) {
23892390
responseObserver.onError(getRunTimeException(e));
2390-
logger.info("exception caught: " + e.getMessage());
2391+
logger.info("scanShieldedTRC20NotesByOvk exception caught: " + e.getMessage());
23912392
return;
23922393
}
23932394
responseObserver.onCompleted();
@@ -2416,8 +2417,7 @@ public void getTriggerInputForShieldedTRC20Contract(
24162417
try {
24172418
checkSupportShieldedTRC20Transaction();
24182419

2419-
BytesMessage bytesMessage = wallet.getTriggerInputForShieldedTRC20Contract(request);
2420-
responseObserver.onNext(bytesMessage);
2420+
responseObserver.onNext(wallet.getTriggerInputForShieldedTRC20Contract(request));
24212421
} catch (Exception e) {
24222422
responseObserver.onError(e);
24232423
return;

framework/src/main/java/org/tron/core/zen/ShieldedTRC20ParametersBuilder.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class ShieldedTRC20ParametersBuilder {
6060
@Setter
6161
private BigInteger transparentToAmount;
6262
@Setter
63-
byte[] burnCiphertext = new byte[80];
63+
private byte[] burnCiphertext = new byte[80];
6464

6565
public ShieldedTRC20ParametersBuilder() {
6666

@@ -565,13 +565,12 @@ public void addSpend(
565565
public void addSpend(
566566
byte[] ak,
567567
byte[] nsk,
568-
byte[] ovk,
569568
Note note,
570569
byte[] alpha,
571570
byte[] anchor,
572571
byte[] path,
573572
long position) {
574-
spends.add(new SpendDescriptionInfo(ak, nsk, ovk, note, alpha, anchor, path, position));
573+
spends.add(new SpendDescriptionInfo(ak, nsk, note, alpha, anchor, path, position));
575574
valueBalance += note.getValue();
576575
}
577576

@@ -600,7 +599,6 @@ public static class SpendDescriptionInfo {
600599
private long position;
601600
private byte[] ak;
602601
private byte[] nsk;
603-
private byte[] ovk;
604602

605603
private SpendDescriptionInfo(
606604
ExpandedSpendingKey expsk,
@@ -635,7 +633,6 @@ private SpendDescriptionInfo(
635633
private SpendDescriptionInfo(
636634
byte[] ak,
637635
byte[] nsk,
638-
byte[] ovk,
639636
Note note,
640637
byte[] alpha,
641638
byte[] anchor,
@@ -648,7 +645,6 @@ private SpendDescriptionInfo(
648645
this.path = path;
649646
this.position = position;
650647
this.alpha = alpha;
651-
this.ovk = ovk;
652648
}
653649
}
654650

tron.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if [ $encrypted_43b7d2f1321f_key ];then
55
cat tron > ~/.ssh/id_rsa
66
chmod 600 ~/.ssh/id_rsa
77
echo "Add docker server success"
8-
sonar-scanner
8+
99
fi
1010

1111
cp -f config/checkstyle/checkStyle.xml config/checkstyle/checkStyleAll.xml

0 commit comments

Comments
 (0)