|
|
@ -36,52 +36,61 @@ public class PrivateTransactionValidator { |
|
|
|
public ValidationResult<TransactionValidator.TransactionInvalidReason> validate( |
|
|
|
public ValidationResult<TransactionValidator.TransactionInvalidReason> validate( |
|
|
|
final PrivateTransaction transaction, final Long accountNonce) { |
|
|
|
final PrivateTransaction transaction, final Long accountNonce) { |
|
|
|
|
|
|
|
|
|
|
|
LOG.debug("Validating private transaction {} signature ", transaction.hash()); |
|
|
|
LOG.debug("Validating the signature of Private Transaction {} ", transaction.hash()); |
|
|
|
|
|
|
|
|
|
|
|
final ValidationResult<TransactionValidator.TransactionInvalidReason> |
|
|
|
final ValidationResult<TransactionValidator.TransactionInvalidReason> |
|
|
|
signatureValidationResult = validateTransactionSignature(transaction); |
|
|
|
signatureValidationResult = validateTransactionSignature(transaction); |
|
|
|
if (!signatureValidationResult.isValid()) { |
|
|
|
if (!signatureValidationResult.isValid()) { |
|
|
|
|
|
|
|
LOG.debug( |
|
|
|
|
|
|
|
"Private Transaction {}, failed validation {}, {}", |
|
|
|
|
|
|
|
transaction.hash(), |
|
|
|
|
|
|
|
signatureValidationResult.getInvalidReason(), |
|
|
|
|
|
|
|
signatureValidationResult.getErrorMessage()); |
|
|
|
return signatureValidationResult; |
|
|
|
return signatureValidationResult; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final long transactionNonce = transaction.getNonce(); |
|
|
|
final long transactionNonce = transaction.getNonce(); |
|
|
|
|
|
|
|
|
|
|
|
LOG.debug("Validating actual nonce {} with expected nonce {}", transactionNonce, accountNonce); |
|
|
|
LOG.debug("Validating actual nonce {}, with expected nonce {}", transactionNonce, accountNonce); |
|
|
|
|
|
|
|
|
|
|
|
if (accountNonce > transactionNonce) { |
|
|
|
if (accountNonce > transactionNonce) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
final String errorMessage = |
|
|
|
TransactionValidator.TransactionInvalidReason.PRIVATE_NONCE_TOO_LOW, |
|
|
|
|
|
|
|
String.format( |
|
|
|
String.format( |
|
|
|
"private transaction nonce %s does not match sender account nonce %s.", |
|
|
|
"Private Transaction nonce %s, is lower than sender account nonce %s.", |
|
|
|
transactionNonce, accountNonce)); |
|
|
|
transactionNonce, accountNonce); |
|
|
|
|
|
|
|
LOG.debug(errorMessage); |
|
|
|
|
|
|
|
return ValidationResult.invalid( |
|
|
|
|
|
|
|
TransactionValidator.TransactionInvalidReason.PRIVATE_NONCE_TOO_LOW, errorMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (accountNonce != transactionNonce) { |
|
|
|
if (accountNonce != transactionNonce) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
final String errorMessage = |
|
|
|
TransactionValidator.TransactionInvalidReason.INCORRECT_PRIVATE_NONCE, |
|
|
|
|
|
|
|
String.format( |
|
|
|
String.format( |
|
|
|
"private transaction nonce %s does not match sender account nonce %s.", |
|
|
|
"Private Transaction nonce %s, does not match sender account nonce %s.", |
|
|
|
transactionNonce, accountNonce)); |
|
|
|
transactionNonce, accountNonce); |
|
|
|
|
|
|
|
LOG.debug(errorMessage); |
|
|
|
|
|
|
|
return ValidationResult.invalid( |
|
|
|
|
|
|
|
TransactionValidator.TransactionInvalidReason.INCORRECT_PRIVATE_NONCE, errorMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ValidationResult.valid(); |
|
|
|
return ValidationResult.valid(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ValidationResult<TransactionValidator.TransactionInvalidReason> |
|
|
|
private ValidationResult<TransactionValidator.TransactionInvalidReason> |
|
|
|
validateTransactionSignature(final PrivateTransaction transaction) { |
|
|
|
validateTransactionSignature(final PrivateTransaction transaction) { |
|
|
|
if (chainId.isPresent() |
|
|
|
if (chainId.isPresent() |
|
|
|
&& (transaction.getChainId().isPresent() && !transaction.getChainId().equals(chainId))) { |
|
|
|
&& (transaction.getChainId().isPresent() && !transaction.getChainId().equals(chainId))) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
return ValidationResult.invalid( |
|
|
|
TransactionValidator.TransactionInvalidReason.WRONG_CHAIN_ID, |
|
|
|
TransactionValidator.TransactionInvalidReason.WRONG_CHAIN_ID, |
|
|
|
String.format( |
|
|
|
String.format( |
|
|
|
"transaction was meant for chain id %s and not this chain id %s", |
|
|
|
"Transaction was meant for chain id %s, not this chain id %s", |
|
|
|
transaction.getChainId().get(), chainId.get())); |
|
|
|
transaction.getChainId().get(), chainId.get())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!chainId.isPresent() && transaction.getChainId().isPresent()) { |
|
|
|
if (!chainId.isPresent() && transaction.getChainId().isPresent()) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
return ValidationResult.invalid( |
|
|
|
TransactionValidator.TransactionInvalidReason.REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED, |
|
|
|
TransactionValidator.TransactionInvalidReason.REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED, |
|
|
|
"replay protected signatures is not supported"); |
|
|
|
"Replay protection (chainId) is not supported"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// org.bouncycastle.math.ec.ECCurve.AbstractFp.decompressPoint throws an
|
|
|
|
// org.bouncycastle.math.ec.ECCurve.AbstractFp.decompressPoint throws an
|
|
|
@ -91,7 +100,7 @@ public class PrivateTransactionValidator { |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
return ValidationResult.invalid( |
|
|
|
return ValidationResult.invalid( |
|
|
|
TransactionValidator.TransactionInvalidReason.INVALID_SIGNATURE, |
|
|
|
TransactionValidator.TransactionInvalidReason.INVALID_SIGNATURE, |
|
|
|
"sender could not be extracted from transaction signature"); |
|
|
|
"Sender could not be extracted from transaction signature"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ValidationResult.valid(); |
|
|
|
return ValidationResult.valid(); |
|
|
|