Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Fix report misbehavior outdated endpoints (#8522)
Browse files Browse the repository at this point in the history
* 🐛 Fix report misbehavior outdated endpoints

* ♻️ Update variable name

* Fix unit test performance
  • Loading branch information
shuse2 authored Jun 6, 2023
1 parent f5b8925 commit 8b8df42
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/pos-mainchain/config/alphanet/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"modules": {},
"plugins": {
"reportMisbehavior": {
"encryptedPassphrase": "iterations=10&cipherText=5dea8b928a3ea2481ebc02499ae77679b7552189181ff189d4aa1f8d89e8d07bf31f7ebd1c66b620769f878629e1b90499506a6f752bf3323799e3a54600f8db02f504c44d&iv=37e0b1753b76a90ed0b8c319&salt=963c5b91d3f7ba02a9d001eed49b5836&tag=c3e30e8f3440ba3f5b6d9fbaccc8918d&version=1"
"encryptedPrivateKey": "kdf=argon2id&cipher=aes-256-gcm&version=1&ciphertext=fb564e463ce46efab010f21b06d01acc62f705049563b58628d4ca23053ba6bdce5be39cb5c0624bd75735ee10a8a12b9c7876d86fc3646d036b414701dc6b01217102480cd327f5eec31b2cf209ea8b6c64505ab8bab81ed315c12c33feaaef982facec63c876def26eeefd1c0d9a5b7dce5e604622c704106a64c27b71eff7&mac=429c65daf7f6e9dba5e105be55fb7a450c74e424ff9a20cd5cb614c31fb8b010&salt=19a15ea6d5925d7104b4db0c8b0ca73a&iv=b5ec03e61586b202a1f4e9aa&tag=82ca4b682f89daa642a13edae085feea&iterations=1&parallelism=4&memorySize=2024"
}
}
}
2 changes: 1 addition & 1 deletion examples/pos-mainchain/config/default/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"modules": {},
"plugins": {
"reportMisbehavior": {
"encryptedPassphrase": "iterations=10&cipherText=5dea8b928a3ea2481ebc02499ae77679b7552189181ff189d4aa1f8d89e8d07bf31f7ebd1c66b620769f878629e1b90499506a6f752bf3323799e3a54600f8db02f504c44d&iv=37e0b1753b76a90ed0b8c319&salt=963c5b91d3f7ba02a9d001eed49b5836&tag=c3e30e8f3440ba3f5b6d9fbaccc8918d&version=1"
"encryptedPrivateKey": "kdf=argon2id&cipher=aes-256-gcm&version=1&ciphertext=fb564e463ce46efab010f21b06d01acc62f705049563b58628d4ca23053ba6bdce5be39cb5c0624bd75735ee10a8a12b9c7876d86fc3646d036b414701dc6b01217102480cd327f5eec31b2cf209ea8b6c64505ab8bab81ed315c12c33feaaef982facec63c876def26eeefd1c0d9a5b7dce5e604622c704106a64c27b71eff7&mac=429c65daf7f6e9dba5e105be55fb7a450c74e424ff9a20cd5cb614c31fb8b010&salt=19a15ea6d5925d7104b4db0c8b0ca73a&iv=b5ec03e61586b202a1f4e9aa&tag=82ca4b682f89daa642a13edae085feea&iterations=1&parallelism=4&memorySize=2024"
}
}
}
14 changes: 7 additions & 7 deletions examples/pos-mainchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@
}
},
"dependencies": {
"@liskhq/lisk-framework-dashboard-plugin": "^0.2.0-alpha.7",
"@liskhq/lisk-framework-faucet-plugin": "^0.2.0-alpha.7",
"@liskhq/lisk-framework-forger-plugin": "^0.3.0-alpha.7",
"@liskhq/lisk-framework-monitor-plugin": "^0.3.0-alpha.7",
"@liskhq/lisk-framework-report-misbehavior-plugin": "^0.3.0-alpha.7",
"@liskhq/lisk-framework-dashboard-plugin": "^0.2.0-beta.1",
"@liskhq/lisk-framework-faucet-plugin": "^0.2.0-beta.1",
"@liskhq/lisk-framework-forger-plugin": "^0.3.0-beta.1",
"@liskhq/lisk-framework-monitor-plugin": "^0.3.0-beta.1",
"@liskhq/lisk-framework-report-misbehavior-plugin": "^0.3.0-beta.1",
"@oclif/core": "1.20.4",
"@oclif/plugin-autocomplete": "1.3.6",
"@oclif/plugin-help": "5.1.19",
"@oclif/plugin-version": "1.1.3",
"axios": "1.2.0",
"fs-extra": "11.1.0",
"inquirer": "8.2.5",
"lisk-commander": "^6.0.0-alpha.7",
"lisk-sdk": "^6.0.0-alpha.7",
"lisk-commander": "^6.0.0-beta.1",
"lisk-sdk": "^6.0.0-beta.1",
"tar": "6.1.12",
"tslib": "2.4.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ export const getContradictingBlockHeader = async (
});
});
for (const header2 of existingHeaders) {
const contradicting = await apiClient.invoke('bft_areHeadersContradicting', {
const { valid } = await apiClient.invoke<{ valid: boolean }>('chain_areHeadersContradicting', {
header1,
header2,
});
if (contradicting) {
if (valid) {
return BlockHeader.fromBytes(Buffer.from(header2, 'hex'));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ReportMisbehaviorPluginConfig, State } from './types';
// eslint-disable-next-line prefer-destructuring
const validator: liskValidator.LiskValidator = liskValidator.validator;

const { encrypt, legacy } = cryptography;
const { encrypt, ed } = cryptography;

export class Endpoint extends BasePluginEndpoint {
private _state!: State;
Expand All @@ -37,22 +37,23 @@ export class Endpoint extends BasePluginEndpoint {

// eslint-disable-next-line @typescript-eslint/require-await
public async authorize(context: PluginEndpointContext): Promise<{ result: string }> {
validator.validate(actionParamsSchema, context.params);
validator.validate<{ enable: boolean; password: string }>(actionParamsSchema, context.params);

const { enable, password } = context.params;

try {
const parsedEncryptedPassphrase = encrypt.parseEncryptedMessage(
this._config.encryptedPassphrase,
const parsedEncryptedPrivateKey = encrypt.parseEncryptedMessage(
this._config.encryptedPrivateKey,
);

const passphrase = await encrypt.decryptMessageWithPassword(
parsedEncryptedPassphrase as any,
password as string,
const privateKeyStr = await encrypt.decryptMessageWithPassword(
parsedEncryptedPrivateKey,
password,
'utf-8',
);
const privateKey = Buffer.from(privateKeyStr, 'hex');

const { publicKey, privateKey } = legacy.getPrivateAndPublicKeyFromPassphrase(passphrase);
const publicKey = ed.getPublicKeyFromPrivateKey(privateKey);

this._state.publicKey = enable ? publicKey : undefined;
this._state.privateKey = enable ? privateKey : undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,11 @@ export class ReportMisbehaviorPlugin extends BasePlugin<ReportMisbehaviorPluginC
decodedBlockHeader: chain.BlockHeader,
): Promise<string> {
// ModuleID:13 (PoS), CommandID:3 (PoMCommand)
const posMeta = this.apiClient.metadata.find(
m => m.id === Buffer.from([0, 0, 0, 13]).toString('hex'),
);
const posMeta = this.apiClient.metadata.find(m => m.name === 'pos');
if (!posMeta) {
throw new Error('PoS module is not registered in the application.');
}
const pomParamsInfo = posMeta.commands.find(
m => m.id === Buffer.from([0, 0, 0, 3]).toString('hex'),
);
const pomParamsInfo = posMeta.commands.find(m => m.name === 'reportMisbehavior');
if (!pomParamsInfo?.params) {
throw new Error('PoM params schema is not registered in the application.');
}
Expand All @@ -146,12 +142,12 @@ export class ReportMisbehaviorPlugin extends BasePlugin<ReportMisbehaviorPluginC
}

const authAccount = await this.apiClient.invoke<{ nonce: string }>('auth_getAuthAccount', {
address: address.getAddressFromPublicKey(this._state.publicKey).toString('hex'),
address: address.getLisk32AddressFromPublicKey(this._state.publicKey),
});

const pomTransactionParams = {
header1: decodedBlockHeader,
header2: contradictingBlock,
header1: decodedBlockHeader.getBytes(),
header2: contradictingBlock.getBytes(),
};

const { chainID } = await this.apiClient.invoke<{ chainID: string }>('system_getNodeInfo');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const configSchema = {
type: 'integer',
description: 'Frequency of cleaning up the outdated data in second.',
},
encryptedPassphrase: {
encryptedPrivateKey: {
type: 'string',
format: 'encryptedPassphrase',
description: 'Encrypted private key of the account sending transaction',
},
defaultPassword: {
type: 'string',
Expand All @@ -35,7 +35,7 @@ export const configSchema = {
required: [],
default: {
clearBlockHeadersInterval: 60000,
encryptedPassphrase: '',
encryptedPrivateKey: '',
defaultPassword: '',
fee: 100000000,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

export interface ReportMisbehaviorPluginConfig {
readonly encryptedPassphrase: string;
readonly encryptedPrivateKey: string;
readonly defaultPassword: string;
readonly fee: number;
readonly clearBlockHeadersInterval: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Send PoM transaction should create pom transaction for given block headers 1`] = `"0a03706f73121a7265706f727456616c696461746f724d69736265686176696f7218002080c2d72f2a2031048f87ca35a00a553633dd03c788d4b82ea9caf6ccc36315cf8e595f3e7a8332b6040a980208021064186422203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989902a1440ff452fae2affe6eeef3c30e53e9eac35a1bc4332203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989903a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e6589899042203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989904a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989905020580060006a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989907206080012001a007a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e6589899012980208021064186422203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989902a1440ff452fae2affe6eeef3c30e53e9eac35a1bc4332203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989903a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e6589899042203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989904a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989905032580060006a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989907206080012001a007a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989903a40fbc4b3864cb4bf331bf10bbd9fcd8107590b4272fc2868efcad95a0eb7e036b84aaff63a02ad15e9d89e7085621392e1e065c1ab29a54a4ab01f1851be5c9b0f"`;
exports[`Send PoM transaction should create pom transaction for given block headers 1`] = `"0a03706f7312117265706f72744d69736265686176696f7218002080c2d72f2a2031048f87ca35a00a553633dd03c788d4b82ea9caf6ccc36315cf8e595f3e7a8332b6040a980208021064186422203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989902a1440ff452fae2affe6eeef3c30e53e9eac35a1bc4332203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989903a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e6589899042203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989904a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989905020580060006a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989907206080012001a007a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e6589899012980208021064186422203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989902a1440ff452fae2affe6eeef3c30e53e9eac35a1bc4332203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989903a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e6589899042203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989904a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989905032580060006a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989907206080012001a007a203d1b5dd1ef4ff7b22359598ebdf58966a51adcc03e02ad356632743e658989903a406655c16821ac902c45a9989d6422b860fb43336a1cd61e07b59ef640d543878a7009c2d8311af28423206af8709817c284ce853791cafedad3e1692ba8e9450a"`;
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const appConfigForPlugin: ApplicationConfigForPlugin = {

const validPluginOptions = {
...configSchema.default,
encryptedPassphrase:
'kdf=argon2id&cipher=aes-256-gcm&version=1&ciphertext=11ac52fe63e95e996a845dbe01de2913fe16d7722008a998fbfb5722be1cb358d67810c7a71b22be167715018458d5705a8242ca18fcb9faa00b3b0dce57c2b7aa4c835b41529a0203598f10f5b8e911&mac=9f7f88d5f4e488dcc27d3d4a1176086e04a0f6ddf2f5bd90890e5002156dd096&salt=8e65503565a1f2352c13cf42c22e6f7c&iv=303a8a37e47fa8517c50fc00&tag=1f9c18ea7cb1dc64c5cabb7fa3ba73f5&iterations=1&parallelism=4&memorySize=2024',
encryptedPrivateKey:
'kdf=argon2id&cipher=aes-256-gcm&version=1&ciphertext=35ab87e625765cb46a2fa07c46321f79451587fb22407b535c3ce3d395ce955892e41c93cec994c9292d471b383f5fdee8a33d5e5d685bf2d9e3a88e93ea9117b6cf1feed9d87e8ca31dea6ae7bf28139ce6fa688b3cda97adf892a0b4e2b9b6d46ac26b2f3874f740c102ad4cc75f0ff3ddc2d09fab24ed3c0ae7f0cc16f10a&mac=56e406e2a3e79c518f697c9a7652abd1b6e40f4ae64471050981d109a95b64b0&salt=c56842e8189a53b26517fb284075c77e&iv=593b08e0ae2239e57e1fba51&tag=a04e2e1617581eb95fb17cc14877202c&iterations=1&parallelism=4&memorySize=2024',
dataPath: '/my/app',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*
* Removal or modification of this copyright notice is prohibited.
*/

import { utils } from '@liskhq/lisk-cryptography';
import { testing, chain, ApplicationConfigForPlugin } from 'lisk-sdk';
import { when } from 'jest-when';

Expand Down Expand Up @@ -89,25 +87,21 @@ describe('Send PoM transaction', () => {
},
metadata: [
{
id: utils.intToBuffer(13, 4).toString('hex'),
name: 'pos',
commands: [
{
id: utils.intToBuffer(3, 4).toString('hex'),
name: 'reportValidatorMisbehavior',
name: 'reportMisbehavior',
params: {
$id: '/lisk/pos/pom',
type: 'object',
required: ['header1', 'header2'],
properties: {
header1: {
...chain.blockHeaderSchema,
$id: 'blockHeader1',
dataType: 'bytes',
fieldNumber: 1,
},
header2: {
...chain.blockHeaderSchema,
$id: 'blockHeader2',
dataType: 'bytes',
fieldNumber: 2,
},
},
Expand Down Expand Up @@ -150,7 +144,6 @@ describe('Send PoM transaction', () => {
},
metadata: [
{
id: utils.intToBuffer(13, 4).toString('hex'),
name: 'pos',
commands: [],
},
Expand Down
9 changes: 6 additions & 3 deletions framework/src/engine/endpoint/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ export class ChainEndpoint {

// eslint-disable-next-line @typescript-eslint/require-await
public async areHeadersContradicting(context: RequestContext): Promise<{ valid: boolean }> {
validator.validate(areHeadersContradictingRequestSchema, context.params);
validator.validate<{ header1: string; header2: string }>(
areHeadersContradictingRequestSchema,
context.params,
);

const bftHeader1 = BlockHeader.fromBytes(Buffer.from(context.params.header1 as string, 'hex'));
const bftHeader2 = BlockHeader.fromBytes(Buffer.from(context.params.header2 as string, 'hex'));
const bftHeader1 = BlockHeader.fromBytes(Buffer.from(context.params.header1, 'hex'));
const bftHeader2 = BlockHeader.fromBytes(Buffer.from(context.params.header2, 'hex'));

if (bftHeader1.id.equals(bftHeader2.id)) {
return { valid: false };
Expand Down
5 changes: 5 additions & 0 deletions framework/test/unit/engine/generator/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ describe('generator endpoint', () => {
data: await encrypt.encryptAES256GCMWithPassword(
codec.encode(plainGeneratorKeysSchema, defaultKeys),
defaultPassword,
{
kdfparams: {
memorySize: 2048,
},
},
),
};

Expand Down

0 comments on commit 8b8df42

Please sign in to comment.