Search in sources :

Example 1 with VMException

use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.

the class Bridge method registerBtcTransaction.

public void registerBtcTransaction(Object[] args) throws VMException {
    logger.trace("registerBtcTransaction");
    byte[] btcTxSerialized = (byte[]) args[0];
    int height = ((BigInteger) args[1]).intValue();
    byte[] pmtSerialized = (byte[]) args[2];
    try {
        bridgeSupport.registerBtcTransaction(rskTx, btcTxSerialized, height, pmtSerialized);
    } catch (IOException | BlockStoreException e) {
        logger.warn("Exception in registerBtcTransaction", e);
        throw new VMException("Exception in registerBtcTransaction", e);
    }
}
Also used : BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) VMException(org.ethereum.vm.exception.VMException) BigInteger(java.math.BigInteger) IOException(java.io.IOException)

Example 2 with VMException

use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.

the class Bridge method addSignature.

public void addSignature(Object[] args) throws VMException {
    logger.trace("addSignature");
    byte[] federatorPublicKeySerialized = (byte[]) args[0];
    BtcECKey federatorPublicKey;
    try {
        federatorPublicKey = BtcECKey.fromPublicOnly(federatorPublicKeySerialized);
    } catch (Exception e) {
        throw new BridgeIllegalArgumentException("Public key could not be parsed " + ByteUtil.toHexString(federatorPublicKeySerialized), e);
    }
    Object[] signaturesObjectArray = (Object[]) args[1];
    if (signaturesObjectArray.length == 0) {
        throw new BridgeIllegalArgumentException("Signatures array is empty");
    }
    List<byte[]> signatures = new ArrayList<>();
    for (Object signatureObject : signaturesObjectArray) {
        byte[] signatureByteArray = (byte[]) signatureObject;
        try {
            BtcECKey.ECDSASignature.decodeFromDER((byte[]) signatureObject);
        } catch (Exception e) {
            throw new BridgeIllegalArgumentException("Signature could not be parsed " + ByteUtil.toHexString(signatureByteArray), e);
        }
        signatures.add(signatureByteArray);
    }
    byte[] rskTxHash = (byte[]) args[2];
    if (rskTxHash.length != 32) {
        throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + ByteUtil.toHexString(rskTxHash));
    }
    try {
        bridgeSupport.addSignature(federatorPublicKey, signatures, rskTxHash);
    } catch (BridgeIllegalArgumentException e) {
        throw e;
    } catch (Exception e) {
        logger.warn("Exception in addSignature", e);
        throw new VMException("Exception in addSignature", e);
    }
}
Also used : VMException(org.ethereum.vm.exception.VMException) ArrayList(java.util.ArrayList) VMException(org.ethereum.vm.exception.VMException) IOException(java.io.IOException) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException)

Example 3 with VMException

use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.

the class Bridge method getBtcBlockchainBlockLocator.

/**
 * @deprecated
 * @param args
 * @return
 */
@Deprecated
public Object[] getBtcBlockchainBlockLocator(Object[] args) throws VMException {
    logger.trace("getBtcBlockchainBlockLocator");
    try {
        List<Sha256Hash> blockLocatorList = bridgeSupport.getBtcBlockchainBlockLocator();
        Object[] blockLocatorArray = new Object[blockLocatorList.size()];
        int i = 0;
        for (Sha256Hash blockHash : blockLocatorList) {
            blockLocatorArray[i] = blockHash.toString();
            i++;
        }
        return blockLocatorArray;
    } catch (Exception e) {
        logger.warn("Exception in getBtcBlockchainBlockLocator", e);
        throw new VMException("Exception in getBtcBlockchainBlockLocator", e);
    }
}
Also used : VMException(org.ethereum.vm.exception.VMException) VMException(org.ethereum.vm.exception.VMException) IOException(java.io.IOException) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException)

Example 4 with VMException

use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.

the class Bridge method receiveHeader.

