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

feat: add contract verification with standard json input #304

Closed
wants to merge 2 commits into from

Conversation

hangleang
Copy link

@hangleang hangleang commented Sep 8, 2024

What I did

reference to this feature issue #267

How I did it

as the one that don't have any background with Python before, I need to search alot and honestly, asked GPT alot, but not copy the whole thing, and create a PR, and done, not like that. let get to the point:

Following on the requirements of the feature issue, which is verify via vyper standard json input:

How to verify it

there is an integration test to verify recent deployed simple_contract on blockscout in test_sepolia_env.py file

Description for the changelog

  • introduce verify flag to deploy function in VyperDeployer class
  • add a few new ENV,
    • ETHERSCAN_API_KEY: api key for verifying on etherscan or etherscan-liked block explorer
    • ETHERSCAN_API_URL: custom api url for etherscan-liked block explorer
    • BLOCKSCOUT_API_URL: base api url for blockscout explorer. e.g. https://eth-sepolia.blockscout.com on ethereum sepolia
  • add verify function in VyperContract class with the same function signature on the reference issue, which point to below functions based on given params
  • add _verify_blockscout internal function in VyperContract class with no args need, since it is only need the correct API URL and correct request payload for it to work properly
  • add _verify_etherscan internal function in VyperContract class with api_key pass through from the verify parent function. At the time of writing, it is not functioning yet, will include in the future commits

2024-09-08-141409_screenshot

link to verified contract on blockscout explorer: https://eth-sepolia.blockscout.com/address/0x3650800AE650D9D7A482d5bf32525774fb982725
link to bounty on bountycaster: https://www.bountycaster.xyz/bounty/0x85ef641ecf3680980c65fd2f3db0b0122d716934

@hangleang
Copy link
Author

@charles-cooper could you please review it again? I have updated to add delay for block confirmation before verifying the contract.

@@ -85,10 +89,13 @@ def __init__(self, compiler_data, filename=None):
def __call__(self, *args, **kwargs):
return self.deploy(*args, **kwargs)

def deploy(self, *args, **kwargs):
return VyperContract(
def deploy(self, *args, verify=False, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify could be a list of explorer names

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I follow the reference issue linked in the description

"settings": self.compiler_data.settings
})

# constructing the request body for verification
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented it out for now since it's not working yet, I'm not sure whether you read the description or not

source_code = json.dumps({
"language": "Vyper",
"sources": {
self.filename: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only supports a single file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in a single contract

# "contractname": f"{self.filename}:{self.contract_name}",
# "compilerversion": self.compiler_data.settings.compiler_version,
# }
body = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeahhh!


# NOTE: comment these fuzz tests for now to test verifying contract
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what? besides not adding tests, this is disabling existing ones?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for comment is to reduce cost on fuzz test txn, as I try to make sure the verification really works, will enable it back soon if you want.

You might prefer LLM code than the hands-written one

@hangleang hangleang closed this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants