mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Code cleanup: proto fields, duplicated expr & null char separator
1. Reorder the PoW fields in the 'Filter' proto by field index, instead of contextually. 2. Deduplicate expression for 'pow' & replace if-block with boolean op to simplify 'FilterManager::isProofOfWorkValid'. 3. Avoid slightly confusing use of null char as a separator to prevent hashing collisions in 'EquihashProofOfWorkService::getChallenge'. Use comma separator and escape the 'itemId' & 'ownerId' arguments instead. (based on PR #5858 review comments)
This commit is contained in:
parent
c9c2be6dcd
commit
ceb9b9acbd
3 changed files with 10 additions and 20 deletions
|
@ -19,16 +19,11 @@ package bisq.common.crypto;
|
|||
|
||||
import com.google.common.primitives.Longs;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@Slf4j
|
||||
public class EquihashProofOfWorkService extends ProofOfWorkService {
|
||||
/** Rough cost of two Hashcash iterations compared to solving an Equihash-90-5 puzzle of unit difficulty. */
|
||||
|
@ -56,9 +51,9 @@ public class EquihashProofOfWorkService extends ProofOfWorkService {
|
|||
|
||||
@Override
|
||||
public byte[] getChallenge(String itemId, String ownerId) {
|
||||
checkArgument(!StringUtils.contains(itemId, '\0'));
|
||||
checkArgument(!StringUtils.contains(ownerId, '\0'));
|
||||
return Hash.getSha256Hash(checkNotNull(itemId) + "\0" + checkNotNull(ownerId));
|
||||
String escapedItemId = itemId.replace(" ", " ");
|
||||
String escapedOwnerId = ownerId.replace(" ", " ");
|
||||
return Hash.getSha256Hash(escapedItemId + ", " + escapedOwnerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -489,16 +489,11 @@ public class FilterManager {
|
|||
if (filter == null) {
|
||||
return true;
|
||||
}
|
||||
checkArgument(offer.getBsqSwapOfferPayload().isPresent(),
|
||||
"Offer payload must be BsqSwapOfferPayload");
|
||||
checkArgument(offer.getBsqSwapOfferPayload().isPresent(), "Offer payload must be BsqSwapOfferPayload");
|
||||
ProofOfWork pow = offer.getBsqSwapOfferPayload().get().getProofOfWork();
|
||||
var service = ProofOfWorkService.forVersion(pow.getVersion());
|
||||
if (!service.isPresent() || !getEnabledPowVersions().contains(pow.getVersion())) {
|
||||
return false;
|
||||
}
|
||||
return service.get().verify(offer.getBsqSwapOfferPayload().get().getProofOfWork(),
|
||||
offer.getId(), offer.getOwnerNodeAddress().toString(),
|
||||
filter.getPowDifficulty());
|
||||
return service.isPresent() && getEnabledPowVersions().contains(pow.getVersion()) &&
|
||||
service.get().verify(pow, offer.getId(), offer.getOwnerNodeAddress().toString(), filter.getPowDifficulty());
|
||||
}
|
||||
|
||||
public List<Integer> getEnabledPowVersions() {
|
||||
|
|
|
@ -85,8 +85,8 @@ message NetworkEnvelope {
|
|||
ShareBuyerPaymentAccountMessage share_buyer_payment_account_message = 54; // Added at 1.7.0
|
||||
|
||||
SellersBsqSwapRequest sellers_bsq_swap_request = 55;
|
||||
BuyersBsqSwapRequest buyers_bsq_swap_request= 56;
|
||||
BsqSwapTxInputsMessage bsq_swap_tx_inputs_message= 57;
|
||||
BuyersBsqSwapRequest buyers_bsq_swap_request = 56;
|
||||
BsqSwapTxInputsMessage bsq_swap_tx_inputs_message = 57;
|
||||
BsqSwapFinalizeTxRequest bsq_swap_finalize_tx_request = 58;
|
||||
BsqSwapFinalizedTxMessage bsq_swap_finalized_tx_message = 59;
|
||||
}
|
||||
|
@ -770,11 +770,11 @@ message Filter {
|
|||
bool disable_mempool_validation = 28;
|
||||
bool disable_pow_message = 29;
|
||||
double pow_difficulty = 30;
|
||||
repeated int32 enabled_pow_versions = 35;
|
||||
int64 maker_fee_btc = 31;
|
||||
int64 taker_fee_btc = 32;
|
||||
int64 maker_fee_bsq = 33;
|
||||
int64 taker_fee_bsq = 34;
|
||||
repeated int32 enabled_pow_versions = 35;
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
|
@ -2038,7 +2038,7 @@ message BaseBlock {
|
|||
}
|
||||
|
||||
message BsqBlockStore {
|
||||
repeated BaseBlock blocks = 1;
|
||||
repeated BaseBlock blocks = 1;
|
||||
}
|
||||
|
||||
message RawBlock {
|
||||
|
|
Loading…
Add table
Reference in a new issue