Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
636405c
include create account fees in the black hole account
Rovak Aug 23, 2018
9b63143
OwnerAddress not equals OriginAddress.
CodeNinjaEvan Sep 4, 2018
bed6bdc
Merge pull request #1441 from tronprotocol/owner_origin_address
huzhenyuan Sep 5, 2018
13a0306
upgrade blockchain version to 2
Yrp Sep 5, 2018
9e12259
refine exceptions in vm
taihaofu Sep 5, 2018
20158e3
add log
tjchern Sep 5, 2018
da5f84b
Merge remote-tracking branch 'remotes/origin/develop' into test_about…
tjchern Sep 5, 2018
550b88b
Merge pull request #1443 from tronprotocol/refine_nullpointerexceptio…
huzhenyuan Sep 5, 2018
2a572a2
set fee_limit up to 1000 trx
Sep 5, 2018
0bbd1e6
update code style
Sep 5, 2018
3770705
set fee_limit up to 1000trx for junit test
Sep 5, 2018
2c416b4
:mute:fork log level to debug
Yrp Sep 5, 2018
7826ffa
Merge pull request #1445 from tronprotocol/fee_limit
huzhenyuan Sep 5, 2018
25b5c75
Merge pull request #1442 from tronprotocol/upgrade_version_2
huzhenyuan Sep 5, 2018
65cd194
Merge pull request #1446 from tronprotocol/remove_logs
huzhenyuan Sep 5, 2018
2fa0152
Merge branch 'master' of https://github.com/tronprotocol/java-tron
CodeNinjaEvan Sep 5, 2018
c795b75
comment out precompile functions
taihaofu Sep 5, 2018
c9176f0
comment out precompile instance
taihaofu Sep 5, 2018
dc1e98c
add fee in blackhole
nanfengpo Sep 5, 2018
36834ca
Merge pull request #1447 from tronprotocol/comment_out_precompile
huzhenyuan Sep 5, 2018
b3dc660
Merge pull request #1352 from tronprotocol/createaccount_add_fee_to_b…
sean-liu55 Sep 5, 2018
ea6dde7
send Fee to Black hole.
CodeNinjaEvan Sep 5, 2018
b6cf587
Merge pull request #1448 from tronprotocol/send_to_block_hole
huzhenyuan Sep 5, 2018
719b19e
throw timeout
tjchern Sep 5, 2018
63dd34d
fix bug
tjchern Sep 5, 2018
1490db2
Merge remote-tracking branch 'remotes/origin/develop' into fix_timeou…
tjchern Sep 5, 2018
0eaae13
create cmd should use child deposit
ithinker1991 Sep 5, 2018
1940257
Update VM.java
huzhenyuan Sep 5, 2018
4c2977d
reset cacl bytesSize.
CodeNinjaEvan Sep 5, 2018
a201942
Merge pull request #1449 from tronprotocol/fix_timeout_bug
huzhenyuan Sep 5, 2018
af9637b
Merge pull request #1450 from tronprotocol/fix/create_child_deposit
huzhenyuan Sep 5, 2018
da9a8ac
Merge pull request #1451 from tronprotocol/set_ret
huzhenyuan Sep 5, 2018
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
70 changes: 45 additions & 25 deletions src/main/java/org/tron/common/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.spongycastle.util.encoders.Hex;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.DataWord;
import org.tron.common.runtime.vm.EnergyCost;
import org.tron.common.runtime.vm.PrecompiledContracts;
Expand All @@ -34,6 +34,7 @@
import org.tron.common.runtime.vm.program.InternalTransaction.ExecutorType;
import org.tron.common.runtime.vm.program.Program;
import org.tron.common.runtime.vm.program.Program.JVMStackOverFlowException;
import org.tron.common.runtime.vm.program.Program.OutOfResourceException;
import org.tron.common.runtime.vm.program.ProgramPrecompile;
import org.tron.common.runtime.vm.program.ProgramResult;
import org.tron.common.runtime.vm.program.invoke.ProgramInvoke;
Expand Down Expand Up @@ -70,7 +71,7 @@
public class Runtime {


private SystemProperties config = SystemProperties.getInstance();
private VMConfig config = VMConfig.getInstance();

private Transaction trx;
private BlockCapsule blockCap = null;
Expand Down Expand Up @@ -184,18 +185,24 @@ public BigInteger getBlockCPULeftInUs() {
}

public void execute() throws ContractValidateException, ContractExeException {
switch (trxType) {
case TRX_PRECOMPILED_TYPE:
precompiled();
break;
case TRX_CONTRACT_CREATION_TYPE:
create();
break;
case TRX_CONTRACT_CALL_TYPE:
call();
break;
default:
throw new ContractValidateException("Unknown contract type");
try {
switch (trxType) {
case TRX_PRECOMPILED_TYPE:
precompiled();
break;
case TRX_CONTRACT_CREATION_TYPE:
create();
break;
case TRX_CONTRACT_CALL_TYPE:
call();
break;
default:
throw new ContractValidateException("Unknown contract type");
}
} catch (ContractExeException | ContractValidateException e) {
throw e;
} catch (Exception e) {
throw new ContractValidateException("Unknown contract error");
}
}

Expand Down Expand Up @@ -303,7 +310,10 @@ private void create()

CreateSmartContract contract = ContractCapsule.getSmartContractFromTransaction(trx);
SmartContract newSmartContract = contract.getNewContract();

if (!contract.getOwnerAddress().equals(newSmartContract.getOriginAddress())) {
logger.error("OwnerAddress not equals OriginAddress");
throw new ContractValidateException("OwnerAddress not equals OriginAddress");
}
byte[] code = newSmartContract.getBytecode().toByteArray();
byte[] contractAddress = Wallet.generateContractAddress(trx);
byte[] ownerAddress = contract.getOwnerAddress().toByteArray();
Expand Down Expand Up @@ -348,9 +358,10 @@ private void create()
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;

long feeLimit = trx.getRawData().getFeeLimit();
if (feeLimit < 0) {
logger.info("feeLimit < 0");
throw new ContractValidateException("feeLimit must be >= 0");
if (feeLimit < 0 || feeLimit > VMConfig.MAX_FEE_LIMIT) {
logger.warn("invalid feeLimit {}", feeLimit);
throw new ContractValidateException(
"feeLimit must be >= 0 and <= " + VMConfig.MAX_FEE_LIMIT);
}

long energyLimit = getEnergyLimit(creator, feeLimit, callValue);
Expand Down Expand Up @@ -425,9 +436,10 @@ private void call()
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;

long feeLimit = trx.getRawData().getFeeLimit();
if (feeLimit < 0) {
logger.info("feeLimit < 0");
throw new ContractValidateException("feeLimit must be >= 0");
if (feeLimit < 0 || feeLimit > VMConfig.MAX_FEE_LIMIT) {
logger.warn("invalid feeLimit {}", feeLimit);
throw new ContractValidateException(
"feeLimit must be >= 0 and <= " + VMConfig.MAX_FEE_LIMIT);
}
long energyLimit;
if (isCallConstant(contractAddress)) {
Expand Down Expand Up @@ -489,10 +501,12 @@ public void go() {
long saveCodeEnergy = getLength(code) * EnergyCost.getInstance().getCREATE_DATA();
long afterSpend = program.getEnergyLimitLeft().longValue() - saveCodeEnergy;
if (afterSpend < 0) {
result.setException(
Program.Exception
.notEnoughSpendEnergy("No energy to save just created contract code",
saveCodeEnergy, program.getEnergyLimitLeft().longValue()));
if (null == result.getException()) {
result.setException(
Program.Exception
.notEnoughSpendEnergy("save just created contract code",
saveCodeEnergy, program.getEnergyLimitLeft().longValue()));
}
} else {
result.spendEnergy(saveCodeEnergy);
// have saveCode in create()
Expand All @@ -518,6 +532,12 @@ public void go() {
deposit.commit();
}
} catch (JVMStackOverFlowException e) {
program.spendAllEnergy();
result.setException(e);
runtimeError = result.getException().getMessage();
logger.error("runtime error is :{}", result.getException().getMessage());
} catch (OutOfResourceException e) {
program.spendAllEnergy();
result.setException(e);
runtimeError = result.getException().getMessage();
logger.error("runtime error is :{}", result.getException().getMessage());
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/tron/common/runtime/config/DefaultConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,31 @@
*/
package org.tron.common.runtime.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* For developer only
* For developer only
*/
public class SystemProperties {
public class VMConfig {

public static final int MAX_CODE_LENGTH = 1024 * 1024;

private static Logger logger = LoggerFactory.getLogger("general");
public static final int MAX_FEE_LIMIT = 1_000_000_000; //1000 trx

private boolean vmTraceCompressed = false;
private boolean vmOn = true;
private boolean vmTrace = false;

private SystemProperties() {

private VMConfig() {
}

private static class SystemPropertiesInstance {

private static final SystemProperties INSTANCE = new SystemProperties();
private static final VMConfig INSTANCE = new VMConfig();
}

public static SystemProperties getInstance() {
public static VMConfig getInstance() {
return SystemPropertiesInstance.INSTANCE;
}

public boolean vmOn() {
return vmOn;
}

public boolean vmTrace() {
return vmTrace;
}
Expand Down
102 changes: 49 additions & 53 deletions src/main/java/org/tron/common/runtime/vm/PrecompiledContracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ public class PrecompiledContracts {
private static final BN128Addition altBN128Add = new BN128Addition();
private static final BN128Multiplication altBN128Mul = new BN128Multiplication();
private static final BN128Pairing altBN128Pairing = new BN128Pairing();
private static final VoteWitnessNative voteContract = new VoteWitnessNative();
// private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative();
// private static final VoteWitnessNative voteContract = new VoteWitnessNative();
// private static final FreezeBalanceNative freezeBalance = new FreezeBalanceNative();
// private static final UnfreezeBalanceNative unFreezeBalance = new UnfreezeBalanceNative();
private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative();
private static final ProposalApproveNative proposalApprove = new ProposalApproveNative();
private static final ProposalCreateNative proposalCreate = new ProposalCreateNative();
private static final ProposalDeleteNative proposalDelete = new ProposalDeleteNative();
private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative();
private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative();
// private static final WithdrawBalanceNative withdrawBalance = new WithdrawBalanceNative();
// private static final ProposalApproveNative proposalApprove = new ProposalApproveNative();
// private static final ProposalCreateNative proposalCreate = new ProposalCreateNative();
// private static final ProposalDeleteNative proposalDelete = new ProposalDeleteNative();
// private static final ConvertFromTronBytesAddressNative convertFromTronBytesAddress = new ConvertFromTronBytesAddressNative();
// private static final ConvertFromTronBase58AddressNative convertFromTronBase58Address = new ConvertFromTronBase58AddressNative();
// private static final TransferAssetNative transferAsset = new TransferAssetNative();
private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative();
// private static final GetTransferAssetNative getTransferAssetAmount = new GetTransferAssetNative();

private static final ECKey addressCheckECKey = new ECKey();
private static final String addressCheckECKeyAddress = Wallet
Expand All @@ -121,28 +121,28 @@ public class PrecompiledContracts {
"0000000000000000000000000000000000000000000000000000000000000007");
private static final DataWord altBN128PairingAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000000008");
private static final DataWord voteContractAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010001");
// private static final DataWord voteContractAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010001");
// private static final DataWord freezeBalanceAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010002");
// private static final DataWord unFreezeBalanceAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010003");
private static final DataWord withdrawBalanceAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010004");
private static final DataWord proposalApproveAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010005");
private static final DataWord proposalCreateAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010006");
private static final DataWord proposalDeleteAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010007");
private static final DataWord convertFromTronBytesAddressAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010008");
private static final DataWord convertFromTronBase58AddressAddr = new DataWord(
"0000000000000000000000000000000000000000000000000000000000010009");
// private static final DataWord withdrawBalanceAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010004");
// private static final DataWord proposalApproveAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010005");
// private static final DataWord proposalCreateAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010006");
// private static final DataWord proposalDeleteAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010007");
// private static final DataWord convertFromTronBytesAddressAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010008");
// private static final DataWord convertFromTronBase58AddressAddr = new DataWord(
// "0000000000000000000000000000000000000000000000000000000000010009");
// private static final DataWord transferAssetAddr = new DataWord(
// "000000000000000000000000000000000000000000000000000000000001000a");
private static final DataWord getTransferAssetAmountAddr = new DataWord(
"000000000000000000000000000000000000000000000000000000000001000b");
// private static final DataWord getTransferAssetAmountAddr = new DataWord(
// "000000000000000000000000000000000000000000000000000000000001000b");

public static PrecompiledContract getContractForAddress(DataWord address) {

Expand All @@ -161,39 +161,39 @@ public static PrecompiledContract getContractForAddress(DataWord address) {
if (address.equals(identityAddr)) {
return identity;
}
if (address.equals(voteContractAddr)) {
return voteContract;
}
// if (address.equals(voteContractAddr)) {
// return voteContract;
// }
// if (address.equals(freezeBalanceAddr)) {
// return freezeBalance;
// }
// if (address.equals(unFreezeBalanceAddr)) {
// return unFreezeBalance;
// }
if (address.equals(withdrawBalanceAddr)) {
return withdrawBalance;
}
if (address.equals(proposalApproveAddr)) {
return proposalApprove;
}
if (address.equals(proposalCreateAddr)) {
return proposalCreate;
}
if (address.equals(proposalDeleteAddr)) {
return proposalDelete;
}
if (address.equals(convertFromTronBytesAddressAddr)) {
return convertFromTronBytesAddress;
}
if (address.equals(convertFromTronBase58AddressAddr)) {
return convertFromTronBase58Address;
}
// if (address.equals(withdrawBalanceAddr)) {
// return withdrawBalance;
// }
// if (address.equals(proposalApproveAddr)) {
// return proposalApprove;
// }
// if (address.equals(proposalCreateAddr)) {
// return proposalCreate;
// }
// if (address.equals(proposalDeleteAddr)) {
// return proposalDelete;
// }
// if (address.equals(convertFromTronBytesAddressAddr)) {
// return convertFromTronBytesAddress;
// }
// if (address.equals(convertFromTronBase58AddressAddr)) {
// return convertFromTronBase58Address;
// }
// if (address.equals(transferAssetAddr)) {
// return transferAsset;
// }
if (address.equals(getTransferAssetAmountAddr)) {
return getTransferAssetAmount;
}
// if (address.equals(getTransferAssetAmountAddr)) {
// return getTransferAssetAmount;
// }

// Byzantium precompiles
if (address.equals(modExpAddr)) {
Expand Down Expand Up @@ -912,10 +912,6 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
return Pair.of(true, new DataWord(0).getData());
}

if (data == null) {
data = EMPTY_BYTE_ARRAY;
}

Contract.WithdrawBalanceContract.Builder builder = Contract.WithdrawBalanceContract
.newBuilder();
ByteString byteAddress = ByteString.copyFrom(getCallerAddress());
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/tron/common/runtime/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
import org.spongycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.tron.common.runtime.config.SystemProperties;
import org.tron.common.runtime.config.VMConfig;
import org.tron.common.runtime.vm.program.Program;
import org.tron.common.runtime.vm.program.Program.JVMStackOverFlowException;
import org.tron.common.runtime.vm.program.Program.OutOfEnergyException;
import org.tron.common.runtime.vm.program.Program.OutOfResourceException;
import org.tron.common.runtime.vm.program.Stack;

@Slf4j(topic = "VM")
Expand All @@ -41,14 +42,14 @@ public class VM {
private boolean vmTrace;
// private long dumpBlock;

private final SystemProperties config;
private final VMConfig config;

public VM() {
config = SystemProperties.getInstance();
config = VMConfig.getInstance();
}

@Autowired
public VM(SystemProperties config) {
public VM(VMConfig config) {
this.config = config;
// vmTrace = config.vmTrace();
// dumpBlock = config.dumpBlock();
Expand Down Expand Up @@ -1332,7 +1333,9 @@ public void play(Program program) {
}

} catch (JVMStackOverFlowException e) {
throw new JVMStackOverFlowException();
throw e;
} catch (OutOfResourceException e) {
throw e;
} catch (RuntimeException e) {
if (StringUtils.isEmpty(e.getMessage())) {
program.setRuntimeFailure(new RuntimeException("Unknown Exception"));
Expand Down
Loading