Skip to content

Commit 7c46d90

Browse files
committed
Added environment configuration and script for cross-chain policy generation using AI agent
1 parent 5750638 commit 7c46d90

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Google API key
2+
GOOGLE_API_KEY=<YOUR_GOOGLE_API_KEY>
3+
# Google model
4+
GOOGLE_MODEL=gemini-2.0-flash
5+
6+
# OpenAI API key
7+
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
8+
# OpenAI model
9+
OPENAI_MODEL=gpt-4o-mini
10+
11+
# Local prompt file path inside the analyzer container (relative or absolute)
12+
PROMPT_FILE=prompts/agent_prompt.md
13+
14+
# Optional: verbosity / debug
15+
LOG_LEVEL=INFO
16+
17+
# Default output file path used when --output-file is not provided
18+
OUTPUT_FILE=output/results.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.external
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
#!/usr/bin/env bash
3+
set -euo pipefail
4+
5+
# - Clones https://github.com/merendamattia/crosschain-policy-agent
6+
# - Builds a Docker image and runs it for each bridge folder found under BRIDGES_ROOT
7+
# - Outputs per-bridge policy files into OUTPUT_ROOT
8+
9+
# -----------------------------
10+
# Configuration (edit these variables directly)
11+
BRIDGES_ROOT="/Users/mere/git/evm-lisa/datasets/cross-chain/smartaxe/manually-labeled"
12+
REPO_TAG="v1.1.1"
13+
REPO_URL="https://github.com/merendamattia/crosschain-policy-agent.git"
14+
CLONE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/.external/crosschain-policy-agent-${REPO_TAG}"
15+
IMAGE_TAG="crosschain-agent:${REPO_TAG}"
16+
OUTPUT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/outputs/generated-policies-${REPO_TAG}"
17+
ENV_FILE=".env"
18+
19+
# Set DRY_RUN=1 to only print commands instead of executing them
20+
DRY_RUN=0
21+
# Delay (seconds) between operations to avoid API rate limits / too many operations per minute
22+
DELAY_SECONDS=20
23+
# -----------------------------
24+
25+
log() { printf "[%s] %s\n" "$(date --iso-8601=seconds 2>/dev/null || date)" "$*"; }
26+
27+
if [[ -z "$BRIDGES_ROOT" || ! -d "$BRIDGES_ROOT" ]]; then
28+
echo "ERROR: please set BRIDGES_ROOT to an existing directory inside this script." >&2
29+
exit 2
30+
fi
31+
32+
mkdir -p "$(dirname "$CLONE_DIR")"
33+
mkdir -p "$OUTPUT_ROOT"
34+
35+
command -v git >/dev/null 2>&1 || { echo "ERROR: git not found. Install git." >&2; exit 3; }
36+
command -v docker >/dev/null 2>&1 || { echo "ERROR: docker not found. Install Docker." >&2; exit 4; }
37+
38+
log "Bridges root: $BRIDGES_ROOT"
39+
log "Clone dir: $CLONE_DIR"
40+
log "Output root: $OUTPUT_ROOT"
41+
42+
# Clone or update the repository at the specific tag
43+
if [[ -d "$CLONE_DIR/.git" ]]; then
44+
log "Repository already cloned. Fetching tags and checking out $REPO_TAG"
45+
set +e
46+
git -C "$CLONE_DIR" fetch --tags --prune
47+
git -C "$CLONE_DIR" checkout "$REPO_TAG"
48+
git -C "$CLONE_DIR" reset --hard
49+
set -e
50+
else
51+
log "Cloning $REPO_URL $REPO_TAG into $CLONE_DIR"
52+
git clone --depth 1 --branch "$REPO_TAG" "$REPO_URL" "$CLONE_DIR"
53+
fi
54+
55+
# Decide env-file usage (ENV_FILE can be left empty to skip)
56+
if [[ -n "$ENV_FILE" && ! -f "$ENV_FILE" ]]; then
57+
echo "ERROR: ENV_FILE is set but file does not exist: $ENV_FILE" >&2
58+
exit 5
59+
fi
60+
61+
# Build docker image
62+
log "Building Docker image: $IMAGE_TAG (context: $CLONE_DIR)"
63+
if [[ $DRY_RUN -eq 1 ]]; then
64+
echo "DRY-RUN: docker build -t $IMAGE_TAG $CLONE_DIR"
65+
else
66+
docker build -t "$IMAGE_TAG" "$CLONE_DIR"
67+
fi
68+
69+
shopt -s nullglob
70+
COUNT=0
71+
for entry in "$BRIDGES_ROOT"/*; do
72+
if [[ -d "$entry" ]]; then
73+
src_dir="$entry/source-code"
74+
if [[ ! -d "$src_dir" ]]; then
75+
log "Skipping $(basename "$entry"): no source-code/ directory found"
76+
continue
77+
fi
78+
79+
sol_files=("$src_dir"/*.sol)
80+
if [[ ${#sol_files[@]} -eq 0 ]]; then
81+
log "Skipping $(basename "$entry"): no .sol files found in source-code/"
82+
continue
83+
fi
84+
85+
bridge_name="$(basename "$entry")"
86+
out_dir="$OUTPUT_ROOT"
87+
mkdir -p "$out_dir"
88+
out_file="$out_dir/${bridge_name}.policy.json"
89+
90+
docker_cmd=(docker run --rm)
91+
if [[ -n "$ENV_FILE" ]]; then
92+
docker_cmd+=(--env-file "$ENV_FILE")
93+
fi
94+
docker_cmd+=(-v "$src_dir:/data/sol:ro")
95+
docker_cmd+=(-v "$out_dir:/app/output")
96+
docker_cmd+=("$IMAGE_TAG")
97+
docker_cmd+=(--target-path /data/sol --output-file /app/output/"${bridge_name}.policy.json")
98+
docker_cmd+=(--client google)
99+
100+
log "Processing bridge: $bridge_name"
101+
log " Source: $entry"
102+
log " Output: $out_file"
103+
104+
if [[ $DRY_RUN -eq 1 ]]; then
105+
printf "DRY-RUN: %s\n" "${docker_cmd[*]}"
106+
else
107+
log "Running: ${docker_cmd[*]}"
108+
"${docker_cmd[@]}"
109+
rc=$?
110+
if [[ $rc -ne 0 ]]; then
111+
echo "WARNING: docker run for $bridge_name exited with code $rc" >&2
112+
else
113+
log "Generated: $out_file"
114+
fi
115+
116+
# Sleep between per-bridge runs to limit operations/minute
117+
if [[ $DRY_RUN -eq 0 && $DELAY_SECONDS -gt 0 ]]; then
118+
log "Sleeping ${DELAY_SECONDS}s before next operation"
119+
sleep "$DELAY_SECONDS"
120+
fi
121+
fi
122+
123+
COUNT=$((COUNT+1))
124+
fi
125+
done
126+
127+
if [[ $COUNT -eq 0 ]]; then
128+
echo "ERROR: no bridges processed. Ensure $BRIDGES_ROOT contains subfolders with .sol files" >&2
129+
exit 6
130+
fi
131+
132+
log "Done. $COUNT bridges processed. Output in: $OUTPUT_ROOT"
133+

0 commit comments

Comments
 (0)