diff --git a/package/version b/package/version index c29f5f750..72400828d 100644 --- a/package/version +++ b/package/version @@ -1 +1 @@ -0.1.114 +0.1.115 diff --git a/pyproject.toml b/pyproject.toml index 0116c9665..1451ef9fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "kontrol" -version = "0.1.114" +version = "0.1.115" description = "Foundry integration for KEVM" authors = [ "Runtime Verification, Inc. ", diff --git a/src/kontrol/__init__.py b/src/kontrol/__init__.py index f373c1a93..da78439fa 100644 --- a/src/kontrol/__init__.py +++ b/src/kontrol/__init__.py @@ -5,4 +5,4 @@ if TYPE_CHECKING: from typing import Final -VERSION: Final = '0.1.114' +VERSION: Final = '0.1.115' diff --git a/src/kontrol/__main__.py b/src/kontrol/__main__.py index 4c6a9e95f..4ec5a903d 100644 --- a/src/kontrol/__main__.py +++ b/src/kontrol/__main__.py @@ -123,6 +123,8 @@ def exec_summary( contract_names: Path | None, output_dir_name: str | None, foundry_root: Path, + license: str, + comment_generated_file: str, condense_summary: bool = False, **kwargs: Any, ) -> None: @@ -132,6 +134,8 @@ def exec_summary( contract_names=contract_names, output_dir_name=output_dir_name, foundry=_load_foundry(foundry_root), + license=license, + comment_generated_file=comment_generated_file, condense_summary=condense_summary, ) @@ -688,6 +692,20 @@ def _parse_test_version_tuple(value: str) -> tuple[str, int | None]: type=str, help='Path to write summary .sol files, relative to foundry root', ) + summary_args.add_argument( + '--comment-generated-files', + dest='comment_generated_file', + default='// This file was autogenerated by running `kontrol summary`. Do not edit this file manually.\n', + type=str, + help='Comment to write at the top of the auto generated summary files', + ) + summary_args.add_argument( + '--license', + dest='license', + default='UNLICENSED', + type=str, + help='License for the auto generated contracts', + ) prove_args = command_parser.add_parser( 'prove', diff --git a/src/kontrol/deployment.py b/src/kontrol/deployment.py index ed7951ea7..0ec1df4a0 100644 --- a/src/kontrol/deployment.py +++ b/src/kontrol/deployment.py @@ -14,8 +14,10 @@ def __init__(self, name: str, accounts: dict | None = None) -> None: for acc_key in list(self.accounts): self.accounts[acc_key] = self.accounts[acc_key] - def generate_header(self) -> list[str]: + def generate_header(self, comment_generated_file: str, license: str) -> list[str]: lines = [] + lines.append(f'// SPDX-License-Identifier: {license}') + lines.append(comment_generated_file) lines.append(f'pragma solidity {self.SOLIDITY_VERSION};\n') lines.append('import { Vm } from "forge-std/Vm.sol";\n') return lines @@ -58,20 +60,22 @@ def generate_main_contract(self) -> list[str]: lines.append('}') return lines - def generate_condensed_file(self) -> list[str]: - lines = self.generate_header() + def generate_condensed_file(self, comment_generated_file: str, license: str) -> list[str]: + lines = self.generate_header(comment_generated_file, license) lines += self.generate_code_contract() lines += self.generate_main_contract() return lines - def generate_main_contract_file(self) -> list[str]: - lines = self.generate_header() + def generate_main_contract_file(self, comment_generated_file: str, license: str) -> list[str]: + lines = self.generate_header(comment_generated_file, license) lines.append('import { ' + self.name + 'Code } from "./' + self.name + 'Code.sol";') lines += self.generate_main_contract() return lines - def generate_code_contract_file(self) -> list[str]: + def generate_code_contract_file(self, comment_generated_file: str, license: str) -> list[str]: lines = [] + lines.append(f'// SPDX-License-Identifier: {license}') + lines.append(comment_generated_file) lines.append(f'pragma solidity {self.SOLIDITY_VERSION};\n') lines += self.generate_code_contract() return lines diff --git a/src/kontrol/foundry.py b/src/kontrol/foundry.py index 16d2375aa..c4a835624 100644 --- a/src/kontrol/foundry.py +++ b/src/kontrol/foundry.py @@ -786,6 +786,8 @@ def foundry_summary( contract_names: Path | None, output_dir_name: str | None, foundry: Foundry, + license: str, + comment_generated_file: str, condense_summary: bool = False, ) -> None: if not accesses_file.exists(): @@ -808,12 +810,15 @@ def foundry_summary( main_file = output_dir / Path(name + '.sol') + if not license.strip(): + raise ValueError('License cannot be empty or blank') + if condense_summary: - main_file.write_text('\n'.join(summary_contract.generate_condensed_file())) + main_file.write_text('\n'.join(summary_contract.generate_condensed_file(comment_generated_file, license))) else: code_file = output_dir / Path(name + 'Code.sol') - main_file.write_text('\n'.join(summary_contract.generate_main_contract_file())) - code_file.write_text('\n'.join(summary_contract.generate_code_contract_file())) + main_file.write_text('\n'.join(summary_contract.generate_main_contract_file(comment_generated_file, license))) + code_file.write_text('\n'.join(summary_contract.generate_code_contract_file(comment_generated_file, license))) def foundry_section_edge( diff --git a/src/tests/integration/test-data/contracts.k.expected b/src/tests/integration/test-data/contracts.k.expected index 7d0b5525c..52cd5ad6c 100644 --- a/src/tests/integration/test-data/contracts.k.expected +++ b/src/tests/integration/test-data/contracts.k.expected @@ -3138,7 +3138,7 @@ module S2KsrcZModDeploymentSummary-CONTRACT - rule ( #initBytecode ( S2KsrcZModDeploymentSummary ) => #parseByteStack ( "0x608060405234801561001057600080fd5b50610323806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b5b8c44814610030575b600080fd5b61003861003a565b005b6000807f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d60001c6001600160a01b031663b4d6c782735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60405180610140016040528061010681526020016101e861010691396040518363ffffffff1660e01b81526004016100bd929190610182565b600060405180830381600087803b1580156100d757600080fd5b505af11580156100eb573d6000803e3d6000fd5b50506040516370ca10bb60e01b8152735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60048201526000602482018190526003604483018190529095509350737109709ecfa91a80626ff3989d68f67f5b1dd12d92506370ca10bb9150606401600060405180830381600087803b15801561016657600080fd5b505af115801561017a573d6000803e3d6000fd5b505050505050565b60018060a01b038316815260006020604081840152835180604085015260005b818110156101be578581018301518582016060015282016101a2565b818111156101d0576000606083870101525b50601f01601f19169290920160600194935050505056fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820360f2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000aa264697066735822122068ab91daa9ffb5a7d2f0c5e4d0883eb7dcddc4df53678c0ea17294ae87d8c7e564736f6c634300080d0033" ) ) + rule ( #initBytecode ( S2KsrcZModDeploymentSummary ) => #parseByteStack ( "0x608060405234801561001057600080fd5b50610323806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b5b8c44814610030575b600080fd5b61003861003a565b005b6000807f885cb69240a935d632d79c317109709ecfa91a80626ff3989d68f67f5b1dd12d60001c6001600160a01b031663b4d6c782735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60405180610140016040528061010681526020016101e861010691396040518363ffffffff1660e01b81526004016100bd929190610182565b600060405180830381600087803b1580156100d757600080fd5b505af11580156100eb573d6000803e3d6000fd5b50506040516370ca10bb60e01b8152735615deb798bb3e4dfa0139dfa1b3d433cc23b72f60048201526000602482018190526003604483018190529095509350737109709ecfa91a80626ff3989d68f67f5b1dd12d92506370ca10bb9150606401600060405180830381600087803b15801561016657600080fd5b505af115801561017a573d6000803e3d6000fd5b505050505050565b60018060a01b038316815260006020604081840152835180604085015260005b818110156101be578581018301518582016060015282016101a2565b818111156101d0576000606083870101525b50601f01601f19169290920160600194935050505056fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820360f2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000aa264697066735822122065ddb5d6f20688945c5fd013278ae89252bfdb6a75b5b19859708c4163839b6b64736f6c634300080d0033" ) ) syntax Bytes ::= S2KsrcZModDeploymentSummaryContract "." S2KsrcZModDeploymentSummaryMethod [function(), symbol(), klabel(method_src%DeploymentSummary)] @@ -3162,7 +3162,7 @@ module S2KsrcZModDeploymentSummaryCode-CONTRACT - rule ( #initBytecode ( S2KsrcZModDeploymentSummaryCode ) => #parseByteStack ( "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220bf3c83c706325d6596b0b6aaa825b20074dd820772ee9da90f5c6788b8f244c564736f6c634300080d0033" ) ) + rule ( #initBytecode ( S2KsrcZModDeploymentSummaryCode ) => #parseByteStack ( "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea26469706673582212200b7867accb23ecb775c2ab8bb72766ea046d5a6121003d74cfee2c1276ed0e4d64736f6c634300080d0033" ) ) endmodule diff --git a/src/tests/integration/test-data/foundry/src/DeploymentSummary.sol b/src/tests/integration/test-data/foundry/src/DeploymentSummary.sol index 628dee017..48d71d450 100644 --- a/src/tests/integration/test-data/foundry/src/DeploymentSummary.sol +++ b/src/tests/integration/test-data/foundry/src/DeploymentSummary.sol @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +// This file was autogenerated by running `kontrol summary`. Do not edit this file manually. + pragma solidity ^0.8.13; import { Vm } from "forge-std/Vm.sol"; diff --git a/src/tests/integration/test-data/foundry/src/DeploymentSummaryCode.sol b/src/tests/integration/test-data/foundry/src/DeploymentSummaryCode.sol index 4266c04f2..2d6e33af8 100644 --- a/src/tests/integration/test-data/foundry/src/DeploymentSummaryCode.sol +++ b/src/tests/integration/test-data/foundry/src/DeploymentSummaryCode.sol @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +// This file was autogenerated by running `kontrol summary`. Do not edit this file manually. + pragma solidity ^0.8.13; contract DeploymentSummaryCode { diff --git a/src/tests/integration/test_foundry_prove.py b/src/tests/integration/test_foundry_prove.py index eb88d799a..9184f5338 100644 --- a/src/tests/integration/test_foundry_prove.py +++ b/src/tests/integration/test_foundry_prove.py @@ -526,6 +526,8 @@ def test_deployment_summary( TEST_DATA_DIR / 'accesses.json', contract_names=None, output_dir_name='src', + license='UNLICENSED', + comment_generated_file='// This file was autogenerated by running `kontrol summary`. Do not edit this file manually.\n', foundry=foundry, )