From 43d50454092adb5c02056aecd5cbb0af29207003 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Wed, 15 Jan 2025 11:10:23 -0300 Subject: [PATCH] fix: minor typos --- .../gas-consumption/gas-struct-packing.md | 1 + .../gas-consumption/gas-struct-packing.js | 3 +++ solhint.js | 3 ++- .../gas-consumption/gas-struct-packing.js | 24 ++++++++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/rules/gas-consumption/gas-struct-packing.md b/docs/rules/gas-consumption/gas-struct-packing.md index 313edfc1..9d199fc7 100644 --- a/docs/rules/gas-consumption/gas-struct-packing.md +++ b/docs/rules/gas-consumption/gas-struct-packing.md @@ -25,6 +25,7 @@ This rule accepts a string option of rule severity. Must be one of "error", "war ### Notes - This rule assumes all UserDefinedTypeName take a new slot. (beware of Enums inside Structs) +- Simple cases like a struct with three addresses might be reported as false positive. (needs to be fixed) - [source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing) - [source 2](https://www.rareskills.io/post/gas-optimization?postId=c9db474a-ff97-4fa3-a51d-fe13ccb8fe3b#viewer-f8m1r) of the rule initiative diff --git a/lib/rules/gas-consumption/gas-struct-packing.js b/lib/rules/gas-consumption/gas-struct-packing.js index f8811d54..3b4a1d1e 100644 --- a/lib/rules/gas-consumption/gas-struct-packing.js +++ b/lib/rules/gas-consumption/gas-struct-packing.js @@ -12,6 +12,9 @@ const meta = { { note: 'This rule assumes all UserDefinedTypeName take a new slot. (beware of Enums inside Structs) ', }, + { + note: 'Simple cases like a struct with three addresses might be reported as false positive. (needs to be fixed)', + }, { note: '[source 1](https://coinsbench.com/comprehensive-guide-tips-and-tricks-for-gas-optimization-in-solidity-5380db734404) of the rule initiative (Variable Packing)', }, diff --git a/solhint.js b/solhint.js index bb5b617d..6c172666 100755 --- a/solhint.js +++ b/solhint.js @@ -126,13 +126,14 @@ function executeMainActionLogic() { const customConfig = program.opts().config if (customConfig && !fs.existsSync(customConfig)) { - console.error(`Config file "${customConfig}" couldnt be found.`) + console.error(`Config file "${customConfig}" couldn't be found.`) process.exit(EXIT_CODES.BAD_OPTIONS) } let reports try { const reportLists = program.args.filter(_.isString).map(processPath) + // console.log('reportLists :>> ', reportLists) reports = _.flatten(reportLists) } catch (e) { console.error(e) diff --git a/test/rules/gas-consumption/gas-struct-packing.js b/test/rules/gas-consumption/gas-struct-packing.js index 975119e8..4363777a 100644 --- a/test/rules/gas-consumption/gas-struct-packing.js +++ b/test/rules/gas-consumption/gas-struct-packing.js @@ -2,12 +2,14 @@ const assert = require('assert') const linter = require('../../../lib/index') const TEST_CASES = require('../../fixtures/gas-consumption/gas-struct-packing-data') +// const { contractWith, multiLine } = require('../../common/contract-builder') + const replaceErrorMsg = (variableName) => { const errMsg = `GC: For [ ${variableName} ] struct, packing seems inefficient. Try rearranging to achieve 32bytes slots` return errMsg } -describe('Linter - gas-struct-packingone', () => { +describe('Linter - gas-struct-packing', () => { for (const contract of TEST_CASES.contractStructsInefficient) { it(`should raise error for ${contract.name}`, () => { const code = contract.code @@ -30,4 +32,24 @@ describe('Linter - gas-struct-packingone', () => { assert.equal(report.errorCount, 0) }) } + + // it(`should NOT raise error for `, () => { + // const code = contractWith( + // multiLine( + // // // Large Types Followed by Small Types + // 'struct MyStruct2 {', + // ' address addr1;', + // ' address addr2;', + // ' address addr3;', + // '}' + // ) + // ) + // const report = linter.processStr(code, { + // rules: { 'gas-struct-packing': 'error' }, + // }) + + // console.log(report) + + // // assert.equal(report.errorCount, 0) + // }) })