|
118 | 118 | import org.tron.common.utils.ByteUtil; |
119 | 119 | import org.tron.common.utils.DecodeUtil; |
120 | 120 | import org.tron.common.utils.Sha256Hash; |
121 | | -import org.tron.common.utils.StringUtil; |
122 | 121 | import org.tron.common.utils.Utils; |
123 | 122 | import org.tron.common.utils.WalletUtil; |
124 | 123 | import org.tron.common.zksnark.IncrementalMerkleTreeContainer; |
@@ -262,6 +261,9 @@ public class Wallet { |
262 | 261 | "Shielded transaction API is disabled; " |
263 | 262 | + "set node.allowShieldedTransactionApi=true to enable."; |
264 | 263 | private static final String PAYMENT_ADDRESS_FORMAT_WRONG = "paymentAddress format is wrong"; |
| 264 | + // the authoritative bound is checkBigIntegerRange: uint256 max is 78 decimal digits, |
| 265 | + // this only keeps the string short enough to convert cheaply |
| 266 | + private static final int MAX_SHIELDED_AMOUNT_LENGTH = 80; |
265 | 267 | private static final String SHIELDED_TRANSACTION_SCAN_RANGE = |
266 | 268 | "request requires start_block_index >= 0 && end_block_index > " |
267 | 269 | + "start_block_index && end_block_index - start_block_index <= 1000"; |
@@ -3235,7 +3237,7 @@ public SmartContract getContract(GrpcAPI.BytesMessage bytesMessage) { |
3235 | 3237 | if (accountCapsule == null) { |
3236 | 3238 | logger.warn( |
3237 | 3239 | "Get contract failed, the account {} does not exist or the account " |
3238 | | - + "does not have a code hash!", StringUtil.encode58Check(address)); |
| 3240 | + + "does not have a code hash!", WalletUtil.getAddressString(address)); |
3239 | 3241 | return null; |
3240 | 3242 | } |
3241 | 3243 |
|
@@ -3264,7 +3266,7 @@ public SmartContractDataWrapper getContractInfo(GrpcAPI.BytesMessage bytesMessag |
3264 | 3266 | if (accountCapsule == null) { |
3265 | 3267 | logger.warn( |
3266 | 3268 | "Get contract failed, the account {} does not exist or the account does not have a code " |
3267 | | - + "hash!", StringUtil.encode58Check(address)); |
| 3269 | + + "hash!", WalletUtil.getAddressString(address)); |
3268 | 3270 | return null; |
3269 | 3271 | } |
3270 | 3272 |
|
@@ -4240,6 +4242,9 @@ private BigInteger getBigIntegerFromString(String in) { |
4240 | 4242 | if (trimmedIn.length() == 0) { |
4241 | 4243 | return BigInteger.ZERO; |
4242 | 4244 | } |
| 4245 | + if (trimmedIn.length() > MAX_SHIELDED_AMOUNT_LENGTH) { |
| 4246 | + throw new IllegalArgumentException("invalid shielded amount"); |
| 4247 | + } |
4243 | 4248 | return new BigInteger(trimmedIn, 10); |
4244 | 4249 | } |
4245 | 4250 |
|
@@ -4351,7 +4356,12 @@ public BytesMessage getTriggerInputForShieldedTRC20Contract( |
4351 | 4356 |
|
4352 | 4357 | ShieldedTRC20Parameters shieldedTRC20Parameters = request.getShieldedTRC20Parameters(); |
4353 | 4358 | List<BytesMessage> spendAuthoritySignature = request.getSpendAuthoritySignatureList(); |
4354 | | - BigInteger value = getBigIntegerFromString(request.getAmount()); |
| 4359 | + BigInteger value; |
| 4360 | + try { |
| 4361 | + value = getBigIntegerFromString(request.getAmount()); |
| 4362 | + } catch (IllegalArgumentException e) { |
| 4363 | + throw new ContractValidateException("invalid amount", e); |
| 4364 | + } |
4355 | 4365 | checkBigIntegerRange(value); |
4356 | 4366 | byte[] transparentToAddress = request.getTransparentToAddress().toByteArray(); |
4357 | 4367 | byte[] transparentToAddressTvm = new byte[20]; |
@@ -4416,9 +4426,16 @@ public BytesMessage getTriggerInputForShieldedTRC20Contract( |
4416 | 4426 | } |
4417 | 4427 | parametersBuilder.setBurnCiphertext(burnCiper); |
4418 | 4428 | } |
4419 | | - String input = parametersBuilder |
4420 | | - .getTriggerContractInput(shieldedTRC20Parameters, spendAuthoritySignature, value, false, |
4421 | | - transparentToAddressTvm); |
| 4429 | + String input; |
| 4430 | + try { |
| 4431 | + input = parametersBuilder |
| 4432 | + .getTriggerContractInput(shieldedTRC20Parameters, spendAuthoritySignature, value, false, |
| 4433 | + transparentToAddressTvm); |
| 4434 | + } catch (IllegalArgumentException e) { |
| 4435 | + // the builder names the offending argument in fixed strings; none of them echoes an input |
| 4436 | + throw new ContractValidateException( |
| 4437 | + "invalid shielded TRC-20 trigger input: " + e.getMessage(), e); |
| 4438 | + } |
4422 | 4439 | if (Objects.isNull(input)) { |
4423 | 4440 | throw new ZksnarkException("generate the trigger contract parameters error"); |
4424 | 4441 | } |
|
0 commit comments