Skip to main content

Python implementation of Foundry using python web3 module

Project description

foundpy

Foundpy is a Python implementation of a popular toolkit Foundry. It replicates Foundry's core functionality without needing Foundry's installation. Foundpy enables users to use Python's web3 module with similar command style as Foundry. Foundpy is also equipped with extra features that is primarily used in CTF challenges.

from foundpy import *
config.setup(
    rpc_url="http://rpc.url/",
    privkey="0xdeadbeef"
)
setup_addr = "0xE162F3696944255cc2850eb73418D34023884D1E"
cast.send(setup_addr, "solve(bytes)", b"args123")
cast.call(setup_addr, "isSolved()")

Installation

foundpy can be installed using pip:

pip install foundpy

Usage

Initialization

foundpy is best used with jupyter notebooks. But it can be used in a python script as well.

First, initialize the configuration with the RPC and your private key:

from foundpy import *
config.setup(
    rpc_url="http://rpc.url/",
    privkey="0xdeadbeef"
)

if you want to change the version of the solidity compiler, you can use the config.change_solc_version() function:

config.change_solc_version("0.8.13")

if you are doing a CTF Challenges and it uses the TCP1P ParadigmCTF Infra, you can use the config.from_tcp1p function instead of config.setup

result = config.from_tcp1p("http://103.178.153.113:30001")
setup = Contract(result["setup_contract"], "Setup.Sol")

also if you are playing HackTheBox challenges, you can use the config.from_htb function

result = config.from_htb(address="http://94.237.59.180:51929")
setup = Contract(result["setupAddress"], "Setup.Sol")

Once you have solved the challenges, simply call the config.flag() function

assert setup.call("isSolved")
print(config.flag())

Interacting with Contracts

To interact with a contract, you can either use the cast object or instantiate a Contract object (source code required).

setup_addr = "0xE162F3696944255cc2850eb73418D34023884D1E"
cast.send(setup_addr, "solve(bytes)", b"args123" value=ether(0.5))
# or
setup = Contract(setup_addr, "Setup.Sol") # or "Setup.Sol:Setup" to specify the class
setup.send("solve", b"args123", value=ether(0.5))

Deploying Contracts

To deploy a contract, you can either use the forge object or use the deploy_contract function. Simply make sure that the contract's source code is in the same directory as the script. The constructor arguments can be passed by adding them to the function call after the filename.

# This will return an address
attack = forge.create("Attack.sol:Attack", setup_addr, value=ether(1))
# or
# This will return a Contract object, which you can interact with attack.call or attack.send
attack = deploy_contract("Attack.sol", setup.address, value=ether(1)) # or "Attack.Sol:Attack" to specify the class

You can check for more examples in the example directory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foundpy-0.2.5.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

foundpy-0.2.5-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file foundpy-0.2.5.tar.gz.

File metadata

  • Download URL: foundpy-0.2.5.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.9

File hashes

Hashes for foundpy-0.2.5.tar.gz
Algorithm Hash digest
SHA256 792d339fe65247258c61dba2f516b14c0e44381b3c49f7b81a1a9aaf72d1f665
MD5 972c3e2f33018a5720e2c98f94109b2b
BLAKE2b-256 3d45b66abfbe292dd65626cd1fb7ec18c0dee0d12dd47f298fa0e5882f10afec

See more details on using hashes here.

File details

Details for the file foundpy-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: foundpy-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.9

File hashes

Hashes for foundpy-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d88bad0b63e523badba596c1b18a9f81a50a261c6d5b8b61f937be47f76f5bba
MD5 ae6f4d10757d2f4865afb86a1a670368
BLAKE2b-256 f01416e5c516e8aff96ed31bf28588b3c71943bcc22f2785e80c3eb094d7988d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page