Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/triggerConstantContract & clearContractABI #2125

Merged
merged 54 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
fd9852c
Add opcode: SHL,SHR,SAR
ithinker1991 Mar 13, 2019
5ec51d5
Add `CREATE2`
ithinker1991 Mar 11, 2019
15b8649
Create contract save returnH value
ithinker1991 Mar 13, 2019
5164c05
Add dataword negate method
ithinker1991 Mar 15, 2019
cefa536
Fix DataWord bug
ithinker1991 Mar 18, 2019
078af92
Fix sender
ithinker1991 Mar 19, 2019
a78dfc5
Add bytes coder
ithinker1991 Mar 19, 2019
bde8009
Add create2 opcode unit test
ithinker1991 Mar 19, 2019
6b18e28
Remove debug msg
ithinker1991 Mar 19, 2019
a5d4069
Add opcode: SHL,SHR,SAR
ithinker1991 Mar 13, 2019
4bf766e
Add bitwise shift instructions
ithinker1991 Mar 18, 2019
417297f
Add shift test
ithinker1991 Mar 20, 2019
ec2e7ae
Fix shiftRightSigned bug
ithinker1991 Mar 20, 2019
b0c742c
Eliminate hidden dangers of DataWord where ZERO is pushed in to the s…
ithinker1991 Mar 20, 2019
9ead847
Fix unsafe method
ithinker1991 Mar 21, 2019
5c5ec2e
Merge branch 'tip29_bitwise_shifting' into tip26_create2
ithinker1991 Mar 21, 2019
f7673d8
Add Zero DataWord
ithinker1991 Mar 21, 2019
b0c8138
Merge branch 'tip29_bitwise_shifting' into tip26_create2
ithinker1991 Mar 21, 2019
1057095
Fix bug
ithinker1991 Mar 21, 2019
b9348c8
Zero DataWord can be rightValue
ithinker1991 Mar 21, 2019
e7f58d1
Merge branch 'tip29_bitwise_shifting' into tip26_create2
ithinker1991 Mar 21, 2019
9aa288b
Add repeat create2 test case
ithinker1991 Mar 21, 2019
0b9faef
refactor
BlueHoopor Mar 22, 2019
7895022
Polish code
ithinker1991 Mar 22, 2019
7aaac97
refactor
BlueHoopor Mar 22, 2019
f0e1ae8
Merge branch 'tip26_create2' of github.com:tronprotocol/java-tron int…
ithinker1991 Mar 22, 2019
30c55b7
Rename final var
ithinker1991 Mar 22, 2019
17b0ba3
refactor: add ALLOW_TVM_CONSTANTINOPLE proposal
CodeNinjaEvan Mar 22, 2019
2acc81b
refactor: filter the decision by allowTvmConstantinople proposal
CodeNinjaEvan Mar 22, 2019
c4ce3cb
Fix salt value
ithinker1991 Mar 25, 2019
5ce3d71
fix: ProposalCreateActuatorTest
CodeNinjaEvan Mar 25, 2019
647c7c7
Merge branch 'feature/bitwise_shifting' into feature/create2
ithinker1991 Mar 25, 2019
bc185cd
Add constantinople hard fork
ithinker1991 Mar 25, 2019
05c64a8
Test add hard fork
ithinker1991 Mar 25, 2019
f474192
Remove `of` method of DataWord
ithinker1991 Mar 25, 2019
41db264
Add fork logic
ithinker1991 Mar 26, 2019
9aa7df8
Add init_code hash
ithinker1991 Mar 27, 2019
0211005
add opcode EXTCODEHASH
llwslc Mar 27, 2019
5a5bd29
add extcodehash fork logic
llwslc Mar 27, 2019
77a67cb
test case DataWord to BigInteger method typo
llwslc Mar 27, 2019
2259037
Fix code style of ABIUtil.java
ithinker1991 Mar 27, 2019
512170b
change return of getCodeHashAt
llwslc Mar 27, 2019
e3062f3
add triggerConstantContract
llwslc Apr 1, 2019
53d322d
refactor constant check
ithinker1991 Apr 3, 2019
dec86a1
add constant_check of tx from P2P
llwslc Apr 9, 2019
70574d6
merge clear abi feature
llwslc Apr 2, 2019
3443bbb
add clearABIContractActuatorTest
llwslc Apr 8, 2019
81298f5
Merge branch 'develop' into feature/trigger_constant_contract
llwslc Apr 12, 2019
fdfddfc
fix enum ChainParameters
llwslc Apr 12, 2019
69afe39
reorder the parameters of `generateContractAddress2` method
ithinker1991 Apr 15, 2019
9f25a23
add triggerConstantContract clearABI http api
llwslc Apr 15, 2019
88d459c
add hard fork
llwslc Apr 15, 2019
73dcfa7
Merge branch 'develop' into feature/trigger_constant_contract
llwslc Apr 16, 2019
e731b68
add clearABI test hard fork
llwslc Apr 16, 2019
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
2 changes: 0 additions & 2 deletions src/main/java/org/tron/common/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

public interface Runtime {

boolean isCallConstant() throws ContractValidateException;

void execute() throws ContractValidateException, ContractExeException, VMIllegalException;

void go();
Expand Down
58 changes: 13 additions & 45 deletions src/main/java/org/tron/common/runtime/RuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.Block;
import org.tron.protos.Protocol.SmartContract;
import org.tron.protos.Protocol.SmartContract.ABI;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.Transaction.Result.contractResult;
Expand Down Expand Up @@ -86,7 +85,10 @@ public class RuntimeImpl implements Runtime {

//tx trace
private TransactionTrace trace;
private boolean isStaticCall;

@Getter
@Setter
private boolean isStaticCall = false;

@Setter
private boolean enableEventLinstener;
Expand Down Expand Up @@ -447,7 +449,6 @@ private void create()
this.blockCap);
byte[] txId = new TransactionCapsule(trx).getTransactionId().getBytes();
this.program.setRootTransactionId(txId);
this.program.setRootCallConstant(isCallConstant());
if (enableEventLinstener &&
(EventPluginLoader.getInstance().isContractEventTriggerEnable()
|| EventPluginLoader.getInstance().isContractLogTriggerEnable())
Expand All @@ -467,8 +468,9 @@ && isCheckTransaction()) {

deposit.createContract(contractAddress, new ContractCapsule(newSmartContract));
byte[] code = newSmartContract.getBytecode().toByteArray();
deposit.saveCode(contractAddress, ProgramPrecompile.getCode(code));

if (!VMConfig.allowTvmConstantinople()) {
deposit.saveCode(contractAddress, ProgramPrecompile.getCode(code));
}
// transfer from callerAddress to contractAddress according to callValue
if (callValue > 0) {
transfer(this.deposit, callerAddress, contractAddress, callValue);
Expand Down Expand Up @@ -542,14 +544,14 @@ private void call()
}
AccountCapsule caller = this.deposit.getAccount(callerAddress);
long energyLimit;
if (isCallConstant(contractAddress)) {
isStaticCall = true;
if (isStaticCall) {
energyLimit = Constant.ENERGY_LIMIT_IN_CONSTANT_TX;
} else {
AccountCapsule creator = this.deposit
.getAccount(deployedContract.getInstance().getOriginAddress().toByteArray());
energyLimit = getTotalEnergyLimit(creator, caller, contract, feeLimit, callValue);
}

long maxCpuTimeOfOneTx = deposit.getDbManager().getDynamicPropertiesStore()
.getMaxCpuTimeOfOneTx() * Constant.ONE_THOUSAND;
long thisTxCPULimitInUs =
Expand All @@ -569,7 +571,6 @@ private void call()
this.blockCap);
byte[] txId = new TransactionCapsule(trx).getTransactionId().getBytes();
this.program.setRootTransactionId(txId);
this.program.setRootCallConstant(isCallConstant());

if (enableEventLinstener &&
(EventPluginLoader.getInstance().isContractEventTriggerEnable()
Expand Down Expand Up @@ -613,7 +614,7 @@ public void go() {
vm.play(program);
result = program.getResult();

if (isCallConstant()) {
if (isStaticCall) {
long callValue = TransactionCapsule.getCallValue(trx.getRawData().getContract(0));
long callTokenValue = TransactionCapsule
.getCallTokenValue(trx.getRawData().getContract(0));
Expand All @@ -636,6 +637,9 @@ public void go() {
}
} else {
result.spendEnergy(saveCodeEnergy);
if (VMConfig.allowTvmConstantinople()) {
deposit.saveCode(program.getContractAddress().getNoLeadZeroesData(), code);
}
}
}

Expand Down Expand Up @@ -679,8 +683,6 @@ public void go() {
result.rejectInternalTransactions();
runtimeError = result.getException().getMessage();
logger.info("timeout: {}", result.getException().getMessage());
} catch (ContractValidateException e) {
logger.info("when check constant, {}", e.getMessage());
} catch (Throwable e) {
program.spendAllEnergy();
result = program.getResult();
Expand All @@ -706,40 +708,6 @@ private static long getEnergyFee(long callerEnergyUsage, long callerEnergyFrozen
.divide(BigInteger.valueOf(callerEnergyTotal)).longValueExact();
}

public boolean isCallConstant() throws ContractValidateException {

TriggerSmartContract triggerContractFromTransaction = ContractCapsule
.getTriggerContractFromTransaction(trx);
if (TrxType.TRX_CONTRACT_CALL_TYPE == trxType) {

ContractCapsule contract = deposit
.getContract(triggerContractFromTransaction.getContractAddress().toByteArray());
if (contract == null) {
logger.info("contract: {} is not in contract store", Wallet
.encode58Check(triggerContractFromTransaction.getContractAddress().toByteArray()));
throw new ContractValidateException("contract: " + Wallet
.encode58Check(triggerContractFromTransaction.getContractAddress().toByteArray())
+ " is not in contract store");
}
ABI abi = contract.getInstance().getAbi();
if (Wallet.isConstant(abi, triggerContractFromTransaction)) {
return true;
}
}
return false;
}

private boolean isCallConstant(byte[] address) throws ContractValidateException {

if (TrxType.TRX_CONTRACT_CALL_TYPE == trxType) {
ABI abi = deposit.getContract(address).getInstance().getAbi();
if (Wallet.isConstant(abi, ContractCapsule.getTriggerContractFromTransaction(trx))) {
return true;
}
}
return false;
}

public void finalization() {
if (StringUtils.isEmpty(runtimeError)) {
for (DataWord contract : result.getDeleteAccounts()) {
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/tron/common/runtime/config/VMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
*/
package org.tron.common.runtime.config;

import lombok.Getter;
import lombok.Setter;
import org.tron.common.utils.ForkController;
import org.tron.core.config.Parameter.ForkBlockVersionConsts;
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
import org.tron.core.config.args.Args;
import org.tron.core.db.Manager;

/**
* For developer only
Expand All @@ -48,6 +45,9 @@ public class VMConfig {
@Setter
private static boolean ALLOW_TVM_TRANSFER_TRC10 = false;

@Setter
private static boolean ALLOW_TVM_CONSTANTINOPLE = false;

@Setter
private static boolean ALLOW_MULTI_SIGN = false;

Expand Down Expand Up @@ -84,6 +84,10 @@ public static void initAllowTvmTransferTrc10(long allow) {
ALLOW_TVM_TRANSFER_TRC10 = allow == 1;
}

public static void initAllowTvmConstantinople(long allow) {
ALLOW_TVM_CONSTANTINOPLE = allow == 1;
}

public static boolean getEnergyLimitHardFork() {
return ENERGY_LIMIT_HARD_FORK;
}
Expand All @@ -92,6 +96,10 @@ public static boolean allowTvmTransferTrc10() {
return ALLOW_TVM_TRANSFER_TRC10;
}

public static boolean allowTvmConstantinople() {
return ALLOW_TVM_CONSTANTINOPLE;
}

public static boolean allowMultiSign() {
return ALLOW_MULTI_SIGN;
}
Expand Down
Loading