public int receiveHeader(Object[] args) throws VMException {
    logger.trace("receiveHeader");
    byte[] headerArg = (byte[]) args[0];
    if (!BtcTransactionFormatUtils.isBlockHeaderSize(headerArg.length, activations)) {
        logger.warn("Unexpected BTC header received (size mismatch). Aborting processing.");
        return RECEIVE_HEADER_ERROR_SIZE_MISTMATCH;
    }
    BtcBlock header = bridgeConstants.getBtcParams().getDefaultSerializer().makeBlock(headerArg);
    try {
        return bridgeSupport.receiveHeader(header);
    } catch (Exception e) {
        String errorMessage = "Exception adding header in receiveHeader";
        logger.warn(errorMessage, e);
        throw new VMException(errorMessage, e);
    }
}
Also used : VMException(org.ethereum.vm.exception.VMException) VMException(org.ethereum.vm.exception.VMException) IOException(java.io.IOException) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException)

Example 5 with VMException

use of org.ethereum.vm.exception.VMException in project rskj by rsksmart.

the class DeriveExtendedPublicKeyPerformanceTestCase method estimateDeriveExtendedPublicKey.

private ExecutionStats estimateDeriveExtendedPublicKey(int times, int pathLength, EnvironmentBuilder environmentBuilder) throws VMException {
    String name = String.format("%s-%d", function.name, pathLength);
    ExecutionStats stats = new ExecutionStats(name);
    Random rnd = new Random();
    byte[] chainCode = new byte[32];
    NetworkParameters networkParameters = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
    ABIEncoder abiEncoder = (int executionIndex) -> {
        rnd.nextBytes(chainCode);
        DeterministicKey key = HDKeyDerivation.createMasterPubKeyFromBytes(new ECKey().getPubKey(true), chainCode);
        int[] pathParts = new int[pathLength];
        for (int i = 0; i < pathLength; i++) {
            pathParts[i] = rnd.nextInt(MAX_CHILD);
        }
        String path = String.join("/", Arrays.stream(pathParts).mapToObj(i -> String.format("%d", i)).collect(Collectors.toList()));
        return function.encode(new Object[] { key.serializePubB58(networkParameters), path });
    };
    executeAndAverage(name, times, environmentBuilder, abiEncoder, Helper.getZeroValueTxBuilder(new ECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
        Object[] decodedResult = function.decodeResult(result);
        Assert.assertEquals(String.class, decodedResult[0].getClass());
        String address = (String) decodedResult[0];
        Assert.assertTrue(address.startsWith("xpub"));
    });
    return stats;
}
Also used : PrecompiledContractPerformanceTestCase(co.rsk.peg.performance.PrecompiledContractPerformanceTestCase) HDKeyDerivation(co.rsk.bitcoinj.crypto.HDKeyDerivation) ExecutionStats(co.rsk.peg.performance.ExecutionStats) VMException(org.ethereum.vm.exception.VMException) Arrays(java.util.Arrays) CallTransaction(org.ethereum.core.CallTransaction) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) Test(org.junit.Test) Random(java.util.Random) Collectors(java.util.stream.Collectors) CombinedExecutionStats(co.rsk.peg.performance.CombinedExecutionStats) DeterministicKey(co.rsk.bitcoinj.crypto.DeterministicKey) TestSystemProperties(co.rsk.config.TestSystemProperties) Ignore(org.junit.Ignore) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) Assert(org.junit.Assert) ECKey(org.ethereum.crypto.ECKey) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) ECKey(org.ethereum.crypto.ECKey) Random(java.util.Random) DeterministicKey(co.rsk.bitcoinj.crypto.DeterministicKey) ExecutionStats(co.rsk.peg.performance.ExecutionStats) CombinedExecutionStats(co.rsk.peg.performance.CombinedExecutionStats)

Aggregations

VMException (org.ethereum.vm.exception.VMException)29 IOException (java.io.IOException)16 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)14 Test (org.junit.Test)11 BigInteger (java.math.BigInteger)9 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 SimpleBtcTransaction (co.rsk.peg.bitcoin.SimpleBtcTransaction)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 RskAddress (co.rsk.core.RskAddress)6 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)5 Keccak256 (co.rsk.crypto.Keccak256)4 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)3 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)3 BridgeConstants (co.rsk.config.BridgeConstants)3 BridgeRegTestConstants (co.rsk.config.BridgeRegTestConstants)3 TestSystemProperties (co.rsk.config.TestSystemProperties)3 MerkleBranch (co.rsk.peg.bitcoin.MerkleBranch)3 OneOffWhiteListEntry (co.rsk.peg.whitelist.OneOffWhiteListEntry)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Instant (java.time.Instant)3