Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor the contract digest logic down to the Contract class #739

Open
JuanCoRo opened this issue Aug 2, 2024 · 0 comments
Open

Factor the contract digest logic down to the Contract class #739

JuanCoRo opened this issue Aug 2, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@JuanCoRo
Copy link
Member

JuanCoRo commented Aug 2, 2024

In solc_to_k.py, Constructor and Method are both child classes of Contract. However, both have the contract_up_to_date function, whereas the Contract class doesn't.
This can cause some redundancy, such as the logic introduced in #735 to determine whether the contract's digest is outdated1.

In this particular case, instead of

any(
        not method.contract_up_to_date(Path(method.contract_digest))
        for contract in self.contracts.values()
        for method in contract.methods
    )

we could do something like

any(
       not contract.contract_up_to_date(Path(contract_digest))
       for contract in self.contracts.values()
   )

Taking into account that the digest files look like this:

{
    "methods": {
        "test%CounterTest.test_Increment()": {
            "method": "4c32041fa5a7c64776f36dab5ae8cc61588efc3e3fb09b3c95ed0917587687d6",
            "contract": "29c961bb216d9a5f16961d6a224fd6cb1feeb18b36e29e9a09c2733b0590a655"
        },
        "test%CounterTest.setUp()": {
            "method": "2c1737186c0be7909e9db344314dabfa10f5f492345ad17e87375ed13c1bcaa6",
            "contract": "29c961bb216d9a5f16961d6a224fd6cb1feeb18b36e29e9a09c2733b0590a655"
        },
        "test%CounterTest.testFuzz_SetNumber(uint256)": {
            "method": "323d5de4c923be8a393316579d3833bd4f00d4d81a5a85b3030a54efd2222e87",
            "contract": "29c961bb216d9a5f16961d6a224fd6cb1feeb18b36e29e9a09c2733b0590a655"
        }
    },
    "kompilation": "089cb7a3c95b4643e44147c41139b379b7a69797b3a8cb3d6a9e4acc41fb3bef",
    "kontrol": "0.1.32",
    "foundry": "a7794d1db53643ecf7e89e8be01ca0fcad6ca2cf381e68f4fdbe70d1be6934f9"
}

we might need to factor out the contract field, although not necessarily.

Footnotes

  1. Note that the logic introduced in Add --remove-old-proofs command #735 showcased above is not more inefficient than doing a single lookup per contract since, according to the Python docs, any is evaluated lazily. But it does result in a more verbose/redundant syntax.

@JuanCoRo JuanCoRo added the enhancement New feature or request label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant