Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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 @@ -95,13 +95,14 @@ private boolean checkPermission(Permission permission) throws ContractValidateEx
long weightSum = 0;
List<ByteString> addressList = permission.getKeysList()
.stream()
.map(x -> x.getAddress())
.map(Key::getAddress)
.distinct()
.collect(toList());
if (addressList.size() != permission.getKeysList().size()) {
throw new ContractValidateException(
"address should be distinct in permission " + permission.getType());
}

for (Key key : permission.getKeysList()) {
if (!DecodeUtil.addressValid(key.getAddress().toByteArray())) {
throw new ContractValidateException("key is not a validate address");
Expand Down Expand Up @@ -237,4 +238,5 @@ public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
public long calcFee() {
return chainBaseManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee();
}

}
33 changes: 32 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,34 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_FN_DSA_512: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
throw new ContractValidateException("Bad chain parameter id [ALLOW_FN_DSA_512]");
}
if (value != 0 && value != 1) {
throw new ContractValidateException(
"This value[ALLOW_FN_DSA_512] is only allowed to be 0 or 1");
}
if (dynamicPropertiesStore.getAllowFnDsa512() == value) {
throw new ContractValidateException(
"[ALLOW_FN_DSA_512] has been set to " + value + ", no need to propose again");
}
break;
}
case ALLOW_ML_DSA_44: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
throw new ContractValidateException("Bad chain parameter id [ALLOW_ML_DSA_44]");
}
if (value != 0 && value != 1) {
throw new ContractValidateException(
"This value[ALLOW_ML_DSA_44] is only allowed to be 0 or 1");
}
if (dynamicPropertiesStore.getAllowMlDsa44() == value) {
throw new ContractValidateException(
"[ALLOW_ML_DSA_44] has been set to " + value + ", no need to propose again");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -1031,7 +1059,10 @@ public enum ProposalType { // current value, value range
ALLOW_TVM_PRAGUE(95), // 0, 1
ALLOW_TVM_OSAKA(96), // 0, 1
ALLOW_HARDEN_RESOURCE_CALCULATION(97), // 0, 1
ALLOW_HARDEN_EXCHANGE_CALCULATION(98); // 0, 1
ALLOW_HARDEN_EXCHANGE_CALCULATION(98), // 0, 1
ALLOW_FN_DSA_512(99), // 0, 1
ALLOW_ML_DSA_44(100); // 0, 1

private long code;

ProposalType(long code) {
Expand Down
46 changes: 32 additions & 14 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 All @@ -38,6 +38,7 @@
import org.tron.api.GrpcAPI.TransactionExtention;
import org.tron.api.GrpcAPI.TransactionSignWeight;
import org.tron.api.GrpcAPI.TransactionSignWeight.Result;
import org.tron.common.math.StrictMathWrapper;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.ChainBaseManager;
Expand All @@ -51,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 @@ -83,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 @@ -199,8 +201,8 @@ public static Transaction truncateSignatures(Transaction trx) {
public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
TransactionSignWeight.Builder tswBuilder = TransactionSignWeight.newBuilder();
Result.Builder resultBuilder = Result.newBuilder();
if (trx.getSignatureCount() > chainBaseManager.getDynamicPropertiesStore()
.getTotalSignNum()) {
if (trx.getSignatureCount() + trx.getPqAuthSigCount()
> chainBaseManager.getDynamicPropertiesStore().getTotalSignNum()) {
resultBuilder.setCode(Result.response_code.OTHER_ERROR);
resultBuilder.setMessage("too many signatures");
tswBuilder.setResult(resultBuilder);
Expand Down Expand Up @@ -243,14 +245,30 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
}
}
tswBuilder.setPermission(permission);
long currentWeight = 0L;
List<ByteString> approveList = new ArrayList<>();
if (trx.getSignatureCount() > 0) {
List<ByteString> approveList = new ArrayList<>();
long currentWeight = TransactionCapsule.checkWeight(permission, trx.getSignatureList(),
currentWeight = TransactionCapsule.checkWeight(permission, trx.getSignatureList(),
Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), trx.getRawData().toByteArray()), approveList);
tswBuilder.addAllApprovedList(approveList);
tswBuilder.setCurrentWeight(currentWeight);
}
if (trx.getPqAuthSigCount() > 0) {
if (!chainBaseManager.getDynamicPropertiesStore().isAnyPqSchemeAllowed()) {
throw new PermissionException(
"pq_auth_sig not allowed: no post-quantum scheme is activated");
}
try {
long pqWeight = TransactionCapsule.validatePQSignatureGetWeight(trx, permission,
chainBaseManager.getDynamicPropertiesStore(), approveList);
currentWeight = StrictMathWrapper.addExact(currentWeight, pqWeight);
} catch (ArithmeticException e) {
throw new PermissionException("weight overflow");
}
}

tswBuilder.addAllApprovedList(approveList);
tswBuilder.setCurrentWeight(currentWeight);

if (tswBuilder.getCurrentWeight() >= permission.getThreshold()) {
resultBuilder.setCode(Result.response_code.ENOUGH_PERMISSION);
} else {
Expand Down Expand Up @@ -279,13 +297,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
Loading
Loading