Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update use of RedeemScriptParser interface to support new changes #321

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ tasks.withType(AbstractArchiveTask) {

ext {
bitcoinjcoreVersion = '0.15.6-rsk-3'
bitcoinjVersion = '0.14.4-rsk-15'
bitcoinjVersion = '0.14.4-rsk-16-SNAPSHOT'
commonsLang3Version = '3.12.0'
commonsIoVersion = '2.11.0'
slf4jVersion = '1.7.36'
Expand Down
8 changes: 0 additions & 8 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@
<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"/>
</artifact>
<artifact name="bitcoinj-thin-0.14.4-rsk-15.pom">
<sha256 value="deda61ace1b697c488c8acddbc60fcc55be75df9097c8cd2dad87f8c6afa21f2" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.fasterxml" name="oss-parent" version="38">
<artifact name="oss-parent-38.pom">
<sha256 value="c83f8f45dfdca8d0b6b3661c60b3f84780f671b12e06f91ad5d1c1a1d1f966e8" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import co.rsk.bitcoinj.script.RedeemScriptParser;
import co.rsk.bitcoinj.script.RedeemScriptParserFactory;
import co.rsk.bitcoinj.script.Script;
import co.rsk.bitcoinj.script.ScriptBuilder;
import co.rsk.bitcoinj.script.ScriptChunk;
import co.rsk.bitcoinj.wallet.RedeemData;
import co.rsk.peg.constants.BridgeConstants;
Expand Down Expand Up @@ -479,8 +480,9 @@ protected void removeSignaturesFromTransaction(BtcTransaction pegoutBtcTx, Feder
}

protected Script extractStandardRedeemScript(Script redeemScript) {
RedeemScriptParser parser = RedeemScriptParserFactory.get(redeemScript.getChunks());
return parser.extractStandardRedeemScript();
RedeemScriptParser redeemScriptParser = RedeemScriptParserFactory.get(redeemScript.getChunks());
List<ScriptChunk> defaultRedeemScriptChunks = redeemScriptParser.extractStandardRedeemScriptChunks();
return new ScriptBuilder().addChunks(defaultRedeemScriptChunks).build();
}

private Script extractDefaultRedeemScript(Federation federation) {
Expand All @@ -505,7 +507,6 @@ protected Federation getSpendingFederation(BtcTransaction btcTx) {
List<Federation> spendingFedFilter = observedFederations.stream()
.filter(f -> (extractDefaultRedeemScript(f)).equals(redeemScript)).collect(Collectors.toList());


return spendingFedFilter.get(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import co.rsk.bitcoinj.core.TransactionInput;
import co.rsk.bitcoinj.crypto.TransactionSignature;
import co.rsk.bitcoinj.params.RegTestParams;
import co.rsk.bitcoinj.script.FastBridgeRedeemScriptParser;
import co.rsk.bitcoinj.script.Script;
import co.rsk.bitcoinj.script.ScriptBuilder;
import co.rsk.bitcoinj.script.ScriptChunk;
import co.rsk.peg.bitcoin.FlyoverRedeemScriptBuilderImpl;
import co.rsk.peg.constants.BridgeConstants;
import co.rsk.crypto.Keccak256;
import co.rsk.federate.FederatorSupport;
Expand Down Expand Up @@ -820,13 +820,16 @@ void validateTxCanBeSigned_fast_bridge_ok() throws Exception {
Federation federation = TestUtils.createFederation(params, 1);

// Create fast bridge redeem script
Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(
federation.getRedeemScript(),
Sha256Hash.wrap(TestUtils.createHash(1).getBytes())

Keccak256 flyoverDerivationHash = createHash(1);

Script flyoverRedeemScript = FlyoverRedeemScriptBuilderImpl.builder().of(
flyoverDerivationHash,
federation.getRedeemScript()
);

// Create a tx from the Fed to a random btc address
BtcTransaction releaseTx = createReleaseTxAndAddInput(federation, fastBridgeRedeemScript);
BtcTransaction releaseTx = createReleaseTxAndAddInput(federation, flyoverRedeemScript);

BtcECKey fed1Key = federation.getBtcPublicKeys().get(0);
ECPublicKey signerPublicKey = new ECPublicKey(fed1Key.getPubKey());
Expand Down Expand Up @@ -1020,13 +1023,14 @@ void getRedeemScriptFromInput_standard_redeem_script() {
@Test
void extractStandardRedeemScript_fast_bridge_redeem_script() {
Federation federation = TestUtils.createFederation(params, 1);
Script fastBridgeRedeemScript =
FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(
federation.getRedeemScript(),
Sha256Hash.of(TestUtils.createHash(1).getBytes())
);

test_extractStandardRedeemScript(federation.getRedeemScript(), fastBridgeRedeemScript);
Keccak256 flyoverDerivationHash = createHash(1);
Script flyoverRedeemScript = FlyoverRedeemScriptBuilderImpl.builder().of(
flyoverDerivationHash,
federation.getRedeemScript()
);

test_extractStandardRedeemScript(federation.getRedeemScript(), flyoverRedeemScript);
}

@Test
Expand Down Expand Up @@ -1112,7 +1116,7 @@ private void test_extractStandardRedeemScript(
);
}

private void test_getRedeemScriptFromInput(boolean isFastBridgeRedeemScript) {
private void test_getRedeemScriptFromInput(boolean isFlyoverRedeemScript) {
BtcReleaseClient client = createBtcClient();

BtcECKey ecKey1 = BtcECKey.fromPrivate(BigInteger.valueOf(100));
Expand All @@ -1124,10 +1128,11 @@ private void test_getRedeemScriptFromInput(boolean isFastBridgeRedeemScript) {
Script federationRedeemScript = federation.getRedeemScript();
Script inputScript;

if (isFastBridgeRedeemScript) {
federationRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(
federationRedeemScript,
Sha256Hash.of(new byte[]{1})
if (isFlyoverRedeemScript) {
Keccak256 flyoverDerivationHash = createHash(1);
federationRedeemScript = FlyoverRedeemScriptBuilderImpl.builder().of(
flyoverDerivationHash,
federation.getRedeemScript()
);
}
inputScript = federation.getP2SHScript().createEmptyInputScript(
Expand Down