diff --git a/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java b/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java index cb060f8a9b..af78ff0348 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java @@ -34,28 +34,27 @@ import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; -import org.aion.interfaces.db.RepositoryCache; -import org.aion.mcf.tx.TransactionTypes; -import org.aion.mcf.valid.TransactionTypeRule; -import org.aion.types.Address; import org.aion.crypto.ECKey; import org.aion.fastvm.FastVmResultCode; +import org.aion.interfaces.db.RepositoryCache; import org.aion.log.AionLoggerFactory; import org.aion.log.LogEnum; +import org.aion.mcf.tx.TransactionTypes; +import org.aion.mcf.valid.TransactionTypeRule; import org.aion.mcf.vm.Constants; import org.aion.mcf.vm.types.DataWordImpl; +import org.aion.types.Address; import org.aion.util.bytes.ByteUtil; import org.aion.util.conversions.Hex; import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; - import org.aion.vm.VirtualMachineProvider; import org.aion.vm.api.interfaces.ResultCode; import org.aion.vm.exception.VMException; -import org.aion.zero.impl.db.AionRepositoryCache; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.StandaloneBlockchain.Builder; +import org.aion.zero.impl.db.AionRepositoryCache; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.impl.vm.contracts.ContractUtils; import org.aion.zero.types.AionTransaction; @@ -84,7 +83,7 @@ public class ContractIntegTest { public void setup() { StandaloneBlockchain.Bundle bundle = (new Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build(); - TransactionTypeRule.disallowAVMContractTransaction(); + TransactionTypeRule.allowAVMContractTransaction(); blockchain = bundle.bc; deployerKey = bundle.privateKeys.get(0); deployer = new Address(deployerKey.getAddress()); @@ -121,7 +120,13 @@ public void testEmptyContract() throws IOException, VMException { // to == null signals that this is contract creation. AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertTrue(tx.isContractCreationTransaction()); @@ -162,7 +167,13 @@ public void testContractDeployCodeIsEmpty() throws VMException { // to == null signals that this is contract creation. AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), new byte[0], nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + new byte[0], + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertTrue(tx.isContractCreationTransaction()); @@ -199,7 +210,13 @@ public void testContractDeployCodeIsNonsensical() throws VMException { // to == null signals that this is contract creation. AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertTrue(tx.isContractCreationTransaction()); @@ -237,7 +254,13 @@ public void testTransferValueToNonPayableConstructor() throws IOException, VMExc // to == null signals that this is contract creation. AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertTrue(tx.isContractCreationTransaction()); @@ -276,7 +299,13 @@ public void testTransferValueToPayableConstructor() throws IOException, VMExcept // to == null signals that this is contract creation. AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertTrue(tx.isContractCreationTransaction()); @@ -311,7 +340,13 @@ public void testTransferValueToPayableConstructorInsufficientFunds() // to == null signals that this is contract creation. AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertTrue(tx.isContractCreationTransaction()); @@ -350,7 +385,13 @@ public void testConstructorIsCalledOnCodeDeployment() throws IOException, VMExce AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); @@ -366,7 +407,8 @@ public void testConstructorIsCalledOnCodeDeployment() throws IOException, VMExce BigInteger.ZERO.toByteArray(), Hex.decode(getMsgFunctionHash), nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -391,7 +433,13 @@ public void testCallFunction() throws IOException, VMException { BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address contract = @@ -408,7 +456,8 @@ public void testCallFunction() throws IOException, VMException { BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -435,7 +484,8 @@ public void testCallFunction() throws IOException, VMException { BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -462,7 +512,13 @@ public void testOverWithdrawFromContract() throws IOException, VMException { BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address contract = @@ -481,7 +537,8 @@ public void testOverWithdrawFromContract() throws IOException, VMException { BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -509,7 +566,13 @@ public void testWithdrawFromContract() throws IOException, VMException { BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address contract = @@ -526,7 +589,8 @@ public void testWithdrawFromContract() throws IOException, VMException { BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -553,7 +617,13 @@ public void testSendContractFundsToOtherAddress() throws IOException, VMExceptio BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address contract = @@ -575,7 +645,8 @@ public void testSendContractFundsToOtherAddress() throws IOException, VMExceptio BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -604,7 +675,13 @@ public void testSendContractFundsToNonexistentAddress() throws IOException, VMEx BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address contract = @@ -625,7 +702,8 @@ public void testSendContractFundsToNonexistentAddress() throws IOException, VMEx BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -655,7 +733,13 @@ public void testCallContractViaAnotherContract() throws IOException, VMException BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address multiFeatureContract = @@ -670,11 +754,17 @@ public void testCallContractViaAnotherContract() throws IOException, VMException value = BigInteger.ZERO; tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); nonce = nonce.add(BigInteger.ONE); Address callerContract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); - Address recipient = new Address(RandomUtils.nextBytes(Address.SIZE)); + Address recipient = Address.wrap(RandomUtils.nextBytes(Address.SIZE)); deployerBalance = repo.getBalance(deployer); deployerNonce = repo.getNonce(deployer); @@ -687,7 +777,8 @@ public void testCallContractViaAnotherContract() throws IOException, VMException BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.DEFAULT); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -719,7 +810,8 @@ public void testCallContractViaAnotherContract() throws IOException, VMException BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.DEFAULT); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -745,7 +837,13 @@ public void testRecursiveStackoverflow() throws IOException, VMException { BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); RepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); Address contract = @@ -765,7 +863,8 @@ public void testRecursiveStackoverflow() throws IOException, VMException { BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.DEFAULT); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -797,7 +896,8 @@ public void testRecursiveStackoverflow() throws IOException, VMException { BigInteger.ZERO.toByteArray(), input, nrg, - nrgPrice); + nrgPrice, + TransactionTypes.DEFAULT); tx.sign(deployerKey); assertFalse(tx.isContractCreationTransaction()); @@ -870,7 +970,13 @@ public void testRedeployContractAtExistentContractAddress() throws IOException, BigInteger nonce = BigInteger.ZERO; AionTransaction tx = new AionTransaction( - nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); + nonce.toByteArray(), + null, + value.toByteArray(), + deployCode, + nrg, + nrgPrice, + TransactionTypes.FVM_CREATE_CODE); // Mock up the repo so that the contract address already exists. AionRepositoryCache repo = mock(AionRepositoryCache.class); @@ -1134,7 +1240,14 @@ private BulkExecutor getNewExecutor( AionTransaction tx, IAionBlock block, RepositoryCache repo) { ExecutionBatch details = new ExecutionBatch(block, Collections.singletonList(tx)); return new BulkExecutor( - details, repo, false, true, block.getNrgLimit(), LOGGER_VM, getPostExecutionWork()); + details, + repo, + false, + true, + block.getNrgLimit(), + true, + LOGGER_VM, + getPostExecutionWork()); } private PostExecutionWork getPostExecutionWork() { diff --git a/modMcf/src/org/aion/mcf/valid/TransactionTypeRule.java b/modMcf/src/org/aion/mcf/valid/TransactionTypeRule.java index fad23f8d20..d2e1e79ae3 100644 --- a/modMcf/src/org/aion/mcf/valid/TransactionTypeRule.java +++ b/modMcf/src/org/aion/mcf/valid/TransactionTypeRule.java @@ -32,28 +32,17 @@ public static boolean isValidTransactionType(byte type) { * @param type the type of a transaction applicable on the FastVM * @return {@code true} is this is an FastVM transaction, {@code false} otherwise */ - public static boolean isValidFVMTransaction(byte type) { + public static boolean isValidFVMCode(byte type) { return FVM.contains(type); } - /** - * Checks if the given transaction is a valid contract deployment on the FastVM. - * - * @param type the type of a contract creation transaction - * @return {@code true} is this is a valid FastVM contract deployment, {@code false} otherwise - */ - public static boolean isValidFVMContractDeployment(byte type) { - return !AVM_CONTRACT_TRANSACTION_ALLOWED - || type == FVM_CREATE_CODE; // anything is valid here before the fork - } - /** * Compares the given transaction type with all the transaction types allowed by the AVM. * * @param type the type of a transaction applicable on the AVM * @return {@code true} is this is an AVM transaction, {@code false} otherwise */ - public static boolean isValidAVMTransaction(byte type) { + public static boolean isValidAVMCode(byte type) { return AVM.contains(type); } diff --git a/modMcf/src/org/aion/mcf/vm/types/KernelInterfaceForFastVM.java b/modMcf/src/org/aion/mcf/vm/types/KernelInterfaceForFastVM.java index 90fff3f822..9f9a816b19 100644 --- a/modMcf/src/org/aion/mcf/vm/types/KernelInterfaceForFastVM.java +++ b/modMcf/src/org/aion/mcf/vm/types/KernelInterfaceForFastVM.java @@ -233,7 +233,7 @@ public boolean isValidEnergyLimitForNonCreate(long energyLimit) { @Override public boolean destinationAddressIsSafeForThisVM(Address address) { - return TransactionTypeRule.isValidFVMContractDeployment(getVmType(address)); + return TransactionTypeRule.isValidFVMCode(getVmType(address)); } private byte getVmType(Address destination) { diff --git a/modVM/src/org/aion/vm/KernelInterfaceForAVM.java b/modVM/src/org/aion/vm/KernelInterfaceForAVM.java index b6a490a95e..9939076b09 100644 --- a/modVM/src/org/aion/vm/KernelInterfaceForAVM.java +++ b/modVM/src/org/aion/vm/KernelInterfaceForAVM.java @@ -215,7 +215,7 @@ public boolean destinationAddressIsSafeForThisVM(Address address) { } // Otherwise, it must be an Avm contract address. - return TransactionTypeRule.isValidAVMContractDeployment(getVmType(address)); + return TransactionTypeRule.isValidAVMCode(getVmType(address)); } private byte getVmType(Address destination) {