Skip to content

Commit

Permalink
fix(@neo-one/node-vm): sort witness script hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dicarlo2 committed Feb 11, 2019
1 parent 9c7f378 commit a5f682b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 14 additions & 5 deletions packages/neo-one-node-core/src/transaction/TransactionBase.ts
Expand Up @@ -151,6 +151,14 @@ export function TransactionBase<
(other: TransactionBaseClass) => common.uInt256Equal(this.hash, other.hash),
);
public readonly toKeyString = utils.toKeyString(TransactionBase, () => this.hashHex);
public readonly getSortedScriptHashesForVerifying = utils.lazyAsync(
async (options: TransactionGetScriptHashesForVerifyingOptions) => {
const hashes = await this.getScriptHashesForVerifying(options);

// tslint:disable-next-line no-array-mutation
return [...hashes].sort();
},
);
private readonly sizeInternal = utils.lazy(
() =>
IOHelper.sizeOfUInt8 +
Expand Down Expand Up @@ -436,17 +444,18 @@ export function TransactionBase<
getOutput,
verifyScript,
}: TransactionVerifyOptions): Promise<ReadonlyArray<VerifyScriptResult>> {
const hashesSet = await this.getScriptHashesForVerifying({
const hashesArr = await this.getSortedScriptHashesForVerifying({
getAsset,
getOutput,
});

if (hashesSet.size !== this.scripts.length) {
throw new VerifyError(`Invalid witnesses. Found ${hashesSet.size} hashes and ${this.scripts.length} scripts.`);
if (hashesArr.length !== this.scripts.length) {
throw new VerifyError(
`Invalid witnesses. Found ${hashesArr.length} hashes and ${this.scripts.length} scripts.`,
);
}

// tslint:disable-next-line no-array-mutation
const hashes = [...hashesSet].sort().map((value) => common.hexToUInt160(value));
const hashes = hashesArr.map((value) => common.hexToUInt160(value));

return Promise.all(
_.zip(hashes, this.scripts).map(async ([hash, witness]) =>
Expand Down
3 changes: 1 addition & 2 deletions packages/neo-one-node-vm/src/syscalls.ts
Expand Up @@ -890,11 +890,10 @@ export const SYSCALLS: { readonly [K in SysCallEnum]: CreateSysCall } = {
throw new ContainerTooLargeError(context);
}

const hashesSet = await transaction.getScriptHashesForVerifying({
const hashes = await transaction.getSortedScriptHashesForVerifying({
getOutput: context.blockchain.output.get,
getAsset: context.blockchain.asset.get,
});
const hashes = [...hashesSet];
const witnesses = await Promise.all(
transaction.scripts.map(async (witness, idx) => {
if (witness.verification.length === 0) {
Expand Down

0 comments on commit a5f682b

Please sign in to comment.