use of org.ethereum.vm.PrecompiledContracts in project rskj by rsksmart.
the class PrecompiledContractAddressTests method checkAddr.
void checkAddr(PrecompiledContracts pcList, String addr, String className) {
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
// Enabling necessary RSKIPs for every precompiled contract to be available
when(activations.isActive(ConsensusRule.RSKIP106)).thenReturn(true);
when(activations.isActive(ConsensusRule.RSKIP119)).thenReturn(true);
RskAddress a;
a = new RskAddress(addr);
PrecompiledContracts.PrecompiledContract pc = pcList.getContractForAddress(activations, DataWord.valueOf(a.getBytes()));
Assert.assertEquals(className, pc.getClass().getSimpleName());
}
use of org.ethereum.vm.PrecompiledContracts in project rskj by rsksmart.
the class VMPerformanceTest method testVMPerformance1.
private void testVMPerformance1(ResultLogger resultLogger) {
maxLLSize = 1000 * 1000 * 10;
createLarseSetOfMemoryObjects();
thread = ManagementFactory.getThreadMXBean();
if (!thread.isThreadCpuTimeSupported())
return;
Boolean old = thread.isThreadCpuTimeEnabled();
thread.setThreadCpuTimeEnabled(true);
vm = new VM(config.getVmConfig(), new PrecompiledContracts(config, null));
if (useProfiler)
waitForProfiler();
System.out.println("Configuration: shortArg = " + shortArg.toString());
// Program
// push "A0", pop it
measureProgram("PUSH/POP", Hex.decode("60A0" + "50"), 2, 2, 0, 100, null);
// measureOpcode(OpCode.NOT, false, 0); // For reference, to see general overhead
// measureOpcode(OpCode.NOT, false,0); // Re-measure to see if JIT does something
measure11Opcodes(resultLogger);
measure21Opcodes(resultLogger);
measure31Opcodes(resultLogger);
thread.setThreadCpuTimeEnabled(old);
}
use of org.ethereum.vm.PrecompiledContracts in project rskj by rsksmart.
the class VMPerformanceTest method testFibonacciLongTime.
//
@Ignore
@Test
public void testFibonacciLongTime() {
/**
******************************************************************************************
* This is the Solidity contract that was compiled:
*
* contract Fibonacci50Times {
* function() {
* uint256 a;
* uint256 b;
* uint256 c;
* for (uint k = 0; k < 1000; k++) { // The maximum value of k was varied
* a=0;
* b=1;
* for (uint i = 1; i < 50; i++) {
* c = a+b;
* a = b;
* b = c;
* }
* }
* assembly {
* mstore(0x0, b)
* return(0x0, 32)
* }
* }
* } // contract
*******************************************************************************************
*/
vm = new VM(config.getVmConfig(), new PrecompiledContracts(config, null));
// ///////////////////////////////////////////////////////////////////////////////////////////////
// To increase precesion of the measurement, the maximum k value was increased
// until the contract took more than 30 seconds
// max k=100
// byte[] codePlusPrefix = Hex.decode("6060604052607e8060106000396000f360606040523615600d57600d565b607c5b60006000600060006000600091505b6064821015606b57600094508450600193508350600190505b6032811015605e5783850192508250839450845082935083505b80806001019150506038565b5b8180600101925050601f565b8360005260206000f35b5050505050565b00");
// max k=1000
// byte[] codePlusPrefix = Hex.decode("6060604052607f8060106000396000f360606040523615600d57600d565b607d5b60006000600060006000600091505b6103e8821015606c57600094508450600193508350600190505b6032811015605f5783850192508250839450845082935083505b80806001019150506039565b5b8180600101925050601f565b8360005260206000f35b5050505050565b00");
// max k=10K
// byte[] codePlusPrefix = Hex.decode("6060604052607f8060106000396000f360606040523615600d57600d565b607d5b60006000600060006000600091505b612710821015606c57600094508450600193508350600190505b6032811015605f5783850192508250839450845082935083505b80806001019150506039565b5b8180600101925050601f565b8360005260206000f35b5050505050565b00");
// max k=100K
// ///////////////////////////////////////////////////////////////////////////////////////////////
byte[] codePlusPrefix = Hex.decode("606060405260808060106000396000f360606040523615600d57600d565b607e5b60006000600060006000600091505b620186a0821015606d57600094508450600193508350600190505b603281101560605783850192508250839450845082935083505b8080600101915050603a565b5b8180600101925050601f565b8360005260206000f35b5050505050565b00");
byte[] code = Arrays.copyOfRange(codePlusPrefix, 16, codePlusPrefix.length);
// vm.computeGas = false;
// 50
String s_expected = "00000000000000000000000000000000000000000000000000000002EE333961";
System.out.println("Creating a large set of linked memory objects to force GC...");
// 10 million linked objects.
maxLLSize = 10 * 1000 * 1000;
createLarseSetOfMemoryObjects();
System.out.println("done.");
testRunTime(code, s_expected);
}
use of org.ethereum.vm.PrecompiledContracts in project rskj by rsksmart.
the class NestedContractsTest method buildEthModule.
private EthModule buildEthModule(World world) {
final TestSystemProperties config = new TestSystemProperties();
TransactionExecutorFactory executor = new TransactionExecutorFactory(config, world.getBlockStore(), null, null, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, world.getBridgeSupportFactory()), null);
return new EthModule(null, Constants.REGTEST_CHAIN_ID, world.getBlockChain(), world.getTransactionPool(), new ReversibleTransactionExecutor(world.getRepositoryLocator(), executor), new ExecutionBlockRetriever(null, world.getBlockChain(), null, null), world.getRepositoryLocator(), null, null, world.getBridgeSupportFactory(), config.getGasEstimationCap());
}
use of org.ethereum.vm.PrecompiledContracts in project rskj by rsksmart.
the class CallContractTest method callContract.
private static ProgramResult callContract(World world, RskAddress receiveAddress, byte[] data) {
Transaction tx = CallTransaction.createRawTransaction(0, 0, 100000000000000L, receiveAddress, 0, data, config.getNetworkConstants().getChainId());
tx.sign(new byte[] {});
Block bestBlock = world.getBlockChain().getBestBlock();
Repository repository = world.getRepositoryLocator().startTrackingAt(world.getBlockChain().getBestBlock().getHeader());
BtcBlockStoreWithCache.Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
try {
TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, null, null, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), world.getBlockTxSignatureCache());
org.ethereum.core.TransactionExecutor executor = transactionExecutorFactory.newInstance(tx, 0, bestBlock.getCoinbase(), repository, bestBlock, 0).setLocalCall(true);
executor.executeTransaction();
return executor.getResult();
} finally {
repository.rollback();
}
}
Aggregations