Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is rollback to 4.7.3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this part of the direct rollback ? I see the previous analysis which is also wrong

Copy link
Contributor Author

@317787106 317787106 Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only this part is new added:

if (scalingFactor.compareTo(BigInteger.ZERO) <= 0) {
      throw new ContractValidateException("scalingFactor must be positive");
}

Other part is still same as before. Check the condition outside this method is not only easy to understand and but also include all conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halibobo1205 what's wrong with previous analysis? This optimization is to coverage this additional case: contract and method scalingFactor are both exist, but it really return 0.


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