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

refactor: Separate generic setup from bounty setup and other stages #193

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/bounties/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ADDER_VERSIONS= safe unsafe
all: $(patsubst %,dist/adder-%-bounty.tar.xz,$(ADDER_VERSIONS))

dist/adder-%-bounty.tar.xz: \
src/adder/setup-exec-env.sh \
src/adder/start.sh \
src/adder/src/IRegistry.sol \
src/adder/src/Registry.sol \
Expand Down
80 changes: 80 additions & 0 deletions tests/bounties/src/adder/setup-exec-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s expand_aliases

SOLC_VERSION=0.8.27

FOUNDRY_REF=2cdbfac
alias cast="cast-$FOUNDRY_REF"
alias forge="forge-$FOUNDRY_REF"

RETH_VERSION=1.0.5
alias reth="reth-$RETH_VERSION"

>&2 echo "Setting up Forge project..."
cp -r src /tmp
cp "$1" /tmp/src/Exploit.sol
cd /tmp

>&2 echo "Building Forge project..."
forge build --use $(which solc-$SOLC_VERSION)

HTTP_ADDR=127.0.0.1
HTTP_PORT=8545

>&2 echo "Starting up Reth..."
reth node \
--dev \
--quiet \
--http.addr $HTTP_ADDR \
--http.port $HTTP_PORT \
--log.file.max-files 0 \
--datadir .local/share/reth &

reth_pid=$!
trap 'kill $reth_pid' EXIT

export ETH_RPC_URL=$HTTP_ADDR:$HTTP_PORT

while true
do
if chain_id=$(cast chain-id 2>/dev/null)
then
if [[ $chain_id == 1337 ]]
then
>&2 echo "Reth is listening."
break
else
>&2 echo "Reth has unexpected chain ID $chain_id."
exit 1
fi
else
if kill -0 $reth_pid
then
>&2 echo "Waiting for Reth to start listening..."
sleep 1
else
>&2 echo "Reth exited..."
exit 1
fi
fi
done

PK=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

deploy() {
forge create --json --private-key "$PK" "$1:$2" | jq -r .deployedTo
}

>&2 echo "Deploying registry contract..."
REGISTRY=$(deploy src/Registry.sol Registry)

send() {
>/dev/null cast send --private-key "$PK" "$@"
}

deploy_and_register() {
address=$(deploy "$@")
send "$REGISTRY" 'set(string,address)' "$2" "$address"
echo "$address"
}
82 changes: 2 additions & 80 deletions tests/bounties/src/adder/start.sh
Original file line number Diff line number Diff line change
@@ -1,83 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s expand_aliases

SOLC_VERSION=0.8.27

FOUNDRY_REF=2cdbfac
alias cast="cast-$FOUNDRY_REF"
alias forge="forge-$FOUNDRY_REF"

RETH_VERSION=1.0.5
alias reth="reth-$RETH_VERSION"

>&2 echo "Setting up Forge project..."
cp -r src /tmp
cp "$1" /tmp/src/Exploit.sol
cd /tmp

>&2 echo "Building Forge project..."
forge build --use $(which solc-$SOLC_VERSION)

HTTP_ADDR=127.0.0.1
HTTP_PORT=8545

>&2 echo "Starting up Reth..."
reth node \
--dev \
--quiet \
--http.addr $HTTP_ADDR \
--http.port $HTTP_PORT \
--log.file.max-files 0 \
--datadir .local/share/reth &

reth_pid=$!
trap 'kill $reth_pid' EXIT

export ETH_RPC_URL=$HTTP_ADDR:$HTTP_PORT

while true
do
if chain_id=$(cast chain-id 2>/dev/null)
then
if [[ $chain_id == 1337 ]]
then
>&2 echo "Reth is listening."
break
else
>&2 echo "Reth has unexpected chain ID $chain_id."
exit 1
fi
else
if kill -0 $reth_pid
then
>&2 echo "Waiting for Reth to start listening..."
sleep 1
else
>&2 echo "Reth exited..."
exit 1
fi
fi
done

PK=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

deploy() {
forge create --json --private-key "$PK" "$1:$2" | jq -r .deployedTo
}

>&2 echo "Deploying registry contract..."
REGISTRY=$(deploy src/Registry.sol Registry)

send() {
>/dev/null cast send --private-key "$PK" "$@"
}

deploy_and_register() {
address=$(deploy "$@")
send "$REGISTRY" 'set(string,address)' "$2" "$address"
echo "$address"
}
source ./setup-exec-env.sh

>&2 echo "Deploying and registering project contracts..."
ADDER=$(deploy_and_register src/Adder.sol Adder)
Expand All @@ -88,7 +10,7 @@ EXPLOIT=$(deploy src/Exploit.sol Exploit)
>&2 echo "Running exploit..."
send "$EXPLOIT" 'run(address)' "$REGISTRY"

>&2 echo "Testing contracts..."
>&2 echo "Verifying contracts after exploit execution..."
number=$(cast call "$ADDER" 'number()(uint256)')

if [ "$number" -eq 0 ]
Expand Down
Loading