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 @@ -410,8 +410,7 @@ private void create()

long thisTxCPULimitInUs = calculateCpuLimitInUs(isConstantCall,
rootRepository.getDynamicPropertiesStore().getMaxCpuTimeOfOneTx(),
getCpuLimitInUsRatio(),
CommonParameter.getInstance().getConstantCallTimeoutMs());
getCpuLimitInUsRatio(), CommonParameter.getInstance().getConstantCallTimeoutMs());
long vmStartInUs = System.nanoTime() / VMConstant.ONE_THOUSAND;
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;
ProgramInvoke programInvoke = ProgramInvokeFactory
Expand Down
6 changes: 2 additions & 4 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
case ALLOW_FN_DSA_512: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_FN_DSA_512]");
throw new ContractValidateException("Bad chain parameter id [ALLOW_FN_DSA_512]");
}
if (value != 0 && value != 1) {
throw new ContractValidateException(
Expand All @@ -959,8 +958,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
case ALLOW_ML_DSA_44: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_ML_DSA_44]");
throw new ContractValidateException("Bad chain parameter id [ALLOW_ML_DSA_44]");
}
if (value != 0 && value != 1) {
throw new ContractValidateException(
Expand Down
21 changes: 11 additions & 10 deletions actuator/src/main/java/org/tron/core/utils/TransactionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import static org.tron.common.crypto.Hash.sha3omit12;
import static org.tron.common.math.Maths.max;
import static org.tron.core.config.Parameter.ChainConstant.DELEGATE_COST_BASE_SIZE;
import static org.tron.core.Constant.PER_SIGN_LENGTH;
import static org.tron.core.config.Parameter.ChainConstant.DELEGATE_COST_BASE_SIZE;
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;

import com.google.common.base.CaseFormat;
Expand Down Expand Up @@ -52,9 +52,9 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract;
import org.tron.protos.Protocol.Transaction.Result.contractResult;
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;
import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;

@Slf4j(topic = "capsule")
@Component
Expand Down Expand Up @@ -84,7 +84,8 @@ public static boolean validUrl(byte[] url) {
}

public static boolean validAccountId(byte[] accountId) {
return validReadableBytes(accountId, MAX_ACCOUNT_ID_LEN) && accountId.length >= MIN_ACCOUNT_ID_LEN;
return validReadableBytes(accountId, MAX_ACCOUNT_ID_LEN)
&& accountId.length >= MIN_ACCOUNT_ID_LEN;
}

public static boolean validAssetName(byte[] assetName) {
Expand Down Expand Up @@ -246,7 +247,7 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
tswBuilder.setPermission(permission);
long currentWeight = 0L;
List<ByteString> approveList = new ArrayList<>();
if (trx.getSignatureCount() > 0 ) {
if (trx.getSignatureCount() > 0) {
currentWeight = TransactionCapsule.checkWeight(permission, trx.getSignatureList(),
Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), trx.getRawData().toByteArray()), approveList);
Expand All @@ -257,7 +258,7 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
long pqWeight = TransactionCapsule.validatePQSignatureGetWeight(trx, permission,
chainBaseManager.getDynamicPropertiesStore(), approveList);
// sum all signature weight
currentWeight = StrictMathWrapper.addExact(currentWeight,pqWeight);
currentWeight = StrictMathWrapper.addExact(currentWeight, pqWeight);
} catch (ArithmeticException e) {
throw new PermissionException("weight overflow");
}
Expand Down Expand Up @@ -297,13 +298,13 @@ public static long estimateConsumeBandWidthSize(DynamicPropertiesStore dps, long
DelegateResourceContract.Builder builder;
if (dps.supportMaxDelegateLockPeriod()) {
builder = DelegateResourceContract.newBuilder()
.setLock(true)
.setLockPeriod(dps.getMaxDelegateLockPeriod())
.setBalance(balance);
.setLock(true)
.setLockPeriod(dps.getMaxDelegateLockPeriod())
.setBalance(balance);
} else {
builder = DelegateResourceContract.newBuilder()
.setLock(true)
.setBalance(balance);
.setLock(true)
.setBalance(balance);
}
long builderSize = builder.build().getSerializedSize();
DelegateResourceContract.Builder builder2 = DelegateResourceContract.newBuilder()
Expand Down
42 changes: 17 additions & 25 deletions actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ public class PrecompiledContracts {

// FreezeV2 PrecompileContracts
private static final GetChainParameter getChainParameter = new GetChainParameter();
private static final AvailableUnfreezeV2Size availableUnfreezeV2Size = new AvailableUnfreezeV2Size();
private static final AvailableUnfreezeV2Size availableUnfreezeV2Size =
new AvailableUnfreezeV2Size();
private static final UnfreezableBalanceV2 unfreezableBalanceV2 = new UnfreezableBalanceV2();
private static final ExpireUnfreezeBalanceV2 expireUnfreezeBalanceV2 = new ExpireUnfreezeBalanceV2();
private static final ExpireUnfreezeBalanceV2 expireUnfreezeBalanceV2 =
new ExpireUnfreezeBalanceV2();
private static final DelegatableResource delegatableResource = new DelegatableResource();
private static final ResourceV2 resourceV2 = new ResourceV2();
private static final CheckUnDelegateResource checkUnDelegateResource = new CheckUnDelegateResource();
private static final CheckUnDelegateResource checkUnDelegateResource =
new CheckUnDelegateResource();
private static final ResourceUsage resourceUsage = new ResourceUsage();
private static final TotalResource totalResource = new TotalResource();
private static final TotalDelegatedResource totalDelegatedResource = new TotalDelegatedResource();
Expand Down Expand Up @@ -558,11 +561,9 @@ private static boolean isValidAbiHead(byte[] data, int headWords) {
* a length word that still fits inside {@code words}. Sister check to
* {@link #isValidAbiEncoding} for ABIs whose items are not uniform width.
*/
private static boolean isValidArrayOffset(DataWord[] words, int offsetWordIndex,
int headWords) {
private static boolean isValidArrayOffset(DataWord[] words, int offsetWordIndex, int headWords) {
long offsetBytes = words[offsetWordIndex].longValueSafe();
if (offsetBytes < (long) headWords * WORD_SIZE
|| offsetBytes % WORD_SIZE != 0) {
if (offsetBytes < (long) headWords * WORD_SIZE || offsetBytes % WORD_SIZE != 0) {
return false;
}
long lengthWordIdx = offsetBytes / WORD_SIZE;
Expand Down Expand Up @@ -846,7 +847,6 @@ public long getEnergyForData(byte[] data) {
int expLen = parseLen(data, 1);
int modLen = parseLen(data, 2);


byte[] expHighBytes = parseBytes(data, addSafely(ARGS_OFFSET, baseLen), min(expLen, 32,
VMConfig.disableJavaLangMath()));

Expand Down Expand Up @@ -948,8 +948,7 @@ private long getAdjustedExponentLength(byte[] expHighBytes, long expLen) {
* TIP-7883: ModExp gas cost increase.
* New pricing formula with higher minimum cost and no divisor.
*/
private long getEnergyTIP7883(int baseLen, int modLen,
byte[] expHighBytes, int expLen) {
private long getEnergyTIP7883(int baseLen, int modLen, byte[] expHighBytes, int expLen) {
long multComplexity = getMultComplexityTIP7883(baseLen, modLen);
long iterCount = getIterationCountTIP7883(expHighBytes, expLen);

Expand Down Expand Up @@ -1329,7 +1328,7 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
try {
return doExecute(data);
} catch (Throwable t) {
if (t instanceof InterruptedException){
if (t instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return Pair.of(true, new byte[WORD_SIZE]);
Expand Down Expand Up @@ -1424,8 +1423,6 @@ private static class RecoverAddrResult {
private byte[] addr;
private int nonce;
}


}

public abstract static class VerifyProof extends PrecompiledContract {
Expand Down Expand Up @@ -2634,6 +2631,7 @@ public Pair<Boolean, byte[]> execute(byte[] data) {

/**
* 0x17 BatchValidateFnDsa512 — independent per-element Falcon-512 verify.
*
* <p>Returns a 256-bit bitmap (matching 0x09) where bit {@code i} is set iff
* {@code derive(pk_i) == expectedAddr_i} AND {@code FNDSA512.verify(pk_i, hash, sig_i)}.
*
Expand Down Expand Up @@ -2766,10 +2764,8 @@ private Pair<Boolean, byte[]> doExecute(byte[] data)
return Pair.of(true, res);
}

private static boolean verifyOne(byte[] sig, byte[] pk, byte[] hash,
byte[] expectedAddr) {
if (pk == null || pk.length != PK_LEN
|| sig == null || sig.length != SIG_SLOT_LEN) {
private static boolean verifyOne(byte[] sig, byte[] pk, byte[] hash, byte[] expectedAddr) {
if (pk == null || pk.length != PK_LEN || sig == null || sig.length != SIG_SLOT_LEN) {
return false;
}
// The slot is the EIP-8052 headerless body; rebuild the BC-headered sig.
Expand Down Expand Up @@ -2801,8 +2797,7 @@ private static class PqVerifyTask implements Callable<PqVerifyResult> {
@Override
public PqVerifyResult call() {
try {
return new PqVerifyResult(
verifyOne(signature, publicKey, hash, expectedAddr), nonce);
return new PqVerifyResult(verifyOne(signature, publicKey, hash, expectedAddr), nonce);
} finally {
countDownLatch.countDown();
}
Expand Down Expand Up @@ -3199,10 +3194,8 @@ private Pair<Boolean, byte[]> doExecute(byte[] data)
return Pair.of(true, res);
}

private static boolean verifyOne(byte[] sig, byte[] pk, byte[] hash,
byte[] expectedAddr) {
if (pk == null || pk.length != PK_LEN
|| sig == null || sig.length != SIG_LEN) {
private static boolean verifyOne(byte[] sig, byte[] pk, byte[] hash, byte[] expectedAddr) {
if (pk == null || pk.length != PK_LEN || sig == null || sig.length != SIG_LEN) {
return false;
}
try {
Expand All @@ -3229,8 +3222,7 @@ private static class PqVerifyTask implements Callable<PqVerifyResult> {
@Override
public PqVerifyResult call() {
try {
return new PqVerifyResult(
verifyOne(signature, publicKey, hash, expectedAddr), nonce);
return new PqVerifyResult(verifyOne(signature, publicKey, hash, expectedAddr), nonce);
} finally {
countDownLatch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public void initPqWitnessAccountAddress(final byte[] explicit) {
if (!CollectionUtils.isEmpty(pqKeypairs)) {
PqKeypair first = pqKeypairs.get(0);
byte[] pubKey = ByteArray.fromHexString(first.getPublicKey());
this.pqWitnessAccountAddress = PQSchemeRegistry.computeAddress(
first.getScheme(), pubKey);
this.pqWitnessAccountAddress = PQSchemeRegistry.computeAddress(first.getScheme(), pubKey);
}
}

Expand Down Expand Up @@ -197,8 +196,7 @@ private static void validatePqKey(String key, int expectedLen, String label) {
TronError.ErrCode.WITNESS_INIT);
}
if (!StringUtil.isHexadecimal(hex)) {
throw new TronError(label + " must be hex string",
TronError.ErrCode.WITNESS_INIT);
throw new TronError(label + " must be hex string", TronError.ErrCode.WITNESS_INIT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ private Sha256Hash getRawHash() {
public boolean validateSignature(DynamicPropertiesStore dynamicPropertiesStore,
AccountStore accountStore) throws ValidateSignatureException {
BlockHeader header = block.getBlockHeader();
byte[] witnessAccountAddress = header.getRawData().getWitnessAddress()
.toByteArray();
byte[] witnessAccountAddress = header.getRawData().getWitnessAddress().toByteArray();

byte[] witnessPermissionAddress;
if (dynamicPropertiesStore.getAllowMultiSign() != 1) {
Expand Down Expand Up @@ -265,12 +264,10 @@ private boolean validatePQSignature(DynamicPropertiesStore dynamicPropertiesStor
*/
PQScheme scheme = pqAuthSig.getScheme();
if (!PQSchemeRegistry.contains(scheme)) {
throw new ValidateSignatureException(
"pq_auth_sig scheme " + scheme + " is not registered");
throw new ValidateSignatureException("pq_auth_sig scheme " + scheme + " is not registered");
}
if (!dynamicPropertiesStore.isPqSchemeAllowed(scheme)) {
throw new ValidateSignatureException(
"pq_auth_sig scheme " + scheme + " is not activated");
throw new ValidateSignatureException("pq_auth_sig scheme " + scheme + " is not activated");
}

byte[] publicKey = pqAuthSig.getPublicKey().toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,7 @@ public boolean validatePubSignature(AccountStore accountStore,
"pq_auth_sig not allowed: no post-quantum scheme is activated");
}

if (signatureCount == 0
|| this.transaction.getRawData().getContractCount() <= 0) {
if (signatureCount == 0 || this.transaction.getRawData().getContractCount() <= 0) {
throw new ValidateSignatureException("miss sig or contract");
}
if (signatureCount > dynamicPropertiesStore.getTotalSignNum()) {
Expand Down Expand Up @@ -762,8 +761,7 @@ public static long validatePQSignatureGetWeight(Transaction transaction, Permiss
byte[] derivedAddr = PQSchemeRegistry.computeAddress(scheme, pk);
ByteString addrBs = ByteString.copyFrom(derivedAddr);
if (!signedAddresses.add(addrBs)) {
throw new PermissionException(
encode58Check(derivedAddr) + " has signed twice!");
throw new PermissionException(encode58Check(derivedAddr) + " has signed twice!");
}
Key matched = null;
for (Key k : permission.getKeysList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3144,10 +3144,8 @@ public boolean isPqSchemeAllowed(PQScheme scheme) {
return false;
}
switch (scheme) {
case FN_DSA_512:
return allowFnDsa512();
case ML_DSA_44:
return allowMlDsa44();
case FN_DSA_512: return allowFnDsa512();
case ML_DSA_44: return allowMlDsa44();
default:
if (PQSchemeRegistry.contains(scheme)) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public void start(Param param) {
this.blockHandle = param.getBlockHandle();
this.genesisBlock = param.getGenesisBlock();
this.genesisBlockTime = Long.parseLong(param.getGenesisBlock().getTimestamp());
param.getMiners().forEach(miner ->
miners.put(miner.getEffectiveWitnessAddress(), miner));
param.getMiners().forEach(miner -> miners.put(miner.getEffectiveWitnessAddress(), miner));

dposTask.setDposService(this);
dposSlot.setDposService(this);
Expand Down
34 changes: 16 additions & 18 deletions crypto/src/main/java/org/tron/common/crypto/pqc/FNDSA512.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public final class FNDSA512 implements PQSignature {
* retries on honest input is astronomically small.
*/
private static final int SIGN_RETRY_BUDGET = 16;
/** Falcon keygen seeds an internal SHAKE256 from 48 bytes of randomness. */
/**
* Falcon keygen seeds an internal SHAKE256 from 48 bytes of randomness.
*/
public static final int SEED_LENGTH = 48;

private static final FalconParameters PARAMS = FalconParameters.falcon_512;
Expand All @@ -115,12 +117,10 @@ public FNDSA512(byte[] seed) {

public FNDSA512(byte[] privateKey, byte[] publicKey) {
if (privateKey == null || privateKey.length != PRIVATE_KEY_LENGTH) {
throw new IllegalArgumentException(
"FN-DSA private key length must be " + PRIVATE_KEY_LENGTH);
throw new IllegalArgumentException("FN-DSA private key length must be " + PRIVATE_KEY_LENGTH);
}
if (publicKey == null || publicKey.length != PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(
"FN-DSA public key length must be " + PUBLIC_KEY_LENGTH);
throw new IllegalArgumentException("FN-DSA public key length must be " + PUBLIC_KEY_LENGTH);
}
requireConsistent(privateKey, publicKey);
this.privateKey = privateKey.clone();
Expand All @@ -137,9 +137,8 @@ public FNDSA512(byte[] privateKey, byte[] publicKey) {
public static FNDSA512 fromPrivateKeyWithPublicKey(byte[] extendedPrivateKey) {
if (extendedPrivateKey == null
|| extendedPrivateKey.length != PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(
"FN-DSA extended private key length must be "
+ PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH);
throw new IllegalArgumentException("FN-DSA extended private key length must be "
+ PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH);
}
byte[] sk = new byte[PRIVATE_KEY_LENGTH];
byte[] pk = new byte[PUBLIC_KEY_LENGTH];
Expand All @@ -163,7 +162,9 @@ public int getPublicKeyLength() {
return PUBLIC_KEY_LENGTH;
}

/** Returns the canonical signature length upper bound (signatures are variable-length). */
/**
* Returns the canonical signature length upper bound (signatures are variable-length).
*/
@Override
public int getSignatureLength() {
return SIGNATURE_MAX_LENGTH;
Expand Down Expand Up @@ -219,15 +220,13 @@ public boolean verify(byte[] message, byte[] signature) {

public static boolean verify(byte[] publicKey, byte[] message, byte[] signature) {
if (publicKey == null || publicKey.length != PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(
"FN-DSA public key length must be " + PUBLIC_KEY_LENGTH);
throw new IllegalArgumentException("FN-DSA public key length must be " + PUBLIC_KEY_LENGTH);
}
if (signature == null
|| signature.length < SIGNATURE_MIN_LENGTH
|| signature.length > SIGNATURE_MAX_LENGTH) {
throw new IllegalArgumentException(
"FN-DSA signature length must be "
+ SIGNATURE_MIN_LENGTH + ".." + SIGNATURE_MAX_LENGTH);
throw new IllegalArgumentException("FN-DSA signature length must be "
+ SIGNATURE_MIN_LENGTH + ".." + SIGNATURE_MAX_LENGTH);
}
if (message == null) {
throw new IllegalArgumentException("message must not be null");
Expand Down Expand Up @@ -370,10 +369,9 @@ private static void requireConsistent(byte[] privateKey, byte[] publicKey) {
private static void validatePrivateKeyBytes(byte[] privateKey) {
if (privateKey == null
|| (privateKey.length != PRIVATE_KEY_LENGTH
&& privateKey.length != PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH)) {
throw new IllegalArgumentException(
"FN-DSA private key length must be " + PRIVATE_KEY_LENGTH
+ " or " + PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH);
&& privateKey.length != PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH)) {
throw new IllegalArgumentException("FN-DSA private key length must be " + PRIVATE_KEY_LENGTH
+ " or " + PRIVATE_KEY_WITH_PUBLIC_KEY_LENGTH);
}
}
}
Loading