diff --git a/app/lib/dto/TransactionDTO.ts b/app/lib/dto/TransactionDTO.ts index aee44796a760b6ca4b362be05e7a2bb47e6dff68..64fcd3ed96a1324db9ad7dff5c014e5d80f58332 100644 --- a/app/lib/dto/TransactionDTO.ts +++ b/app/lib/dto/TransactionDTO.ts @@ -13,7 +13,7 @@ import {hashf} from "../common" import {Cloneable} from "./Cloneable" -import {verifyBuggy} from "../common-libs/crypto/keyring" +import {verify, verifyBuggy} from "../common-libs/crypto/keyring" export interface BaseDTO { base: number @@ -237,7 +237,7 @@ export class TransactionDTO implements Cloneable { } } - getTransactionSigResult() { + getTransactionSigResult(dubp_version: number) { const sigResult = new TxSignatureResultImpl(this.issuers.slice()) let i = 0 const raw = this.getRawTxNoSig() @@ -245,14 +245,19 @@ export class TransactionDTO implements Cloneable { while (matching && i < this.signatures.length) { const sig = this.signatures[i] const pub = this.issuers[i] - sigResult.sigs[i].ok = matching = verifyBuggy(raw, sig, pub) + if (dubp_version >= 12) { + sigResult.sigs[i].ok = verify(raw, sig, pub) + } else { + sigResult.sigs[i].ok = verifyBuggy(raw, sig, pub) + } + matching = sigResult.sigs[i].ok i++ } return sigResult } - checkSignatures() { - return this.getTransactionSigResult().allMatching + checkSignatures(dubp_version: number) { + return this.getTransactionSigResult(dubp_version).allMatching } static fromJSONObject(obj:any, currency:string = "") { diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts index 8ea092799aea792ae16dcefbf8f7b0cbe715d03b..72377e871226a29aeef88e60116f5b9a7b83fe90 100644 --- a/app/lib/indexer.ts +++ b/app/lib/indexer.ts @@ -2160,7 +2160,7 @@ function txSourceUnlock(ENTRY:SindexEntry, source:{ conditions: string, written_ const tx = ENTRY.txObj; const unlockParams:string[] = TransactionDTO.unlock2params(ENTRY.unlock || '') const unlocksMetadata:UnlockMetadata = {} - const sigResult = TransactionDTO.fromJSONObject(tx).getTransactionSigResult() + const sigResult = TransactionDTO.fromJSONObject(tx).getTransactionSigResult(HEAD.version) if (!source.conditions) { return false // Unlock fail } diff --git a/app/lib/rules/global_rules.ts b/app/lib/rules/global_rules.ts index 4842cd4ee3f363717e3796492022efa08f6d7826..21779706ac242ef610004fd1b321625be956fe19 100644 --- a/app/lib/rules/global_rules.ts +++ b/app/lib/rules/global_rules.ts @@ -94,7 +94,7 @@ export const GLOBAL_RULES_FUNCTIONS = { return true; }, - checkSourcesAvailability: async (block:{ transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, findSourceTx:(txHash:string) => Promise<DBTx|null>) => { + checkSourcesAvailability: async (block:{ version: number, transactions:TransactionDTO[], medianTime: number }, conf:ConfDTO, dal:FileDAL, findSourceTx:(txHash:string) => Promise<DBTx|null>) => { const txs = block.transactions const current = await dal.getCurrentBlockOrNull(); for (const tx of txs) { @@ -150,7 +150,7 @@ export const GLOBAL_RULES_FUNCTIONS = { unlocksMetadata.elapsedTime = block.medianTime - dbSrc.written_time; } - const sigs = tx.getTransactionSigResult() + const sigs = tx.getTransactionSigResult(block.version) try { if (!txunlock(dbSrc.conditions, unlocksForCondition, sigs, unlocksMetadata)) { @@ -213,13 +213,18 @@ export const GLOBAL_RULES_HELPERS = { checkSingleTransaction: ( tx:TransactionDTO, - block:{ medianTime: number }, + dubp_version: number, + medianTime: number, conf:ConfDTO, dal:FileDAL, - findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability({ - transactions: [tx], - medianTime: block.medianTime - }, conf, dal, findSourceTx), + findSourceTx:(txHash:string) => Promise<DBTx|null>) => GLOBAL_RULES_FUNCTIONS.checkSourcesAvailability( + { + version: dubp_version, + transactions: [tx], + medianTime: medianTime + }, + conf, dal, findSourceTx + ), checkTxBlockStamp: async (tx:TransactionDTO, dal:FileDAL) => { const number = parseInt(tx.blockstamp.split('-')[0]) diff --git a/app/lib/rules/local_rules.ts b/app/lib/rules/local_rules.ts index eb71d674ca4919cf0ed5ce05e5456121ee203b42..c943fac63f8cba8718f20a22d92a936e71cfcaea 100644 --- a/app/lib/rules/local_rules.ts +++ b/app/lib/rules/local_rules.ts @@ -390,7 +390,7 @@ export const LOCAL_RULES_FUNCTIONS = { const txs = block.transactions // Check rule against each transaction for (const tx of txs) { - if (!tx.checkSignatures()) { + if (!tx.checkSignatures(block.version)) { throw Error('Signature from a transaction must match') } } diff --git a/app/modules/prover/lib/blockGenerator.ts b/app/modules/prover/lib/blockGenerator.ts index 2d7bba35595c127f7643d257e55d192ae93b2742..45529c4106eb3dad6fdf60aed8aa4e79e4833f12 100644 --- a/app/modules/prover/lib/blockGenerator.ts +++ b/app/modules/prover/lib/blockGenerator.ts @@ -144,8 +144,8 @@ export class BlockGenerator { const tx = TransactionDTO.fromJSONObject(obj); try { await LOCAL_RULES_HELPERS.checkBunchOfTransactions(passingTxs.concat(tx), this.conf, medianTime, options) - const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 }; - await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, nextBlockWithFakeTimeVariation, this.conf, this.dal, async (txHash:string) => { + const fakeTimeVariation = current.medianTime + 1; + await GLOBAL_RULES_HELPERS.checkSingleTransaction(tx, current.version, fakeTimeVariation, this.conf, this.dal, async (txHash:string) => { return Underscore.findWhere(passingTxs, { hash: txHash }) || null }); await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal); diff --git a/app/service/TransactionsService.ts b/app/service/TransactionsService.ts index 489ed660e1aaf794f3324cf60a3dab2045350bc5..a343b625b13e6756e365b1ed7e422ea0bad7cdaf 100644 --- a/app/service/TransactionsService.ts +++ b/app/service/TransactionsService.ts @@ -54,11 +54,11 @@ export class TransactionService extends FIFOService { throw constants.ERRORS.TX_ALREADY_PROCESSED; } // Start checks... - const nextBlockWithFakeTimeVariation = { medianTime: current.medianTime + 1 }; + const fakeTimeVariation = current.medianTime + 1; const dto = TransactionDTO.fromJSONObject(tx) await LOCAL_RULES_HELPERS.checkSingleTransactionLocally(dto, this.conf) await GLOBAL_RULES_HELPERS.checkTxBlockStamp(tx, this.dal); - await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, nextBlockWithFakeTimeVariation, this.conf, this.dal, this.dal.getTxByHash.bind(this.dal)); + await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, current.version, fakeTimeVariation, this.conf, this.dal, this.dal.getTxByHash.bind(this.dal)); const server_pubkey = this.conf.pair && this.conf.pair.pub; if (!(await this.dal.txsDAL.sandbox.acceptNewSandBoxEntry({ issuers: tx.issuers,