Skip to content

Philippe/fix GitHub action enclave test #183

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4278c70
Ensure the steps for running the tests in the enclave are run in sequ…
philippecamacho Jun 23, 2025
a5be428
Avoid logic redundancy
philippecamacho Jun 23, 2025
1caadb9
Refactor running tests in EC2 instance.
philippecamacho Jun 23, 2025
d1c32c0
Fix timeout assignation.
philippecamacho Jun 23, 2025
4ef5f77
Checkout the repository inside github actions.
philippecamacho Jun 23, 2025
9b8fa6d
Put checkout repository as a single step at the beginning.
philippecamacho Jun 23, 2025
784f108
Pinpoint version of aws-nitro-enclaves-cli
philippecamacho Jun 23, 2025
944a3c4
Fix version nitro cli for installation.
philippecamacho Jun 23, 2025
875e1c3
Upgrade image of Espresso node.
philippecamacho Jun 23, 2025
6ce0502
Switch to a slower but more reliable build for contracts.
philippecamacho Jun 24, 2025
eb2fc90
Don't build the tests contracts
philippecamacho Jun 24, 2025
32d650a
Compile contracts first and then run the tests.
philippecamacho Jun 24, 2025
c9eab50
Fix attempt
philippecamacho Jun 24, 2025
b250f6e
Other attempt
philippecamacho Jun 24, 2025
6af5af1
Fix
philippecamacho Jun 24, 2025
39b4759
Improvements
philippecamacho Jun 24, 2025
265cda7
Fix bug #4736 of foundry. Faster execution of commands inside nix shell.
philippecamacho Jun 24, 2025
81fa274
Fix call to nix develop
philippecamacho Jun 24, 2025
876b911
Fix nix develop command. Add some log message to get the batch authen…
philippecamacho Jun 24, 2025
b2f8cd9
Fix to install svm.
philippecamacho Jun 24, 2025
4c6b782
Define cargo in flake.nix in order to be able to install svm.
philippecamacho Jun 24, 2025
f6d76f4
Regenerate the bindings for batch authenticator contract.
philippecamacho Jun 24, 2025
4fb4aec
Sleep 5s before running the tests.
philippecamacho Jun 24, 2025
d89ce0b
Cachix configuration
philippecamacho Jun 24, 2025
3c0f433
Echo variable
philippecamacho Jun 24, 2025
1187fca
Fix cachix configuration
philippecamacho Jun 24, 2025
de5e285
Fix permission issue
philippecamacho Jun 24, 2025
2190b74
Another fix for cachix
philippecamacho Jun 24, 2025
a6c68d6
Poblate Cachix cache
philippecamacho Jun 24, 2025
b407915
Fix
philippecamacho Jun 24, 2025
12e211b
Fix order of commands
philippecamacho Jun 24, 2025
82a8112
Fix order again
philippecamacho Jun 24, 2025
6e59224
Create directory for nix config earlier.
philippecamacho Jun 24, 2025
e6c235d
Another try
philippecamacho Jun 24, 2025
a1fd1fa
Use organization CACHIX_AUTH_TOKEN.
philippecamacho Jun 24, 2025
ed56955
Use old Espresso Node image.
philippecamacho Jun 24, 2025
07e328c
Hardcode gas limit in tx to register batcher.
philippecamacho Jun 24, 2025
60e6056
Try to fix issue https://github.com/foundry-rs/foundry/issues/4736
philippecamacho Jun 24, 2025
bd0f1e4
Better fix workaround for foundry bug.
philippecamacho Jun 25, 2025
968fb44
Check if batch authenticator contract has been deployed.
philippecamacho Jun 25, 2025
78f5dad
Fix workaround and update bindings
philippecamacho Jun 25, 2025
32e7489
Install more solidity versions.
philippecamacho Jun 25, 2025
ebe127b
Add missing solidity version
philippecamacho Jun 25, 2025
56a6ee7
Trying to use pre-installed AMI.
philippecamacho Jun 26, 2025
80742e9
Document how to create AMI.
philippecamacho Jul 2, 2025
1afe44c
Remove gas limit in espresso batcher logic.
philippecamacho Jul 2, 2025
0351855
Update version of espresso node image.
philippecamacho Jul 2, 2025
1e63fc6
Update espresso-tee module version.
philippecamacho Jul 2, 2025
0f10fb8
Revert "Update version of espresso node image."
philippecamacho Jul 2, 2025
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
58 changes: 13 additions & 45 deletions .github/workflows/enclave.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Checkout repository
uses: actions/checkout@v4

