Search in sources :

Example 26 with VMException

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

the class Bridge method getFederatorPublicKeyOfType.

public byte[] getFederatorPublicKeyOfType(Object[] args) throws VMException {
    logger.trace("getFederatorPublicKeyOfType");
    int index = ((BigInteger) args[0]).intValue();
    FederationMember.KeyType keyType;
    try {
        keyType = FederationMember.KeyType.byValue((String) args[1]);
    } catch (Exception e) {
        logger.warn("Exception in getFederatorPublicKeyOfType", e);
        throw new VMException("Exception in getFederatorPublicKeyOfType", e);
    }
    return bridgeSupport.getFederatorPublicKeyOfType(index, keyType);
}
Also used : VMException(org.ethereum.vm.exception.VMException) BigInteger(java.math.BigInteger) VMException(org.ethereum.vm.exception.VMException) IOException(java.io.IOException) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException)

Example 27 with VMException

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

the class Bridge method receiveHeaders.

public void receiveHeaders(Object[] args) throws VMException {
    logger.trace("receiveHeaders");
    Object[] btcBlockSerializedArray = (Object[]) args[0];
    // a simple size check. If this check fails, just fail.
    if (Arrays.stream(btcBlockSerializedArray).anyMatch(bytes -> !BtcTransactionFormatUtils.isBlockHeaderSize(((byte[]) bytes).length, activations))) {
        // This exception type bypasses bridge teardown, signalling no work done
        // and preventing the overhead of saving bridge storage
        logger.warn("Unexpected BTC header(s) received (size mismatch). Aborting processing.");
        throw new BridgeIllegalArgumentException("Unexpected BTC header(s) received (size mismatch). Aborting processing.");
    }
    BtcBlock[] btcBlockArray = new BtcBlock[btcBlockSerializedArray.length];
    for (int i = 0; i < btcBlockSerializedArray.length; i++) {
        byte[] btcBlockSerialized = (byte[]) btcBlockSerializedArray[i];
        try {
            BtcBlock header = bridgeConstants.getBtcParams().getDefaultSerializer().makeBlock(btcBlockSerialized);
            btcBlockArray[i] = header;
        } catch (ProtocolException e) {
            throw new BridgeIllegalArgumentException("Block " + i + " could not be parsed " + ByteUtil.toHexString(btcBlockSerialized), e);
        }
    }
    try {
        bridgeSupport.receiveHeaders(btcBlockArray);
    } catch (Exception e) {
        logger.warn("Exception adding header", e);
        throw new VMException("Exception adding header", 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 28 with VMException

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

the class Bridge method getBtcTransactionConfirmations.

public int getBtcTransactionConfirmations(Object[] args) throws VMException {
    logger.trace("getBtcTransactionConfirmations");
    try {
        Sha256Hash btcTxHash = Sha256Hash.wrap((byte[]) args[0]);
        Sha256Hash btcBlockHash = Sha256Hash.wrap((byte[]) args[1]);
        int merkleBranchPath = ((BigInteger) args[2]).intValue();
        Object[] merkleBranchHashesArray = (Object[]) args[3];
        List<Sha256Hash> merkleBranchHashes = Arrays.stream(merkleBranchHashesArray).map(hash -> Sha256Hash.wrap((byte[]) hash)).collect(Collectors.toList());
        MerkleBranch merkleBranch = new MerkleBranch(merkleBranchHashes, merkleBranchPath);
        return bridgeSupport.getBtcTransactionConfirmations(btcTxHash, btcBlockHash, merkleBranch);
    } catch (Exception e) {
        logger.warn("Exception in getBtcTransactionConfirmations", e);
        throw new VMException("Exception in getBtcTransactionConfirmations", e);
    }
}
Also used : OneOffWhiteListEntry(co.rsk.peg.whitelist.OneOffWhiteListEntry) VMException(org.ethereum.vm.exception.VMException) Arrays(java.util.Arrays) LockWhitelistEntry(co.rsk.peg.whitelist.LockWhitelistEntry) LoggerFactory(org.slf4j.LoggerFactory) CallTransaction(org.ethereum.core.CallTransaction) RskAddress(co.rsk.core.RskAddress) ProgramSubtrace(co.rsk.rpc.modules.trace.ProgramSubtrace) Keccak256(co.rsk.crypto.Keccak256) Block(org.ethereum.core.Block) ArrayList(java.util.ArrayList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) BridgeConstants(co.rsk.config.BridgeConstants) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BigInteger(java.math.BigInteger) MerkleBranch(co.rsk.peg.bitcoin.MerkleBranch) LogInfo(org.ethereum.vm.LogInfo) PanicProcessor(co.rsk.panic.PanicProcessor) Logger(org.slf4j.Logger) BtcTransactionFormatUtils(co.rsk.peg.utils.BtcTransactionFormatUtils) DataWord(org.ethereum.vm.DataWord) IOException(java.io.IOException) BlockStore(org.ethereum.db.BlockStore) Instant(java.time.Instant) Repository(org.ethereum.core.Repository) Collectors(java.util.stream.Collectors) ReceiptStore(org.ethereum.db.ReceiptStore) Program(org.ethereum.vm.program.Program) List(java.util.List) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) ByteUtil(org.ethereum.util.ByteUtil) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Transaction(org.ethereum.core.Transaction) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) Constants(org.ethereum.config.Constants) VMException(org.ethereum.vm.exception.VMException) BigInteger(java.math.BigInteger) MerkleBranch(co.rsk.peg.bitcoin.MerkleBranch) VMException(org.ethereum.vm.exception.VMException) IOException(java.io.IOException) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException)

