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

Feature/powpeg validation protocol phase3 #2811

Open
wants to merge 44 commits into
base: feature/powpeg_validation_protocol-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d0e50e1
Move searchForOutput method to BitcoinUtils to reuse it
julia-zack Sep 25, 2024
cb0e2bc
Create and process svp spend transaction
julia-zack Sep 25, 2024
5f23da4
Add tests to spend transaction process. Refactor some methods to avoi…
julia-zack Sep 26, 2024
8f188b2
Create new method in BitcoinUtils to remove duplicated code from Brid…
julia-zack Sep 26, 2024
3f6c1e5
Add hsm-needed pegout logging for svp spend tx. Remove duplicated code
julia-zack Sep 26, 2024
5d288e1
Add assertions to new logged events. Reorder methods to be more organ…
julia-zack Sep 26, 2024
70fd49e
Refactor method to avoid throwing exception unnecessary. Rename metho…
julia-zack Sep 26, 2024
729fca9
Rename method that calculates amount to be sent in svp spend tx. Repl…
julia-zack Sep 26, 2024
ab6c7fd
Add missing empty p2sh input script to svp spend transaction
julia-zack Sep 30, 2024
407f086
Add tests to check if svp spend tx inputs have expected script sig
julia-zack Oct 1, 2024
7c961d4
Refactor BridgeEventLoggerImpl
julia-zack Sep 27, 2024
2048c49
Refactor BridgeEventLoggerImpl to not receive SignatureCache object
marcos-iov Sep 27, 2024
fd62cb8
Remove unnecessary (since we are unit-testing) arguments from asserti…
julia-zack Sep 27, 2024
5fe0e32
feat(federation): add getProposedFederationAddress method to Federati…
apancorb Oct 2, 2024
c8ce076
feat(federation): add getProposedFederationSize to Federation Support
apancorb Oct 2, 2024
94b87a7
Create new commitFederationFailed Bridge event
julia-zack Sep 27, 2024
b707b0c
Add test for logCommitFederationFailure from deprecated logger
julia-zack Oct 1, 2024
144ea6e
Move rsk block creation method to RskTestUtils
julia-zack Oct 3, 2024
82f0c9b
Remove unnecessary suffix from variable name
julia-zack Oct 3, 2024
d9c4942
Create default implementation of createRskBlock util method
marcos-iov Oct 3, 2024
f18dac8
feat(federation): add getProposedFederationCreationTime in Federation…
apancorb Oct 2, 2024
f8e925b
feat(federation): add getProposedFederationCreationBlockNumber method…
apancorb Oct 2, 2024
1a95c23
feat(peg): add getProposedFederationAddress Bridge method
apancorb Oct 3, 2024
7732178
feat(peg): Update Bridge
apancorb Oct 4, 2024
fd6bd6b
feat(federation): add getProposedFederatorPublicKeyOfType method in F…
apancorb Oct 2, 2024
fae9175
refactor(federation): tidy up federation builder
apancorb Oct 3, 2024
aaa4fb8
feat(federation): add more unit tests per key type when empty federation
apancorb Oct 4, 2024
e0f52f5
feat(federation): add javadoc for getProposedFederationCreationTime i…
apancorb Oct 7, 2024
2e405e6
feat(peg): add getProposedFederationCreationTime Bridge method
apancorb Oct 7, 2024
7825529
feat(federation): add javadoc for getProposedFederationCreationBlockN…
apancorb Oct 7, 2024
6e76150
feat(peg): add getProposedFederationCreationBlockNumber Bridge Method
apancorb Oct 7, 2024
26ef5b5
feat(federation): add javadoc for getProposedFederationSize in Federa…
apancorb Oct 7, 2024
af872b3
feat(peg): add getProposedFederationSize Bridge Method
apancorb Oct 7, 2024
25e7437
Rename method that calculates amount to be sent in svp spend tx. Repl…
julia-zack Sep 26, 2024
f044914
feat(federation): add getProposedFederatorPublicKeyOfType method in F…
apancorb Oct 2, 2024
6ca9bec
feat(peg): add getProposedFederatorPublicKeyOfType Bridge method
apancorb Oct 8, 2024
cf7f2b0
Remove duplicated method declaration in FederationSupport
marcos-iov Oct 8, 2024
2a0aafc
feat(peg): update test name in BridgeSupportTest
apancorb Oct 9, 2024
e8f58ed
Refactor addSignature as previous step to create addSvpSpendTxSignatu…
julia-zack Oct 3, 2024
88bb819
Use getScriptSigWithSignature instead of updateScriptWithSignature
julia-zack Oct 8, 2024
3731668
Rename boolean method. Replace rskTxHashSerialized argument for the k…
julia-zack Oct 9, 2024
2961f83
Use already existing method to extract redeem script. Remove unnecess…
julia-zack Oct 11, 2024
7083694
Throw exception when trying to serialize a null value. Move tests to …
julia-zack Oct 14, 2024
48c63ee
Create addSvpSpendTxSignature method. Add tests. Rename method to mak…
julia-zack Oct 14, 2024
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
132 changes: 127 additions & 5 deletions rskj-core/src/main/java/co/rsk/peg/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package co.rsk.peg;

import static co.rsk.peg.BridgeSerializationUtils.deserializeRskTxHash;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP417;

import co.rsk.bitcoinj.core.*;
Expand All @@ -33,6 +34,7 @@
import co.rsk.peg.vote.ABICallSpec;
import co.rsk.peg.bitcoin.MerkleBranch;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.FederationChangeResponseCode;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.flyover.FlyoverTxResponseCodes;
import co.rsk.peg.utils.BtcTransactionFormatUtils;
Expand Down Expand Up @@ -616,14 +618,15 @@ public void addSignature(Object[] args) throws VMException {
}
signatures.add(signatureByteArray);
}
byte[] rskTxHash = (byte[]) args[2];
if (rskTxHash.length!=32) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHash));
byte[] rskTxHashSerialized = (byte[]) args[2];
Keccak256 rskTxHash;
try {
rskTxHash = deserializeRskTxHash(rskTxHashSerialized);
} catch (IllegalArgumentException e) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHashSerialized));
}
try {
bridgeSupport.addSignature(federatorPublicKey, signatures, rskTxHash);
} catch (BridgeIllegalArgumentException e) {
throw e;
} catch (Exception e) {
logger.warn("Exception in addSignature", e);
throw new VMException("Exception in addSignature", e);
Expand Down Expand Up @@ -1040,6 +1043,125 @@ public byte[] getPendingFederatorPublicKeyOfType(Object[] args) throws VMExcepti
return publicKey;
}

/**
* Retrieves the proposed federation Bitcoin address as a Base58 string.
*
* <p>
* This method attempts to fetch the address of the proposed federation. If the
* proposed federation is present, it converts the address to its Base58 representation.
* If not, an empty string is returned.
* <p>
*
* @param args Additional arguments (currently unused)
* @return The Base58 encoded Bitcoin address of the proposed federation, or an empty
* string if no proposed federation is present.
*/
public String getProposedFederationAddress(Object[] args) {
logger.trace("getProposedFederationAddress");

return bridgeSupport.getProposedFederationAddress()
.map(Address::toBase58)
.orElse("");
}

/**
* Retrieves the size of the proposed federation, if it exists.
*
* <p>
* This method returns the number of members in the proposed federation. If no proposed federation exists,
* it returns a default response code {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT} that indicates
* the federation does not exist.
* </p>
*
* @param args unused arguments for this method (can be null or empty).
* @return the size of the proposed federation (number of members), or the default code from
* {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT} if no proposed federation is available.
*/
public int getProposedFederationSize(Object[] args) {
logger.trace("getProposedFederationSize");

return bridgeSupport.getProposedFederationSize()
.orElse(FederationChangeResponseCode.FEDERATION_NON_EXISTENT.getCode());
}

