Skip to content

Conversation

@julianlen
Copy link
Contributor

Description

Motivation and Context

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@julianlen julianlen requested a review from a team as a code owner December 5, 2025 20:30
@julianlen julianlen requested review from Copilot and removed request for a team December 5, 2025 20:31
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds tests to verify the maximum number of inputs allowed in Bitcoin pegout transactions while staying within the Bitcoin standard transaction size limit. The changes include updates to the PegoutTransactionBuilder to accept custom script signatures, a new utility method for calculating SegWit transaction virtual size, and two test cases that verify transaction sizes with different input counts.

  • Added calculateSignedSegwitBtcTxVirtualSize utility method for calculating transaction virtual sizes
  • Updated PegoutTransactionBuilder.withInput to accept a script parameter instead of hardcoding an empty byte array
  • Added tests verifying that 150 inputs stay below the limit while 210 inputs exceed it

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java Extracted virtual byte calculation into reusable methods and added public method for calculating SegWit transaction virtual size
rskj-core/src/test/java/co/rsk/peg/BridgeUtilsTest.java Added test case to verify virtual size calculation using a real SegWit transaction
rskj-core/src/test/java/co/rsk/peg/ReleaseTransactionBuilderTest.java Added tests verifying transaction size limits with varying input counts and refactored UTXO generation helper
rskj-core/src/test/java/co/rsk/test/builders/PegoutTransactionBuilder.java Modified withInput method to accept script parameter for more flexible test setup
rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java Updated test calls to match new withInput signature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@julianlen
Copy link
Contributor Author

As a comment, the method calculateSignedSegwitBtcTxVirtualSize https://github.com/rsksmart/rskj/pull/3405/files#diff-a33646b11694d377aa69060bbfd25b2800f9e3f72e5ecfbbb3b1b4ab16c4da2fR674 is in BridgeUtils.java as production code. Although the tests only use this method.

int actualVirtualBytes = calculateSignedSegwitBtcTxVirtualSize(btcTx);

//assert
Assertions.assertEquals(expectedVirtualBytes, actualVirtualBytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very very nice

}

@Test
void createPegoutTransaction_with210Inputs_with50Outputs_shouldHaveASizeAboveMaximumBtcStandardSize() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do these tests for migrations also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is right now, a migration tx has only 3 outputs (if there is change). Would you think it makes sense at this stage? Perhaps in the future with multiple utxos?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean creating it manually, no big deal at all anyways

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(btw, there's no change in the migration tx)

}

@Test
void calculateSignedSegwitBtcTxVirtualSize_withASegwitTx_shouldReturnCorrectVirtualSize() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void calculateSignedSegwitBtcTxVirtualSize_withASegwitTx_shouldReturnCorrectVirtualSize() {
void calculateSignedSegwitBtcTxVirtualSize_whenSignedSegwitTx_shouldReturnCorrectVirtualSize() {

Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm the tx is not being signed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the article. I refer to the noun ASignedSegwitTx, which denotes a signed segwit tx is being passed. The point is to make that test case explicit and to test it with other types of txs as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was changed to calculateBtcTxVirtualSize_withARealBtcTx_shouldReturnCorrectVirtualSize

return baseSize + signingSize;
}

public static int calculateSignedSegwitBtcTxVirtualSize(BtcTransaction btcTx) {
Copy link
Contributor

@nathanieliov nathanieliov Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you pass an unsigned segwit transaction? Does it work? Return the correct value? Or should throw an exception?

I think we are missing more tests for this method. To mention some cases:

  • Passing unsigned segwit tx(as said)?
  • Bech32 tx?
  • Legacy tx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unsigned segwit tx there is a different method that estimates the size calculateSegwitTxSize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass an unsigned segwit tx or another type of tx, it will attempt to calculate the btc tx size. Will it succeed on it? If so, will the result be correct? I guess no. Since this used is not expected, should we throw an exception if the method is misused so we can catch this error early?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that this method isn't used anywhere but to calculate the btc tx size limit for a SegWit tx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, let's create a task to further analyze the missing test cases.

}

@Test
void createPegoutTransaction_with210Inputs_with50Outputs_shouldHaveASizeAboveMaximumBtcStandardSize() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test naming is confusing to me. The name says you are testing the createPegoutTransaction method, but it is a test helper method, so I guess what is being tested is calculateSignedSegwitBtcTxVirtualSize. Then, why have these tests in ReleaseTransactionBuilderTest? According to what I see, these tests are using nothing from it. I would rather move them to BridgeUtilsTest, or better yet, to their own test class. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are one step before creating migration transactions with multiple utxos. That is why it is confusing. The test will be createMigrationTransactionWithMultipleUtxos..

In BridgeUtilsTest I am testing calculateBtcTxVirtualSize_withARealBtcTx_shouldReturnCorrectVirtualSize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same, let's create a task for the future refactors.

private final Federation p2shP2wshErpProposedFederation = P2shP2wshErpFederationBuilder.builder().build();
private final List<BtcECKey> signingKeys = BitcoinTestUtils.getBtcEcKeys(20);
private final Federation p2shP2wshErpProposedFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build();
private final Federation p2shP2wshErpFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private final Federation p2shP2wshErpFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build();
private final Federation activeP2shP2wshErpFederation = P2shP2wshErpFederationBuilder.builder().withMembersBtcPublicKeys(signingKeys).build();

wdyt? and move the declaration below the activeP2shErpFederation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Contributor

@julia-zack julia-zack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work! left one suggestion

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants