Search in sources :

Example 36 with LockWhitelist

use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.

the class BridgeSupportTestPowerMock method removeLockWhitelistAddress_notAuthorized.

@Test
public void removeLockWhitelistAddress_notAuthorized() {
    Transaction mockedTx = mock(Transaction.class);
    byte[] senderBytes = Hex.decode("0000000000000000000000000000000000aabbcc");
    RskAddress sender = new RskAddress(senderBytes);
    when(mockedTx.getSender()).thenReturn(sender);
    LockWhitelist mockedWhitelist = mock(LockWhitelist.class);
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksForWhitelistTests(mockedWhitelist);
    Assert.assertEquals(BridgeSupport.LOCK_WHITELIST_GENERIC_ERROR_CODE.intValue(), bridgeSupport.removeLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN").intValue());
    verify(mockedWhitelist, never()).remove(any());
}
Also used : LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) InternalTransaction(org.ethereum.vm.program.InternalTransaction) RskAddress(co.rsk.core.RskAddress) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with LockWhitelist

use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.

the class BridgeSupportTestPowerMock method setLockWhitelistDisableBlockDelay_disableBlockDelayBIBiggerThanInt.

@Test(expected = ArithmeticException.class)
public void setLockWhitelistDisableBlockDelay_disableBlockDelayBIBiggerThanInt() throws IOException, BlockStoreException {
    Transaction mockedTx = mock(Transaction.class);
    byte[] senderBytes = ECKey.fromPublicOnly(Hex.decode(// Public key hex of the authorized whitelist admin in regtest, taken from BridgeRegTestConstants
    "04641fb250d7ca7a1cb4f530588e978013038ec4294d084d248869dd54d98873e45c61d00ceeaeeb9e35eab19fa5fbd8f07cb8a5f0ddba26b4d4b18349c09199ad")).getAddress();
    RskAddress sender = new RskAddress(senderBytes);
    when(mockedTx.getSender()).thenReturn(sender);
    LockWhitelist mockedWhitelist = mock(LockWhitelist.class);
    when(mockedWhitelist.isDisableBlockSet()).thenReturn(false);
    int bestChainHeight = 10;
    BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
    StoredBlock storedBlock = mock(StoredBlock.class);
    when(storedBlock.getHeight()).thenReturn(bestChainHeight);
    when(btcBlockStore.getChainHead()).thenReturn(storedBlock);
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksAndBtcBlockstoreForWhitelistTests(mockedWhitelist, btcBlockStore);
    // Duplicate Int Max Value by 2 because its signed and add 1 to pass the limit
    BigInteger disableBlockDelayBI = BigInteger.valueOf((long) Integer.MAX_VALUE * 2 + 1);
    bridgeSupport.setLockWhitelistDisableBlockDelay(mockedTx, disableBlockDelayBI);
    verify(mockedWhitelist, never()).put(any(), any());
}
Also used : LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) InternalTransaction(org.ethereum.vm.program.InternalTransaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with LockWhitelist

use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.

the class BridgeSupportTestPowerMock method addLockWhitelistAddress_notAuthorized.

@Test
public void addLockWhitelistAddress_notAuthorized() {
    Transaction mockedTx = mock(Transaction.class);
    byte[] senderBytes = Hex.decode("0000000000000000000000000000000000aabbcc");
    RskAddress sender = new RskAddress(senderBytes);
    when(mockedTx.getSender()).thenReturn(sender);
    LockWhitelist mockedWhitelist = mock(LockWhitelist.class);
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksForWhitelistTests(mockedWhitelist);
    Assert.assertEquals(BridgeSupport.LOCK_WHITELIST_GENERIC_ERROR_CODE.intValue(), bridgeSupport.addOneOffLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", BigInteger.valueOf(Coin.COIN.getValue())).intValue());
    verify(mockedWhitelist, never()).put(any(), any());
}
Also used : LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) InternalTransaction(org.ethereum.vm.program.InternalTransaction) RskAddress(co.rsk.core.RskAddress) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with LockWhitelist

use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.

the class BridgeSupportTestPowerMock method setLockWhitelistDisableBlockDelay_negativeDisableBlockBI.

@Test
public void setLockWhitelistDisableBlockDelay_negativeDisableBlockBI() throws IOException, BlockStoreException {
    Transaction mockedTx = mock(Transaction.class);
    byte[] senderBytes = ECKey.fromPublicOnly(Hex.decode(// Public key hex of the authorized whitelist admin in regtest, taken from BridgeRegTestConstants
    "04641fb250d7ca7a1cb4f530588e978013038ec4294d084d248869dd54d98873e45c61d00ceeaeeb9e35eab19fa5fbd8f07cb8a5f0ddba26b4d4b18349c09199ad")).getAddress();
    RskAddress sender = new RskAddress(senderBytes);
    when(mockedTx.getSender()).thenReturn(sender);
    LockWhitelist mockedWhitelist = mock(LockWhitelist.class);
    when(mockedWhitelist.isDisableBlockSet()).thenReturn(false);
    int bestChainHeight = 10;
    BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
    StoredBlock storedBlock = mock(StoredBlock.class);
    when(storedBlock.getHeight()).thenReturn(bestChainHeight);
    when(btcBlockStore.getChainHead()).thenReturn(storedBlock);
    BtcBlock btcBlock = mock(BtcBlock.class);
    doReturn(Sha256Hash.of(Hex.decode("aa"))).when(btcBlock).getHash();
    doReturn(btcBlock).when(storedBlock).getHeader();
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksAndBtcBlockstoreForWhitelistTests(mockedWhitelist, btcBlockStore);
    BigInteger disableBlockDelayBI = BigInteger.valueOf(-2);
    Assert.assertEquals(-2, bridgeSupport.setLockWhitelistDisableBlockDelay(mockedTx, disableBlockDelayBI).intValue());
    verify(mockedWhitelist, never()).put(any(), any());
}
Also used : LockWhitelist(co.rsk.peg.whitelist.LockWhitelist) InternalTransaction(org.ethereum.vm.program.InternalTransaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with LockWhitelist

use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.

the class BridgeSupport method verifyLockSenderIsWhitelisted.

private boolean verifyLockSenderIsWhitelisted(Address senderBtcAddress, Coin totalAmount, int height) {
    // If the address is not whitelisted, then return the funds
    // using the exact same utxos sent to us.
    // That is, build a release transaction and get it in the release transaction set.
    // Otherwise, transfer SBTC to the sender of the BTC
    // The RSK account to update is the one that matches the pubkey "spent" on the first bitcoin tx input
    LockWhitelist lockWhitelist = provider.getLockWhitelist();
    if (!lockWhitelist.isWhitelistedFor(senderBtcAddress, totalAmount, height)) {
        logger.info("Rejecting lock. Address {} is not whitelisted.", senderBtcAddress);
        return false;
    }
    // Consume this whitelisted address
    lockWhitelist.consume(senderBtcAddress);
    return true;
}
Also used : LockWhitelist(co.rsk.peg.whitelist.LockWhitelist)

Aggregations

LockWhitelist (co.rsk.peg.whitelist.LockWhitelist)41 RskAddress (co.rsk.core.RskAddress)38 Test (org.junit.Test)36 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)34 InternalTransaction (org.ethereum.vm.program.InternalTransaction)33 MutableRepository (org.ethereum.db.MutableRepository)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)19 Repository (org.ethereum.core.Repository)19 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)18 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)17 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)16 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)16 OneOffWhiteListEntry (co.rsk.peg.whitelist.OneOffWhiteListEntry)16 Block (org.ethereum.core.Block)16 Transaction (org.ethereum.core.Transaction)16 BigInteger (java.math.BigInteger)15 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)9 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)9 ECKey (org.ethereum.crypto.ECKey)9