Skip to content

Commit

Permalink
fix: move fallback optimizing for size to optimizer section (#687)
Browse files Browse the repository at this point in the history
* fix: move fallback optimizing for size to optimizer section

* fix: remove only for tests

---------

Co-authored-by: Mimi TxFusion <milivoje@txfusion.com>
Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent b759f0e commit a1ab511
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/hardhat-zksync-chai-matchers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"outDir": "./dist",
"esModuleInterop": true,
"skipLibCheck": true
},
"exclude": ["./dist", "./node_modules"]
}
4 changes: 2 additions & 2 deletions packages/hardhat-zksync-solc/src/compile/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export async function compileWithBinary(
solcPath: string,
detectMissingLibrariesMode: boolean = false,
): Promise<any> {
const { compilerPath, isSystem, forceEvmla, fallbackOz } = config.settings;
const { compilerPath, isSystem, forceEvmla} = config.settings;

const processCommand = `${compilerPath} --standard-json ${isSystem ? '--system-mode' : ''} ${
forceEvmla ? '--force-evmla' : ''
} ${fallbackOz ? '--fallback-Oz' : ''} --solc ${solcPath} ${
} --solc ${solcPath} ${
detectMissingLibrariesMode ? '--detect-missing-libraries' : ''
}`;

Expand Down
3 changes: 0 additions & 3 deletions packages/hardhat-zksync-solc/src/compile/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ export async function compileWithDocker(
if (zksolcConfig.settings.forceEvmla) {
command.push('--force-evmla');
}
if (zksolcConfig.settings.fallbackOz) {
command.push('--fallback-Oz');
}

// @ts-ignore
const dockerInstance: Docker = docker._docker;
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-zksync-solc/src/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import { compileWithBinary } from './binary';
export async function compile(zksolcConfig: ZkSolcConfig, input: CompilerInput, solcPath?: string) {
let compiler: ICompiler;
if (
zksolcConfig.settings.fallbackOz &&
zksolcConfig.settings.optimizer?.fallback_to_optimizing_for_size &&
semver.lt(zksolcConfig.version, ZKSOLC_COMPILER_MIN_VERSION_WITH_FALLBACK_OZ)
) {
throw new ZkSyncSolcPluginError(
`FallbackOz option is not supported for zksolc compiler version ${zksolcConfig.version}. Please use version ${ZKSOLC_COMPILER_MIN_VERSION_WITH_FALLBACK_OZ} or higher.`,
`fallback_to_optimizing_for_size option in optimizer is not supported for zksolc compiler version ${zksolcConfig.version}. Please use version ${ZKSOLC_COMPILER_MIN_VERSION_WITH_FALLBACK_OZ} or higher.`,
);
}
if (zksolcConfig.compilerSource === 'binary') {
Expand Down
2 changes: 0 additions & 2 deletions packages/hardhat-zksync-solc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export interface ZkSolcConfig {
enabled?: boolean;
[key: string]: any;
};
// Try to recompile with -Oz if the bytecode is too large.
fallbackOz?: boolean;
// Remove metadata hash from bytecode. If the option is ommited, the metadata hash will be appended by default.
metadata?: {
bytecodeHash?: 'none';
Expand Down
14 changes: 9 additions & 5 deletions packages/hardhat-zksync-solc/test/tests/compile/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ describe('compile', () => {
}
});

it('should throw an error for unsupported zksolc compiler version with fallbackOz', async () => {
it('should throw an error for unsupported zksolc compiler version with fallback_to_optimizing_for_size', async () => {
const zksolcConfig: ZkSolcConfig = {
compilerSource: 'binary',
version: '1.3.16',
settings: {
fallbackOz: true,
optimizer: {
fallback_to_optimizing_for_size: true,
},
},
};

Expand All @@ -107,17 +109,19 @@ describe('compile', () => {
expect.fail('Expected ZkSyncSolcPluginError to be thrown');
} catch (error: any) {
expect(error.message).to.equal(
'FallbackOz option is not supported for zksolc compiler version 1.3.16. Please use version 1.3.21 or higher.',
'fallback_to_optimizing_for_size option in optimizer is not supported for zksolc compiler version 1.3.16. Please use version 1.3.21 or higher.',
);
}
});

it('should zksolc compiler compile with fallbackOz', async () => {
it('should zksolc compiler compile with fallback_to_optimizing_for_size', async () => {
const zksolcConfig: ZkSolcConfig = {
compilerSource: 'binary',
version: '1.3.21',
settings: {
fallbackOz: true,
optimizer: {
fallback_to_optimizing_for_size: true,
},
},
};

Expand Down

0 comments on commit a1ab511

Please sign in to comment.