Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
60 changes: 60 additions & 0 deletions .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Dependency Check"

on:
push:
branches: [ 'develop', 'master', 'release_**', 'feat/state_root_sync' ]
pull_request:
branches: [ 'develop', "release_**" , 'feat/state_root_sync' ]
schedule:
- cron: '25 6 * * *'
workflow_dispatch:

jobs:
dependency-check:
name: Dependency Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Cache ODC data
uses: actions/cache@v3
with:
path: ~/.dependency-check/data
key: ${{ runner.os }}-odc-data-${{ hashFiles('**/build.gradle') }}
restore-keys: |
${{ runner.os }}-odc-data-

- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'

- name: Gradlew build
run: ./gradlew --no-daemon -S -Dorg.gradle.dependency.verification=off -Dorg.gradle.warning.mode=none build -x test

- name: Dependency Check
uses: dependency-check/Dependency-Check_Action@1.1.0
env:
# actions/setup-java@v1 changes JAVA_HOME, so it needs to be reset to match the depcheck image
JAVA_HOME: /opt/jdk
with:
project: 'java-tron'
path: '.'
format: 'HTML'
out: 'reports'
args: >
--failOnCVSS 7
--enableRetired
- name: Generate timestamp
run: echo "BUILD_TIMESTAMP=$(date -u +"%Y%m%d-%H%M%S")" >> $GITHUB_ENV
- name: Get Repository Name
run: echo "REPO_NAME=$(echo '${{ github.repository }}' | cut -d'/' -f2)" >> $GITHUB_ENV
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: dependency-check-${{ env.REPO_NAME }}-${{ env.BUILD_TIMESTAMP }}
path: ${{github.workspace}}/reports
29 changes: 29 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Dependency Submission

on:
push:
branches: [ 'develop', 'master', 'release_**', 'feat/state_root_sync' ]
pull_request:
branches: [ 'develop', "release_**" , 'feat/state_root_sync' ]

workflow_dispatch:

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-24.04-arm

steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v4
243 changes: 131 additions & 112 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions actuator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ test {

jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
xml.required.set(true)
html.required.set(true)
}
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.StrictMathWrapper;
import org.tron.common.utils.DecodeUtil;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.AssetIssueCapsule;
import org.tron.core.capsule.TransactionResultCapsule;
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
import org.tron.core.exception.BalanceInsufficientException;
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
Expand Down Expand Up @@ -263,6 +265,16 @@ public boolean validate() throws ContractValidateException {
"frozenDuration must be less than " + maxFrozenSupplyTime + " days "
+ "and more than " + minFrozenSupplyTime + " days");
}
// make sure FrozenSupply.expireTime not overflow
if (chainBaseManager.getForkController().pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
long frozenPeriod = next.getFrozenDays() * FROZEN_PERIOD;
try {
StrictMathWrapper.addExact(assetIssueContract.getStartTime(), frozenPeriod);
} catch (ArithmeticException e) {
throw new ContractValidateException(
"Start time and frozen days would cause expire time overflow");
}
}
remainSupply -= next.getFrozenAmount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.DecodeUtil;
import org.tron.common.utils.StringUtil;
import org.tron.core.capsule.ProposalCapsule;
Expand Down Expand Up @@ -53,7 +52,7 @@ public boolean execute(Object result) throws ContractExeException {

long currentMaintenanceTime =
chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
long now3 = now + CommonParameter.getInstance().getProposalExpireTime();
long now3 = now + chainBaseManager.getDynamicPropertiesStore().getProposalExpireTime();
long round = (now3 - currentMaintenanceTime) / maintenanceTimeInterval;
long expirationTime =
currentMaintenanceTime + (round + 1) * maintenanceTimeInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,27 @@ private void executeShielded(List<SpendDescription> spends, List<ReceiveDescript
}
nullifierStore.put(new BytesCapsule(spend.getNullifier().toByteArray()));
}
if (CommonParameter.getInstance().isFullNodeAllowShieldedTransactionArgs()) {
IncrementalMerkleTreeContainer currentMerkle = merkleContainer.getCurrentMerkle();

IncrementalMerkleTreeContainer currentMerkle = merkleContainer.getCurrentMerkle();
try {
currentMerkle.wfcheck();
} catch (ZksnarkException e) {
ret.setStatus(fee, code.FAILED);
ret.setShieldedTransactionFee(fee);
throw new ContractExeException(e.getMessage());
}
//handle receives
for (ReceiveDescription receive : receives) {
try {
currentMerkle.wfcheck();
merkleContainer
.saveCmIntoMerkleTree(currentMerkle, receive.getNoteCommitment().toByteArray());
} catch (ZksnarkException e) {
ret.setStatus(fee, code.FAILED);
ret.setStatus(0, code.FAILED);
ret.setShieldedTransactionFee(fee);
throw new ContractExeException(e.getMessage());
}
//handle receives
for (ReceiveDescription receive : receives) {
try {
merkleContainer
.saveCmIntoMerkleTree(currentMerkle, receive.getNoteCommitment().toByteArray());
} catch (ZksnarkException e) {
ret.setStatus(0, code.FAILED);
ret.setShieldedTransactionFee(fee);
throw new ContractExeException(e.getMessage());
}
}
merkleContainer.setCurrentMerkle(currentMerkle);
}
merkleContainer.setCurrentMerkle(currentMerkle);
}

@Override
Expand Down Expand Up @@ -236,8 +235,7 @@ public boolean validate() throws ContractValidateException {
throw new ContractValidateException("duplicate sapling nullifiers in this transaction");
}
nfSet.add(spendDescription.getNullifier());
if (CommonParameter.getInstance().isFullNodeAllowShieldedTransactionArgs()
&& !merkleContainer.merkleRootExist(spendDescription.getAnchor().toByteArray())) {
if (!merkleContainer.merkleRootExist(spendDescription.getAnchor().toByteArray())) {
throw new ContractValidateException("Rt is invalid.");
}
if (nullifierStore.has(spendDescription.getNullifier().toByteArray())) {
Expand Down
38 changes: 36 additions & 2 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;

import org.tron.common.utils.ForkController;
Expand Down Expand Up @@ -354,7 +356,8 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
break;
}
case ALLOW_MARKET_TRANSACTION: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1)) {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1)
|| forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_MARKET_TRANSACTION]");
}
Expand Down Expand Up @@ -839,6 +842,35 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_TVM_SELFDESTRUCT_RESTRICTION: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_TVM_SELFDESTRUCT_RESTRICTION]");
}
if (dynamicPropertiesStore.allowTvmSelfdestructRestriction()) {
throw new ContractValidateException(
"[ALLOW_TVM_SELFDESTRUCT_RESTRICTION] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_TVM_SELFDESTRUCT_RESTRICTION] is only allowed to be 1");
}
break;
}
case PROPOSAL_EXPIRE_TIME: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
throw new ContractValidateException(
"Bad chain parameter id [PROPOSAL_EXPIRE_TIME]");
}
if (value <= MIN_PROPOSAL_EXPIRE_TIME
|| value >= MAX_PROPOSAL_EXPIRE_TIME) {
throw new ContractValidateException(
"This value[PROPOSAL_EXPIRE_TIME] is only allowed to be greater than "
+ MIN_PROPOSAL_EXPIRE_TIME + " and less than "
+ MAX_PROPOSAL_EXPIRE_TIME + "!");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -921,7 +953,9 @@ public enum ProposalType { // current value, value range
ALLOW_TVM_CANCUN(83), // 0, 1
ALLOW_STRICT_MATH(87), // 0, 1
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
ALLOW_TVM_BLOB(89); // 0, 1
ALLOW_TVM_BLOB(89), // 0, 1
PROPOSAL_EXPIRE_TIME(92), // (0, 31536003000)
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94); // 0, 1

private long code;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
package org.tron.core.utils;

import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.reflections.Reflections;
import org.tron.core.actuator.AbstractActuator;
import org.tron.core.exception.TronError;

@Slf4j(topic = "TransactionRegister")
public class TransactionRegister {

private static final AtomicBoolean REGISTERED = new AtomicBoolean(false);
private static final String PACKAGE_NAME = "org.tron.core.actuator";

public static void registerActuator() {
Reflections reflections = new Reflections("org.tron");
Set<Class<? extends AbstractActuator>> subTypes = reflections
.getSubTypesOf(AbstractActuator.class);
for (Class _class : subTypes) {
try {
_class.newInstance();
} catch (Exception e) {
logger.error("{} contract actuator register fail!", _class, e);
if (REGISTERED.get()) {
logger.info("Actuator already registered.");
return;
}

synchronized (TransactionRegister.class) {
if (REGISTERED.get()) {
logger.info("Actuator already registered.");
return;
}

logger.info("Register actuator start.");
Reflections reflections = new Reflections(PACKAGE_NAME);
Set<Class<? extends AbstractActuator>> subTypes = reflections
.getSubTypesOf(AbstractActuator.class);

for (Class<? extends AbstractActuator> clazz : subTypes) {
try {
logger.debug("Registering actuator: {} start", clazz.getName());
clazz.getDeclaredConstructor().newInstance();
logger.debug("Registering actuator: {} done", clazz.getName());
} catch (Exception e) {
throw new TronError(clazz.getName() + ": "
+ (e.getCause() == null ? e.getMessage() : e.getCause().getMessage()),
e, TronError.ErrCode.ACTUATOR_REGISTER);
}
}

REGISTERED.set(true);
logger.info("Register actuator done, total {}.", subTypes.size());
}
}

}
9 changes: 9 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/EnergyCost.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class EnergyCost {
private static final long EXT_CODE_SIZE = 20;
private static final long EXT_CODE_HASH = 400;
private static final long SUICIDE = 0;
private static final long SUICIDE_V2 = 5000;
private static final long STOP = 0;
private static final long CREATE_DATA = 200;
private static final long TLOAD = 100;
Expand Down Expand Up @@ -289,6 +290,14 @@ public static long getSuicideCost2(Program program) {
return getSuicideCost(program);
}

public static long getSuicideCost3(Program program) {
DataWord inheritorAddress = program.getStack().peek();
if (isDeadAccount(program, inheritorAddress)) {
return SUICIDE_V2 + NEW_ACCT_CALL;
}
return SUICIDE_V2;
}

public static long getBalanceCost(Program ignored) {
return BALANCE;
}
Expand Down
15 changes: 15 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/OperationActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1072,4 +1072,19 @@ public static void suicideAction(Program program) {
program.stop();
}

public static void suicideAction2(Program program) {
if (program.isStaticCall()) {
throw new Program.StaticCallModificationException();
}

if (!program.canSuicide2()) {
program.getResult().setRevert();
} else {
DataWord address = program.stackPop();
program.suicide2(address);
}

program.stop();
}

}
11 changes: 11 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/OperationRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static JumpTable getTable() {
adjustForFairEnergy(table);
}

if (VMConfig.allowTvmSelfdestructRestriction()) {
adjustSelfdestruct(table);
}

return table;
}

Expand Down Expand Up @@ -695,4 +699,11 @@ public static void appendCancunOperations(JumpTable table) {
OperationActions::blobBaseFeeAction,
tvmBlobProposal));
}

public static void adjustSelfdestruct(JumpTable table) {
table.set(new Operation(
Op.SUICIDE, 1, 0,
EnergyCost::getSuicideCost3,
OperationActions::suicideAction2));
}
}
Loading
Loading