- uses: aws-actions/configure-aws-credentials@v4
name: configure aws credentials
with:
Expand Down Expand Up @@ -69,7 +73,7 @@ jobs:
- name: Launch EC2 Instance
id: ec2
run: |
AMI_ID=ami-0fe972392d04329e1
AMI_ID=ami-0ff5662328e9bbc2f
INSTANCE_ID=$(aws ec2 run-instances \
--image-id "$AMI_ID" \
--count 1 \
Expand All @@ -96,53 +100,17 @@ jobs:
echo "DNS=$DNS" >> $GITHUB_ENV
echo "dns=$DNS" >> $GITHUB_OUTPUT

- name: Install dependencies
run: |
echo "Current branch: $BRANCH_NAME"
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS << EOF
set -e
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon
source ~/.bashrc
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
sudo yum update
sudo yum install git -y
sudo yum install docker -y
sudo amazon-linux-extras install aws-nitro-enclaves-cli -y
git clone https://github.com/EspressoSystems/optimism-espresso-integration.git
cd optimism-espresso-integration
git checkout "$BRANCH_NAME"
git submodule update --init --recursive
nix develop
EOF

- name: Configure and start enclave service
- name: Upload run-tests.sh to EC2
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS << 'EOF'
set -e
sudo nitro-cli --version
sudo systemctl stop nitro-enclaves-allocator.service
echo -e '---\nmemory_mib: 4096\ncpu_count: 2' | sudo tee /etc/nitro_enclaves/allocator.yaml
sudo systemctl start nitro-enclaves-allocator.service
EOF

- name: Start docker service
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS << 'EOF'
set -e
sudo usermod -a -G docker ec2-user
sudo service docker start
sudo chown ec2-user /var/run/docker.sock
EOF
scp -o StrictHostKeyChecking=no -i key.pem espresso/scripts/run-tests-github-actions.sh ec2-user@$DNS:/home/ec2-user/
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@$DNS "chmod +x run-tests-github-actions.sh"

# Compile contracts first to avoid text file busy error
- name: Run tests
- name: Run test script on EC2
timeout-minutes: 40
run: |
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -i key.pem ec2-user@$DNS << 'EOF'
set -e
cd /home/ec2-user/optimism-espresso-integration
nix develop --command just compile-contracts
nix develop --command just espresso-enclave-tests
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=5 -i key.pem ec2-user@$DNS << EOF
export BRANCH_NAME=$BRANCH_NAME
./run-tests-github-actions.sh ${{ secrets.CACHIX_AUTH_TOKEN }}
EOF

- name: Terminate EC2 instance
Expand Down
6 changes: 6 additions & 0 deletions README_ESPRESSO.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,9 @@ In order to run the tests for the enclave in EC2 via github actions one must cre
]
}
```

Currently, the github workflow in `.github/workflows/enclave.yaml` relies on a custom AWS AMI with id `ami-0ff5662328e9bbc2f`.
In order to refresh this AMI one needs to:
1. Create an AWS EC2 instance with the characteristics described in (see `.github/workflows/enclave.yaml` *Launch EC2 Instance* job).
2. Copy the script `espresso/scrips/enclave-prepare-ami.sh` in the EC2 instance (e.g. using scp) and run it.
3. [Export the AMI instance](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/tkv-create-ami-from-instance.html).
30 changes: 30 additions & 0 deletions espresso/scripts/enclave-prepare-ami.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail
set -x

echo "[*] Setting up Nix"
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon --no-confirm
source /etc/profile.d/nix.sh
nix-env -iA cachix -f https://cachix.org/api/v1/install
mkdir -p ~/.config/nix
echo "trusted-users = root ec2-user" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon


echo "[*] Installing dependencies..."
sudo yum update -y
sudo yum install -y git docker
sudo amazon-linux-extras enable aws-nitro-enclaves-cli
sudo yum install -y aws-nitro-enclaves-cli-1.4.2


# Workaround due to https://github.com/foundry-rs/foundry/issues/4736
sudo yum install -y gcc
curl https://sh.rustup.rs -sSf | sh -s -- -y
. $HOME/.cargo/env
cargo install svm-rs
svm install 0.8.15
svm install 0.8.19
svm install 0.8.22
svm install 0.8.25
svm install 0.8.28
svm install 0.8.30
31 changes: 31 additions & 0 deletions espresso/scripts/run-tests-github-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -euo pipefail
set -x

echo "[*] Setting up Cachix"
cachix authtoken $1
cachix use espresso-systems-private
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf

echo "[*] Cloning repo and checking out branch $BRANCH_NAME..."
git clone https://github.com/EspressoSystems/optimism-espresso-integration.git
cd optimism-espresso-integration
git checkout "$BRANCH_NAME"
git submodule update --init --recursive
# Poblate cachix cahe
nix flake archive --json | jq -r '.path,(.inputs|to_entries[].value.path)' | cachix push espresso-systems-private

echo "[*] Starting Docker..."
sudo systemctl enable --now docker
sudo usermod -a -G docker ec2-user
sudo chown ec2-user /var/run/docker.sock

echo "[*] Configuring Nitro Enclaves..."
sudo systemctl stop nitro-enclaves-allocator.service || true
echo -e '---\nmemory_mib: 4096\ncpu_count: 2' | sudo tee /etc/nitro_enclaves/allocator.yaml
sudo systemctl start nitro-enclaves-allocator.service


echo "[*] Running tests in nix develop shell..."

nix develop --command bash -c "just compile-contracts-fast && just build-batcher-enclave-image && just espresso-enclave-tests"
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
pkgs.awscli2
pkgs.just
pkgs.pnpm
pkgs.cargo
];
shellHook = ''
export FOUNDRY_DISABLE_NIGHTLY_WARNING=1
Expand Down
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ run-test12: compile-contracts
compile-contracts:
(cd packages/contracts-bedrock && just build-dev)

compile-contracts-fast:
(cd packages/contracts-bedrock && forge build --offline --skip "/**/test/**")

build-batcher-enclave-image:
(cd kurtosis-devnet && just op-batcher-enclave-image)

Expand All @@ -30,8 +33,9 @@ espresso_tests_timeout := "35m"
espresso-tests timeout=espresso_tests_timeout: compile-contracts
go test -timeout={{timeout}} -p=1 -count=1 ./espresso/environment

espresso-enclave-tests timeout=espresso_tests_timeout: compile-contracts build-batcher-enclave-image
ESPRESSO_RUN_ENCLAVE_TESTS=true go test -timeout={{timeout}} -p=1 -count=1 ./espresso/enclave-tests/...
espresso-enclave-tests:
ESPRESSO_RUN_ENCLAVE_TESTS=true go test -timeout={{espresso_tests_timeout}} -p=1 -count=1 ./espresso/enclave-tests/...


IMAGE_NAME := "ghcr.io/espressosystems/espresso-sequencer/espresso-dev-node:release-colorful-snake"
remove-espresso-containers:
Expand Down
9 changes: 9 additions & 0 deletions op-batcher/batcher/espresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,15 @@ func (l *BatchSubmitter) registerBatcher(ctx context.Context) error {
return nil
}

log.Info("Batch authenticator address", "value", l.RollupConfig.BatchAuthenticatorAddress)
code, err := l.L1Client.CodeAt(ctx, l.RollupConfig.BatchAuthenticatorAddress, nil)
if err != nil {
return fmt.Errorf("Failed to check code at contrat address: %w", err)
}
if len(code) == 0 {
return fmt.Errorf("No contract deployed at this address %w", err)
}

batchAuthenticator, err := bindings.NewBatchAuthenticator(l.RollupConfig.BatchAuthenticatorAddress, l.L1Client)
if err != nil {
return fmt.Errorf("failed to create BatchAuthenticator contract bindings: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/lib/espresso-tee-contracts
Loading