Example 29 with VMException

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

the class VoteFeePerKbChangeTest method voteFeePerKbChange_unauthorized.

@Test
public void voteFeePerKbChange_unauthorized() throws VMException {
    BridgeStorageProviderInitializer storageInitializer = Helper.buildNoopInitializer();
    Coin genesisFeePerKB = BridgeRegTestConstants.getInstance().getGenesisFeePerKb();
    ABIEncoder abiEncoder = (int executionIndex) -> Bridge.VOTE_FEE_PER_KB.encode(BigInteger.valueOf(Helper.randomCoin(Coin.MILLICOIN, 1, 100).getValue()));
    TxBuilder txBuilder = (int executionIndex) -> {
        String generator = "unauthorized";
        ECKey sender = ECKey.fromPrivate(HashUtil.keccak256(generator.getBytes(StandardCharsets.UTF_8)));
        return Helper.buildTx(sender);
    };
    ExecutionStats stats = new ExecutionStats("voteFeePerKbChange_unauthorized");
    executeAndAverage("voteFeePerKbChange_unauthorized", 1000, abiEncoder, storageInitializer, txBuilder, Helper.getRandomHeightProvider(10), stats, ((environment, callResult) -> {
        Assert.assertEquals(genesisFeePerKB.getValue(), ((Bridge) environment.getContract()).getFeePerKb(null));
    }));
    BridgePerformanceTest.addStats(stats);
}
Also used : Coin(co.rsk.bitcoinj.core.Coin) VMException(org.ethereum.vm.exception.VMException) Ignore(org.junit.Ignore) HashUtil(org.ethereum.crypto.HashUtil) Test(org.junit.Test) BigInteger(java.math.BigInteger) BridgeRegTestConstants(co.rsk.config.BridgeRegTestConstants) Assert(org.junit.Assert) AtomicReference(java.util.concurrent.atomic.AtomicReference) Bridge(co.rsk.peg.Bridge) StandardCharsets(java.nio.charset.StandardCharsets) ECKey(org.ethereum.crypto.ECKey) Coin(co.rsk.bitcoinj.core.Coin) ECKey(org.ethereum.crypto.ECKey) Bridge(co.rsk.peg.Bridge) Test(org.junit.Test)

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