/**
* Retrieves the creation time of the proposed federation in milliseconds since the epoch.
*
* <p>
* This method checks if a proposed federation exists and returns its creation time in
* milliseconds since the Unix epoch. If no proposed federation exists, it returns -1.
* </p>
*
* @param args unused arguments for this method (can be null or empty).
* @return the creation time of the proposed federation in milliseconds since the epoch,
* or -1 if no proposed federation exists.
*/
public Long getProposedFederationCreationTime(Object[] args) {
logger.trace("getProposedFederationCreationTime");

return bridgeSupport.getProposedFederationCreationTime()
.map(Instant::toEpochMilli)
.orElse(-1L);
}

/**
* Retrieves the block number of the proposed federation's creation.
*
* <p>
* This method checks if a proposed federation exists and returns the block number at which it was created.
* If no proposed federation exists, it returns the default code defined in
* {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT}.
* </p>
*
* @param args unused arguments for this method (can be null or empty).
* @return the block number of the proposed federation's creation, or
* the code from {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT}
* if no proposed federation exists.
*/
public long getProposedFederationCreationBlockNumber(Object[] args) {
logger.trace("getProposedFederationCreationBlockNumber");

return bridgeSupport.getProposedFederationCreationBlockNumber()
.orElse((long) FederationChangeResponseCode.FEDERATION_NON_EXISTENT.getCode());
}

/**
* Retrieves the public key of the proposed federator at the specified index and key type.
*
* <p>
* This method extracts the index and key type from the provided arguments, retrieves the
* public key of the proposed federator, and returns it. If no public key is found, an empty byte
* array is returned.
* </p>
*
* <p>
* The first argument in the {@code args} array is expected to be a {@link BigInteger} representing
* the federator's index. The second argument is expected to be a {@link String} representing
* the key type, which is converted into a {@link FederationMember.KeyType}.
* </p>
*
* @param args an array of arguments, where {@code args[0]} is a {@link BigInteger} for the federator's index,
* and {@code args[1]} is a {@link String} for the key type.
* @return a byte array containing the federator's public key, or an empty byte array if not found.
* @throws VMException if an error occurs while processing the key type.
*/
public byte[] getProposedFederatorPublicKeyOfType(Object[] args) throws VMException {
logger.trace("getProposedFederatorPublicKeyOfType");

int index = ((BigInteger) args[0]).intValue();

FederationMember.KeyType keyType;
try {
keyType = FederationMember.KeyType.byValue((String) args[1]);
} catch (Exception e) {
logger.warn("Exception in getProposedFederatorPublicKeyOfType", e);
throw new VMException("Exception in getProposedFederatorPublicKeyOfType", e);
}

return bridgeSupport.getProposedFederatorPublicKeyOfType(index, keyType)
.orElse(new byte[]{});
}

public Integer getLockWhitelistSize(Object[] args) {
logger.trace("getLockWhitelistSize");

Expand Down
10 changes: 8 additions & 2 deletions rskj-core/src/main/java/co/rsk/peg/BridgeEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public enum BridgeEvents {
new CallTransaction.Param(false, "activationHeight", SolidityType.getType(SolidityType.INT256))
}
),
COMMIT_FEDERATION_FAILED("commit_federation_failed",
new CallTransaction.Param[]{
new CallTransaction.Param(false, "proposedFederationRedeemScript", SolidityType.getType(SolidityType.BYTES)),
new CallTransaction.Param(false, "blockNumber", SolidityType.getType(SolidityType.INT256))
}
),
RELEASE_REQUESTED("release_requested",
new CallTransaction.Param[]{
new CallTransaction.Param(true, "rskTxHash", SolidityType.getType(SolidityType.BYTES32)),
Expand Down Expand Up @@ -107,8 +113,8 @@ public enum BridgeEvents {
}
);

private String eventName;
private CallTransaction.Param[] params;
private final String eventName;
private final CallTransaction.Param[] params;

BridgeEvents(String eventName, CallTransaction.Param[] params) {
this.eventName = eventName;
Expand Down
Loading