use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class StatefulnessTest method deployContract.
private AionTxReceipt deployContract(AvmVersion version) {
byte[] jar = getJarBytes(version);
AionTransaction transaction = AionTransaction.create(deployerKey, getNonce(this.deployer).toByteArray(), null, new byte[0], jar, 5_000_000, this.energyPrice, txType, null);
return sendTransactions(transaction);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class FvmBulkTransactionTest method getDeployedTickerCountValue.
private int getDeployedTickerCountValue(ECKey sender, BigInteger nonce, AionAddress contract) {
// This hash will call the 'getTicker' function of the deployed contract (giving us the
// count).
byte[] callBytes = Hex.decode("c0004213");
AionTransaction transaction = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, new byte[0], callBytes, 2_000_000, this.energyPrice, TransactionTypes.DEFAULT, null);
AionBlockSummary summary = sendTransactionsInBulkInSingleBlock(Collections.singletonList(transaction));
return new DataWord(summary.getReceipts().get(0).getTransactionOutput()).intValue();
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class FvmExploitsTest method testModifer.
@Ignore
@Test
public void testModifer() throws InterruptedException {
String testerByteCode = "0x605060405234156100105760006000fd5b5b3360006000508282909180600101839055555050505b61002c565b61016e8061003b6000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680630acf8c2e14610049578063421b2d8b14610073578063e61a60bb1461009f57610043565b60006000fd5b34156100555760006000fd5b61005d6100c9565b6040518082815260100191505060405180910390f35b341561007f5760006000fd5b61009d600480808060100135903590916020019091929050506100d7565b005b34156100ab5760006000fd5b6100b3610113565b6040518082815260100191505060405180910390f35b6000600a90506100d4565b90565b600060005080600101549054339091149190141615156100f75760006000fd5b818160026000508282909180600101839055555050505b5b5050565b6000600260005080600101549054339091149190141615156101355760006000fd5b600b905061013e565b5b905600a165627a7a723058201d8c8bf193120213679831363ac65fecb0dcb5be8b65e6c0a1c97f4a7d3d3ef20029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
// =======================================================================
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(testerByteCode), 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
assertThat(tx.isContractCreationTransaction()).isTrue();
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(tx), false);
ImportResult result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
Thread.sleep(1000L);
// =======================================================================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx2 = AionTransaction.create(deployerAccount, nonce.toByteArray(), contractAddress, new byte[0], // getEleven()
ByteUtil.hexStringToBytes("0xe61a60bb"), 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
BlockContext context2 = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(tx2), false);
ImportResult result2 = bc.tryToConnect(context2.block);
assertThat(result2).isEqualTo(ImportResult.IMPORTED_BEST);
Thread.sleep(1000L);
// assert failure
AionTxInfo info2 = bc.getTransactionInfo(context2.block.getTransactionsList().get(0).getTransactionHash());
assertEquals("REVERT", info2.getReceipt().getError());
// =======================================================================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx3 = AionTransaction.create(deployerAccount, nonce.toByteArray(), contractAddress, new byte[0], ByteUtil.hexStringToBytes("0x421b2d8b" + Hex.toHexString(// addUser(address)
deployerAccount.getAddress())), 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
BlockContext context3 = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(tx3), false);
ImportResult result3 = bc.tryToConnect(context3.block);
assertThat(result3).isEqualTo(ImportResult.IMPORTED_BEST);
Thread.sleep(1000L);
// assert failure
AionTxInfo info3 = bc.getTransactionInfo(context3.block.getTransactionsList().get(0).getTransactionHash());
assertEquals("", info3.getReceipt().getError());
Thread.sleep(1000L);
// =======================================================================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx4 = AionTransaction.create(deployerAccount, nonce.toByteArray(), contractAddress, new byte[0], // getEleven()
ByteUtil.hexStringToBytes("0xe61a60bb"), 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
BlockContext context4 = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(tx4), false);
ImportResult result4 = bc.tryToConnect(context4.block);
assertThat(result4).isEqualTo(ImportResult.IMPORTED_BEST);
Thread.sleep(1000L);
// assert failure
AionTxInfo info4 = bc.getTransactionInfo(context4.block.getTransactionsList().get(0).getTransactionHash());
assertEquals("", info4.getReceipt().getError());
assertEquals(11, FvmDataWord.fromBytes(info4.getReceipt().getTransactionOutput()).toInt());
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class FvmExploitsTest method testBlockCreationExploit.
@Test
public void testBlockCreationExploit() throws InterruptedException {
String testerByteCode = "0x605060405234156100105760006000fd5b5b3360006000508282909180600101839055555050505b61002c565b6103828061003b6000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680634f2be91f14610049578063b4b65ae01461005f578063cd909c75146100cb57610043565b60006000fd5b34156100555760006000fd5b61005d6100e1565b005b341561006b5760006000fd5b6100736100e7565b6040518080601001828103825283818151815260100191508051906010019060200280838360005b838110156100b75780820151818401525b60108101905061009b565b505050509050019250505060405180910390f35b34156100d75760006000fd5b6100df61015d565b005b6002505b565b6100ef6101cf565b600260005080548060200260100160405190810160405280929190818152601001828054801561014e576020028201919060005260106000209050905b816000508060010154905482528160100152602001906002019080831161012c575b5050505050905061015a565b90565b600060006101696101e6565b604051809103906000f08015821516156101835760006000fd5b915091506002600050805480600101828161019e91906101f5565b91909060005260106000209050906002020160005b84849091929091925091909091806001018390555550505b5050565b601060405190810160405280600081526010015090565b60405160fa8061025d83390190565b8154818355818115116102245760020281600202836000526010600020905091820191016102239190610229565b5b505050565b6102599190610233565b8082111561025557600081815080600090556001016000905550600201610233565b5090565b905600605060405234156100105760006000fd5b5b4260006000508190909055507fd4fc977b8ac41e3fa318bb6650de6044046ea9e8cda72be27b6b0c458726c1666000600050546040518082815260100191505060405180910390a15b61005f565b608d8061006d6000396000f30060506040526000356c01000000000000000000000000900463ffffffff16806316ada54714603157602b565b60006000fd5b3415603c5760006000fd5b60426058565b6040518082815260100191505060405180910390f35b600060005054815600a165627a7a723058206919d683bc89f37f2bf6a52877fe0997e5d9b83057967fa1fd4a420b5da707b20029a165627a7a723058202d4cb48cf45eb1f4907e249b6060d84330669ff7f27d967554eb3a20e1c1f6840029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
BigInteger nonce = BigInteger.ZERO;
/* byte[] nonce, Address to, byte[] value, byte[] data, long nrg, long nrgPrice */
AionTransaction tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(testerByteCode), 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
assertThat(tx.isContractCreationTransaction()).isTrue();
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(tx), false);
// try to connect the deployment block
ImportResult result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
System.out.println("xxx = " + bc.getRepository().getNonce(new AionAddress(deployerAccount.getAddress())));
Thread.sleep(1000L);
// try executing a makeTest() call
byte[] funcSig = ByteUtil.hexStringToBytes("0xcd909c75");
nonce = nonce.add(BigInteger.ONE);
AionTransaction makeTestCallTx = AionTransaction.create(deployerAccount, nonce.toByteArray(), contractAddress, new byte[0], funcSig, 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
BlockContext context2 = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(makeTestCallTx), false);
ImportResult result2 = bc.tryToConnect(context2.block);
assertThat(result2).isEqualTo(ImportResult.IMPORTED_BEST);
System.out.println("xxx = " + bc.getRepository().getNonce(new AionAddress(deployerAccount.getAddress())));
System.out.println("yyy = " + bc.getRepository().getNonce(contractAddress));
Thread.sleep(1000L);
// try executing another makeTest() call
funcSig = ByteUtil.hexStringToBytes("0xcd909c75");
nonce = nonce.add(BigInteger.ONE);
AionTransaction anotherMakeTestCall = AionTransaction.create(deployerAccount, nonce.toByteArray(), contractAddress, new byte[0], funcSig, 1_000_000L, energyPrice, TransactionTypes.DEFAULT, null);
BlockContext context3 = bc.createNewMiningBlockContext(bc.getBestBlock(), Collections.singletonList(anotherMakeTestCall), false);
ImportResult result3 = bc.tryToConnect(context3.block);
assertThat(result3).isEqualTo(ImportResult.IMPORTED_BEST);
System.out.println("xxx = " + bc.getRepository().getNonce(new AionAddress(deployerAccount.getAddress())));
System.out.println("yyy = " + bc.getRepository().getNonce(contractAddress));
assertEquals(BigInteger.valueOf(3), bc.getRepository().getNonce(new AionAddress(deployerAccount.getAddress())));
assertEquals(BigInteger.valueOf(2), bc.getRepository().getNonce(contractAddress));
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class InternalTransactionTest method testNestedCreateWithExistedAccount.
@Test
public void testNestedCreateWithExistedAccount() throws Exception {
String contractA = "0x60506040523415600f5760006000fd5b5b60166048565b604051809103906000f0801582151615602f5760006000fd5b60006000508282909180600101839055555050505b6057565b604051605a8061009f83390190565b603a806100656000396000f30060506040526008565b60006000fd00a165627a7a72305820c0eea40d4778b01848164e58898e9e8c8ab068ed5ee36ed6f0582d119ecbbede002960506040523415600f5760006000fd5b6013565b603a8060206000396000f30060506040526008565b60006000fd00a165627a7a723058208c13bc92baf844f8574632dca44c49776516cb6cd537b10ed700bf61392b6ae80029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
AionAddress firstContractAddr = TxUtil.calculateContractAddress(deployerAccount.getAddress(), BigInteger.ONE);
AionAddress internalContractAddress = TxUtil.calculateContractAddress(firstContractAddr.toByteArray(), BigInteger.ZERO);
BigInteger nonce = BigInteger.ZERO;
// ======================
// Transfer balance to the internal contract address
// ======================
AionTransaction tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), internalContractAddress, BigInteger.ONE.toByteArray(), new byte[0], 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
Block parentBlock = bc.getBestBlock();
MiningBlock newBlock = bc.createBlock(parentBlock, Collections.singletonList(tx), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> result = bc.tryToConnectAndFetchSummary(newBlock);
assertTrue(result.getLeft().isSuccessful());
nonce = nonce.add(BigInteger.ONE);
bc.forkUtility.enable040Fork(1000);
// ======================
// DEPLOY Failed
// ======================
tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
parentBlock = bc.getBestBlock();
newBlock = bc.createBlock(parentBlock, Collections.singletonList(tx), false, parentBlock.getTimestamp());
result = bc.tryToConnectAndFetchSummary(newBlock);
assertTrue(result.getLeft().isSuccessful());
assertEquals("reverted", result.getRight().getReceipts().get(0).getError());
nonce = nonce.add(BigInteger.ONE);
bc.forkUtility.enable040Fork(0);
// ======================
// DEPLOY
// ======================
tx = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
System.out.println("contractaddr: " + TxUtil.calculateContractAddress(tx));
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx), false);
AionTxExecSummary summary = executeTransaction(bc, context, tx);
System.out.println(summary.getReceipt());
boolean firstItx = true;
for (InternalTransaction itx : summary.getInternalTransactions()) {
System.out.println(itx);
if (firstItx) {
AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
assertNotNull(contractAddress);
assertTrue(bc.getRepository().hasAccountState(contractAddress));
assertTrue(bc.getRepository().hasAccountState(TxUtil.calculateContractAddress(contractAddress.toByteArray(), BigInteger.ZERO)));
firstItx = false;
}
}
}
Aggregations