Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions/checkout…
Browse files Browse the repository at this point in the history
…-4.2.2
  • Loading branch information
fmacleal authored Jan 20, 2025
2 parents ce2f487 + 95a8f1a commit ba24c35
Show file tree
Hide file tree
Showing 121 changed files with 13,242 additions and 709 deletions.
10 changes: 5 additions & 5 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
<sha256 value="c717c468bfc91536f1dbc0d98d6116a8e7c49fbaff643ef8710e7505cc450878" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="co.rsk.bitcoinj" name="bitcoinj-thin" version="0.14.4-rsk-15">
<artifact name="bitcoinj-thin-0.14.4-rsk-15.jar">
<sha256 value="871b008d5b148f066a6e4d46b154a96532e22b7b6faff6e28821fa4e7b078346" origin="Generated by Gradle"/>
<component group="co.rsk.bitcoinj" name="bitcoinj-thin" version="0.14.4-rsk-17">
<artifact name="bitcoinj-thin-0.14.4-rsk-17.jar">
<sha256 value="beff6002e72162984daa3e7016b1a6fb6d372e5cfb14101a50d150c0adfbda71" origin="Generated by Gradle"/>
</artifact>
<artifact name="bitcoinj-thin-0.14.4-rsk-15.pom">
<sha256 value="deda61ace1b697c488c8acddbc60fcc55be75df9097c8cd2dad87f8c6afa21f2" origin="Generated by Gradle"/>
<artifact name="bitcoinj-thin-0.14.4-rsk-17.pom">
<sha256 value="32fca4aac555f60d824cda58f69e64a7641f60dbbf5ec733966dbe2ded3214d7" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.diffplug.durian" name="durian-collect" version="1.2.0">
Expand Down
21 changes: 14 additions & 7 deletions rskj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ checkstyle {
}

spotless {
enforceCheck false
java {
googleJavaFormat()
indentWithTabs(2)
Expand Down Expand Up @@ -150,6 +151,7 @@ tasks.withType(Checkstyle).configureEach { Checkstyle task ->
}
}
}
task.dependsOn processResources
}

configurations {
Expand Down Expand Up @@ -271,7 +273,7 @@ ext {
jaxwsRtVer : '2.3.5',
picocliVer : '4.6.3',

bitcoinjThinVer: '0.14.4-rsk-16-SNAPSHOT',
bitcoinjThinVer: '0.14.4-rsk-17',
rskjNativeVer: '1.3.0',
]

Expand Down Expand Up @@ -565,9 +567,14 @@ static def amendPathIfNeeded(details) {
}
}

tasks.named('check').configure {
dependsOn 'checkstyleMain'
dependsOn 'checkstyleTest'
dependsOn 'checkstyleJmh'
dependsOn 'checkstyleIntegrationTest'
}
task checkstyleAll {
group = 'Verification'
description = 'Run all Checkstyle checks'
dependsOn 'checkstyleMain', 'checkstyleTest', 'checkstyleJmh', 'checkstyleIntegrationTest'
}

task spotlessAll {
group = 'Verification'
description = 'Run all Spotless checks'
dependsOn 'spotlessJavaCheck'
}
6 changes: 3 additions & 3 deletions rskj-core/src/jmh/resources/conf/testnet-3_860_000.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ sendRawTransaction.tx=0xf868826d28840387ee40825208947986b3df570230288501eea3d890
############################
# estimateGas
############################
estimateGas.from=0x05EEEF8B42D583880A24d74853669ee4a36bB530
estimateGas.to=0x51B631722323189ee8d3e4E558eC399d7aa40FcC
estimateGas.data=0xcbf83a0400000000000000000000000000000000000000000000000000000000000000034254435553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000409c969dacf4b38000000000000000000000000000005eeef8b42d583880a24d74853669ee4a36bb53000000000000000000000000000000000000000000000000000000000003567dd0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000038e9c434a2b164e2c07758f0b30af4cf4b5ad0dc98e8f13413b8beb36124574b82c84681feac9d982591f4701ba33e2949d1ae0df7363ac90d99d5c16f91a9f0c6c1131f84944ae1dd2bba3bbcf3e592a838286bbcf816247939548ee33ec23e200000000000000000000000000000000000000000000000000000000000000034821d173b4098826fb4d5a42dbfd4582de9ff98efabecb5596ac088ec387e9c765a5d167455ef2de2636857fde728c153e94e6406779063f6d95f76a85a07ef33a0ab20a151a912a49838ad9262524986595531bc0680a502ca04fe736414775
estimateGas.from=0x824dB056754BE52602CF9a2Ea1b8082Dad4dc89C
estimateGas.to=0xB913c7494b918Ed637D4df1308E1B7FF820b75B6
estimateGas.data=0x5a686699000000000000000000000000000000000000000000000000f438a7c30553000000000000000000000000000000000000000000000000000000000000645fa03b0000000000000000000000006951020041bfa2565877bf0eaf7f5df039b490dc

############################
# debug
Expand Down
21 changes: 13 additions & 8 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
import co.rsk.rpc.*;
import co.rsk.rpc.modules.debug.DebugModule;
import co.rsk.rpc.modules.debug.DebugModuleImpl;
import co.rsk.rpc.modules.debug.trace.RskTracer;
import co.rsk.rpc.modules.debug.trace.TraceProvider;
import co.rsk.rpc.modules.debug.trace.call.CallTracer;
import co.rsk.rpc.modules.eth.*;
import co.rsk.rpc.modules.eth.subscribe.BlockHeaderNotificationEmitter;
import co.rsk.rpc.modules.eth.subscribe.LogsNotificationEmitter;
Expand Down Expand Up @@ -104,6 +107,7 @@
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.signature.Secp256k1;
import org.ethereum.datasource.*;
import org.ethereum.db.BlockStore;
import org.ethereum.db.IndexedBlockStore;
import org.ethereum.db.ReceiptStore;
import org.ethereum.db.ReceiptStoreImplV2;
Expand Down Expand Up @@ -812,15 +816,16 @@ public synchronized ConfigCapabilities getConfigCapabilities() {
public synchronized DebugModule getDebugModule() {
checkIfNotClosed();

Web3InformationRetriever web3i = getWeb3InformationRetriever();
BlockStore bs = getBlockStore();
BlockExecutor be = getBlockExecutor();
RskTracer rskTracer = new RskTracer(bs, getReceiptStore(),
be, web3i);

CallTracer callTracer = new CallTracer(bs, be, web3i, getReceiptStore(), getBlockchain());
TraceProvider traceProvider = new TraceProvider(Arrays.asList(callTracer, rskTracer));
if (debugModule == null) {
debugModule = new DebugModuleImpl(
getBlockStore(),
getReceiptStore(),
getNodeMessageHandler(),
getBlockExecutor(),
getTxQuotaChecker(),
getWeb3InformationRetriever()
);
debugModule = new DebugModuleImpl(traceProvider, getNodeMessageHandler(), getTxQuotaChecker());
}

return debugModule;
Expand Down
131 changes: 107 additions & 24 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static co.rsk.peg.BridgeUtils.getRegularPegoutTxSize;
import static co.rsk.peg.ReleaseTransactionBuilder.BTC_TX_VERSION_2;
import static co.rsk.peg.bitcoin.BitcoinUtils.findWitnessCommitment;
import static co.rsk.peg.bitcoin.UtxoUtils.extractOutpointValues;
import static co.rsk.peg.pegin.RejectedPeginReason.INVALID_AMOUNT;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.*;
Expand Down Expand Up @@ -52,6 +53,7 @@
import co.rsk.peg.whitelist.*;
import co.rsk.rpc.modules.trace.CallType;
import co.rsk.rpc.modules.trace.ProgramSubtrace;
import co.rsk.util.HexUtils;
import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -60,6 +62,7 @@
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

import org.apache.commons.lang3.tuple.Pair;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
Expand Down Expand Up @@ -1765,7 +1768,7 @@ public Long getBtcTransactionConfirmationsGetCost(Object[] args) {
Context.propagate(btcContext);
try {
this.ensureBtcBlockStore();
final StoredBlock block = btcBlockStore.getFromCache(btcBlockHash);
final StoredBlock block = getBlockKeepingTestnetConsensus(btcBlockHash);

// Block not found, default to basic cost
if (block == null) {
Expand Down Expand Up @@ -1803,7 +1806,7 @@ public Integer getBtcTransactionConfirmations(Sha256Hash btcTxHash, Sha256Hash b
this.ensureBtcBlockChain();

// Get the block using the given block hash
StoredBlock block = btcBlockStore.getFromCache(btcBlockHash);
StoredBlock block = getBlockKeepingTestnetConsensus(btcBlockHash);
if (block == null) {
return BTC_TRANSACTION_CONFIRMATION_INEXISTENT_BLOCK_HASH_ERROR_CODE;
}
Expand Down Expand Up @@ -1839,6 +1842,31 @@ public Integer getBtcTransactionConfirmations(Sha256Hash btcTxHash, Sha256Hash b
return bestChainHeight - block.getHeight() + 1;
}

private StoredBlock getBlockKeepingTestnetConsensus(Sha256Hash btcBlockHash) throws BlockStoreException {
long rskBlockNumber = 5_148_285;

boolean networkIsTestnet = bridgeConstants.getBtcParams().equals(NetworkParameters.fromID(NetworkParameters.ID_TESTNET));
Sha256Hash blockHash = Sha256Hash.wrap("00000000e8e7b540df01a7067e020fd7e2026bf86289def2283a35120c1af379");

// DO NOT MODIFY.
// This check is needed since this block caused a misbehaviour
// for being stored in the cache but not in the storage
if (rskExecutionBlock.getNumber() == rskBlockNumber
&& networkIsTestnet
&& btcBlockHash.equals(blockHash)
) {
byte[] rawBtcBlockHeader = HexUtils.stringHexToByteArray("000000203b5d178405c4e6e7dc07d63d6de5db1342044791721654760c00000000000000796cf6743a036300b43fb3abe6703d04a7999751b6d5744f20327d1175320bd37b954e66ffff001d56dc11ce");

BtcBlock btcBlockHeader = new BtcBlock(bridgeConstants.getBtcParams(), rawBtcBlockHeader);
BigInteger btcBlockChainWork = new BigInteger("000000000000000000000000000000000000000000000ddeb5fbcd969312a77c", 16);
int btcBlockNumber = 2_817_125;

return new StoredBlock(btcBlockHeader, btcBlockChainWork, btcBlockNumber);
}

return btcBlockStore.get(btcBlockHash);
}

private StoredBlock getPrevBlockAtHeight(StoredBlock cursor, int height) throws BlockStoreException {
if (cursor.getHeight() == height) {
return cursor;
Expand Down Expand Up @@ -2144,49 +2172,88 @@ public boolean increaseLockingCap(Transaction tx, Coin newLockingCap) throws Loc
return lockingCapSupport.increaseLockingCap(tx, newLockingCap);
}

public void registerBtcCoinbaseTransaction(byte[] btcTxSerialized, Sha256Hash blockHash, byte[] pmtSerialized, Sha256Hash witnessMerkleRoot, byte[] witnessReservedValue) throws VMException {
public void registerBtcCoinbaseTransaction(
byte[] btcTxSerialized,
Sha256Hash blockHash,
byte[] pmtSerialized,
Sha256Hash witnessMerkleRoot,
byte[] witnessReservedValue
) throws VMException {
Context.propagate(btcContext);
try{
this.ensureBtcBlockStore();
}catch (BlockStoreException | IOException e) {
logger.warn("Exception in registerBtcCoinbaseTransaction", e);
throw new VMException("Exception in registerBtcCoinbaseTransaction", e);
String message = String.format("Exception in registerBtcCoinbaseTransaction. %s", e.getMessage());
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
throw new VMException(message, e);
}

Sha256Hash btcTxHash = BtcTransactionFormatUtils.calculateBtcTxHash(btcTxSerialized);
logger.debug("[registerBtcCoinbaseTransaction] Going to register coinbase information for btcTx: {}", btcTxHash);

if (witnessReservedValue.length != 32) {
logger.warn("[btcTx:{}] WitnessResevedValue length can't be different than 32 bytes", btcTxHash);
throw new BridgeIllegalArgumentException("WitnessResevedValue length can't be different than 32 bytes");
String message = String.format(
"Witness reserved value length can't be different than 32 bytes. Value received: %s",
Bytes.of(witnessReservedValue)
);
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
throw new BridgeIllegalArgumentException(message);
}
logger.trace("[registerBtcCoinbaseTransaction] Witness reserved value: {}", Bytes.of(witnessReservedValue));

if (!PartialMerkleTreeFormatUtils.hasExpectedSize(pmtSerialized)) {
logger.warn("[btcTx:{}] PartialMerkleTree doesn't have expected size", btcTxHash);
throw new BridgeIllegalArgumentException("PartialMerkleTree doesn't have expected size");
String message = String.format(
"PartialMerkleTree doesn't have expected size. Value received: %s",
Bytes.of(pmtSerialized)
);
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
throw new BridgeIllegalArgumentException(message);
}

Sha256Hash merkleRoot;

try {
PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0);
List<Sha256Hash> hashesInPmt = new ArrayList<>();
merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt);
if (!hashesInPmt.contains(btcTxHash)) {
logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash);
logger.warn(
"[registerBtcCoinbaseTransaction] Supplied btc tx {} is not in the supplied partial merkle tree {}",
btcTxHash,
pmt
);
return;
}
} catch (VerificationException e) {
logger.warn("[btcTx:{}] PartialMerkleTree could not be parsed", btcTxHash);
throw new BridgeIllegalArgumentException(String.format("PartialMerkleTree could not be parsed %s", Bytes.of(pmtSerialized)), e);
String message = String.format("Partial merkle tree could not be parsed. %s", Bytes.of(pmtSerialized));
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
throw new BridgeIllegalArgumentException(message, e);
}
logger.trace("[registerBtcCoinbaseTransaction] Merkle root: {}", merkleRoot);

// Check merkle root equals btc block merkle root at the specified height in the btc best chain
// Btc blockstore is available since we've already queried the best chain height
StoredBlock storedBlock = btcBlockStore.getFromCache(blockHash);
StoredBlock storedBlock = null;
try {
storedBlock = btcBlockStore.get(blockHash);
} catch (BlockStoreException e) {
logger.error(
"[registerBtcCoinbaseTransaction] Error gettin block {} from block store. {}",
blockHash,
e.getMessage()
);
}

if (storedBlock == null) {
logger.warn("[btcTx:{}] Block not registered", btcTxHash);
throw new BridgeIllegalArgumentException(String.format("Block not registered %s", blockHash.toString()));
String message = String.format("Block %s not yet registered", blockHash);
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
throw new BridgeIllegalArgumentException(message);
}
logger.trace(
"[registerBtcCoinbaseTransaction] Found block with hash {} at height {}",
blockHash,
storedBlock.getHeight()
);

BtcBlock blockHeader = storedBlock.getHeader();
if (!blockHeader.getMerkleRoot().equals(merkleRoot)) {
String panicMessage = String.format(
Expand All @@ -2195,25 +2262,41 @@ public void registerBtcCoinbaseTransaction(byte[] btcTxSerialized, Sha256Hash bl
merkleRoot,
blockHeader.getMerkleRoot()
);
logger.warn(panicMessage);
logger.warn("[registerBtcCoinbaseTransaction] {}", panicMessage);
panicProcessor.panic("btclock", panicMessage);
return;
}

BtcTransaction btcTx = new BtcTransaction(networkParameters, btcTxSerialized);
btcTx.verify();

Sha256Hash witnessCommitment = Sha256Hash.twiceOf(witnessMerkleRoot.getReversedBytes(), witnessReservedValue);

if(!witnessCommitment.equals(btcTx.findWitnessCommitment())){
logger.warn("[btcTx:{}] WitnessCommitment does not match", btcTxHash);
throw new BridgeIllegalArgumentException("WitnessCommitment does not match");
}
validateWitnessInformation(btcTx, witnessMerkleRoot, witnessReservedValue);

CoinbaseInformation coinbaseInformation = new CoinbaseInformation(witnessMerkleRoot);
provider.setCoinbaseInformation(blockHeader.getHash(), coinbaseInformation);

logger.warn("[btcTx:{}] Registered coinbase information", btcTxHash);
logger.debug("[registerBtcCoinbaseTransaction] Registered coinbase information for btc tx {}", btcTxHash);
}

private void validateWitnessInformation(
BtcTransaction coinbaseTransaction,
Sha256Hash witnessMerkleRoot,
byte[] witnessReservedValue
) throws BridgeIllegalArgumentException {
Optional<Sha256Hash> expectedWitnessCommitment = findWitnessCommitment(coinbaseTransaction);
Sha256Hash calculatedWitnessCommitment = Sha256Hash.twiceOf(witnessMerkleRoot.getReversedBytes(), witnessReservedValue);

if (expectedWitnessCommitment.isEmpty() || !expectedWitnessCommitment.get().equals(calculatedWitnessCommitment)) {
String message = String.format(
"[btcTx: %s] Witness commitment does not match. Expected: %s, Calculated: %s",
coinbaseTransaction.getHash(),
expectedWitnessCommitment.orElse(null),
calculatedWitnessCommitment
);
logger.warn("[validateWitnessInformation] {}", message);
throw new BridgeIllegalArgumentException(message);
}
logger.debug("[validateWitnessInformation] Witness commitment {} validated for btc tx {}", calculatedWitnessCommitment, coinbaseTransaction.getHash());
}

public boolean hasBtcBlockCoinbaseTransactionInformation(Sha256Hash blockHash) {
Expand Down
9 changes: 2 additions & 7 deletions rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import co.rsk.bitcoinj.core.*;
import co.rsk.bitcoinj.crypto.TransactionSignature;
import co.rsk.bitcoinj.script.RedeemScriptParserFactory;
import co.rsk.bitcoinj.script.Script;
import co.rsk.bitcoinj.script.ScriptChunk;
import co.rsk.bitcoinj.script.*;
import co.rsk.bitcoinj.wallet.Wallet;
import co.rsk.peg.constants.BridgeConstants;
import co.rsk.core.RskAddress;
Expand All @@ -48,10 +46,7 @@

import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP284;
Expand Down
Loading

0 comments on commit ba24c35

Please sign in to comment.