Skip to content

Commit

Permalink
hotfix(net):throw exception if scalingFactor <=0 (#5746)
Browse files Browse the repository at this point in the history
  • Loading branch information
317787106 authored Mar 6, 2024
1 parent fa46c4f commit 074e0d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,6 @@ public Transaction getInstance() {
@Override
public String toString() {
StringBuilder toStringBuff = new StringBuilder();
toStringBuff.setLength(0);
toStringBuff.append("TransactionCapsule \n[ ");

toStringBuff.append("hash=").append(getTransactionId()).append("\n");
Expand Down
17 changes: 9 additions & 8 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3862,12 +3862,11 @@ private boolean isShieldedTRC20NoteSpent(GrpcAPI.Note note, long pos, byte[] ak,
TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder();
Return.Builder retBuilder = Return.newBuilder();
TransactionExtention trxExt;
Transaction trx;

try {
TransactionCapsule trxCap = createTransactionCapsule(trigger,
ContractType.TriggerSmartContract);
trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);
Transaction trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);

retBuilder.setResult(true).setCode(response_code.SUCCESS);
trxExtBuilder.setTransaction(trx);
Expand All @@ -3890,10 +3889,10 @@ private boolean isShieldedTRC20NoteSpent(GrpcAPI.Note note, long pos, byte[] ak,
logger.warn("unknown exception caught: " + e.getMessage(), e);
} finally {
trxExt = trxExtBuilder.build();
trx = trxExt.getTransaction();
}

if (code.SUCESS == trx.getRet(0).getRet()) {
String code = trxExt.getResult().getCode().toString();
if ("SUCCESS".equals(code)) {
List<ByteString> list = trxExt.getConstantResultList();
byte[] listBytes = new byte[0];
for (ByteString bs : list) {
Expand Down Expand Up @@ -4086,6 +4085,9 @@ private long[] checkPublicAmount(byte[] address, BigInteger fromAmount, BigInteg
} catch (ContractExeException e) {
throw new ContractExeException("Get shielded contract scalingFactor failed");
}
if (scalingFactor.compareTo(BigInteger.ZERO) <= 0) {
throw new ContractValidateException("scalingFactor must be positive");
}

// fromAmount and toAmount must be a multiple of scalingFactor
if (!(fromAmount.mod(scalingFactor).equals(BigInteger.ZERO)
Expand Down Expand Up @@ -4127,12 +4129,11 @@ public byte[] getShieldedContractScalingFactor(byte[] contractAddress)
TransactionExtention.Builder trxExtBuilder = TransactionExtention.newBuilder();
Return.Builder retBuilder = Return.newBuilder();
TransactionExtention trxExt;
Transaction trx;

try {
TransactionCapsule trxCap = createTransactionCapsule(trigger,
ContractType.TriggerSmartContract);
trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);
Transaction trx = triggerConstantContract(trigger, trxCap, trxExtBuilder, retBuilder);

retBuilder.setResult(true).setCode(response_code.SUCCESS);
trxExtBuilder.setTransaction(trx);
Expand All @@ -4155,10 +4156,10 @@ public byte[] getShieldedContractScalingFactor(byte[] contractAddress)
logger.warn("Unknown exception caught: " + e.getMessage(), e);
} finally {
trxExt = trxExtBuilder.build();
trx = trxExt.getTransaction();
}

if (code.SUCESS == trx.getRet(0).getRet()) {
String code = trxExt.getResult().getCode().toString();
if ("SUCCESS".equals(code)) {
List<ByteString> list = trxExt.getConstantResultList();
byte[] listBytes = new byte[0];
for (ByteString bs : list) {
Expand Down

0 comments on commit 074e0d6

Please sign in to comment.