Skip to content

Commit 930474d

Browse files
Merge pull request #1 from datachainlab/init
init
2 parents 42d75f7 + 90283c4 commit 930474d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+10563
-2
lines changed

.dockerignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# LCP
2+
**/target
3+
4+
## object file
5+
**/*.o
6+
7+
## library
8+
**/*.a
9+
10+
## share object
11+
**/*.so
12+
**/*.so.*
13+
!**/enclave.so
14+
15+
## generated proxy
16+
**/*_u.c
17+
**/*_u.h
18+
**/enclave/Enclave_t.c
19+
**/*_t.h
20+
21+
## test data
22+
tests

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
directories: ["/enclaves/**/*"]
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 3
8+
labels:
9+
- "dependencies"
10+
- "rust"

.github/workflows/release.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
enclave:
6+
type: string
7+
required: true
8+
description: 'Enclave to be released'
9+
options:
10+
- ethereum
11+
- optimism
12+
- parlia
13+
network:
14+
type: string
15+
required: true
16+
default: mainnet
17+
options:
18+
- testnet
19+
- mainnet
20+
description: 'The network on which the enclave runs.'
21+
tag:
22+
type: string
23+
required: true
24+
description: 'Tag Name (e.g. v1.2.3)'
25+
draft:
26+
type: boolean
27+
required: true
28+
default: false
29+
description: 'create a release as draft'
30+
prerelease:
31+
type: boolean
32+
required: true
33+
default: false
34+
description: 'create a release as prerelease'
35+
36+
jobs:
37+
release:
38+
runs-on: ubuntu-24.04
39+
permissions:
40+
contents: write # Push Tag and Create Release
41+
packages: write # Push Docker Image to ghcr.io
42+
steps:
43+
- uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
- name: Check if tag exists
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
OWNER: ${{ github.repository_owner }}
50+
REPO: ${{ github.event.repository.name }}
51+
TAG: ${{ github.event.inputs.enclave }}-${{ github.event.inputs.network }}-${{ github.event.inputs.tag }}
52+
run: |
53+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
54+
-H "Authorization: token ${GITHUB_TOKEN}" \
55+
"https://api.github.com/repos/${OWNER}/${REPO}/git/refs/tags/${TAG}")
56+
if [ "$STATUS" = "200" ]; then
57+
echo "🚫 Tag '${TAG}' already exists."
58+
exit 1
59+
fi
60+
- name: Configure Git user
61+
run: |
62+
git config user.name "github-actions[bot]"
63+
git config user.email "github-actions[bot]@users.noreply.github.com"
64+
- uses: docker/setup-buildx-action@v3
65+
- uses: docker/login-action@v3
66+
with:
67+
registry: ghcr.io
68+
username: ${{ github.actor }}
69+
password: ${{ github.token }}
70+
logout: true
71+
- id: metadata
72+
uses: docker/metadata-action@v5
73+
with:
74+
images: ghcr.io/${{ github.repository }}/${{ github.event.inputs.enclave }}/${{ github.event.inputs.network }}
75+
tags: |
76+
type=sha,prefix=,format=long
77+
${{ github.event.inputs.tag }}
78+
- name: Build and Push
79+
uses: docker/build-push-action@v5
80+
id: docker_build_and_push
81+
with:
82+
context: .
83+
push: true
84+
build-args: |
85+
LCP_ELC_TYPE=${{ github.event.inputs.enclave }}
86+
DEPLOYMENT_NETWORK=${{ github.event.inputs.network }}
87+
tags: ${{ steps.metadata.outputs.tags }}
88+
labels: ${{ steps.metadata.outputs.labels }}
89+
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/${{ github.event.inputs.enclave }}/${{ github.event.inputs.network }}:buildCache
90+
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/${{ github.event.inputs.enclave }}/${{ github.event.inputs.network }}:buildCache,mode=max
91+
- name: Create Release
92+
uses: softprops/action-gh-release@v2
93+
with:
94+
name: ${{ github.event.inputs.enclave }}/${{ github.event.inputs.network }}/${{ github.event.inputs.tag }}
95+
tag_name: ${{ github.event.inputs.enclave }}-${{ github.event.inputs.network }}-${{ github.event.inputs.tag }}
96+
draft: ${{ github.event.inputs.draft }}
97+
prerelease: ${{ github.event.inputs.prerelease }}
98+
generate_release_notes: true
99+
append_body: true
100+
body: |
101+
## Docker Image
102+
1. Image Digest: ${{ steps.docker_build_and_push.outputs.imageid }}
103+
2. [Link to Docker Repository](https://github.com/${{ github.repository }}/pkgs/container/${{ github.event.repository.name }}%2F${{ github.event.inputs.enclave }}%2F${{ github.event.inputs.network }})

.github/workflows/sgxsdk.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: SgxSDK
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
push:
8+
runs-on: ubuntu-24.04
9+
permissions:
10+
contents: read # checkout
11+
packages: write # Push Docker Image to ghcr.io
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: docker/setup-buildx-action@v3
15+
- uses: docker/login-action@v3
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.actor }}
19+
password: ${{ github.token }}
20+
logout: true
21+
- id: metadata
22+
uses: docker/metadata-action@v5
23+
with:
24+
images: ghcr.io/${{ github.repository }}/intel-sgx-sdk
25+
tags: |
26+
type=sha,prefix=,format=long
27+
- name: Build and Push
28+
uses: docker/build-push-action@v5
29+
id: docker_build_and_push
30+
with:
31+
context: ./sgxsdk
32+
push: true
33+
tags: ${{ steps.metadata.outputs.tags }}
34+
labels: ${{ steps.metadata.outputs.labels }}
35+
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/intel-sgx-sdk:buildCache
36+
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/intel-sgx-sdk:buildCache,mode=max

.github/workflows/test.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Test
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
get-enclaves:
7+
runs-on: ubuntu-24.04
8+
outputs:
9+
enclaves: ${{ steps.changed.outputs.enclaves }}
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
- id: changed
15+
run: |
16+
enclaves=$(find enclaves -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | jq -R . | jq -s -c .)
17+
echo "enclaves=$enclaves" >> "$GITHUB_OUTPUT"
18+
build:
19+
needs: get-enclaves
20+
if: needs.get-enclaves.outputs.enclaves != '[]'
21+
runs-on: ubuntu-24.04
22+
strategy:
23+
matrix:
24+
enclave: ${{ fromJson(needs.get-enclaves.outputs.enclaves) }}
25+
network: [testnet, mainnet]
26+
permissions:
27+
contents: read # For checkout repo
28+
packages: write # For Push Image for buildCache to ghcr.io
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: docker/setup-buildx-action@v3
32+
- uses: docker/login-action@v3
33+
with:
34+
registry: ghcr.io
35+
username: ${{ github.actor }}
36+
password: ${{ github.token }}
37+
logout: true
38+
- id: meta
39+
uses: docker/metadata-action@v5
40+
with:
41+
images: ghcr.io/${{ github.repository }}/${{ matrix.enclave }}/${{ matrix.network }}
42+
tags: ${{ github.event.pull_request.head.sha }}
43+
- name: Set UID and GID as env
44+
run: |
45+
echo "UID=$(id -u)" >> "$GITHUB_ENV"
46+
echo "GID=$(id -g)" >> "$GITHUB_ENV"
47+
- uses: docker/build-push-action@v5
48+
with:
49+
context: .
50+
push: false
51+
build-args: |
52+
LCP_ELC_TYPE=${{ matrix.enclave }}
53+
DEPLOYMENT_NETWORK=${{ matrix.network }}
54+
UID=${{ env.UID }}
55+
GID=${{ env.GID }}
56+
tags: ${{ steps.meta.outputs.tags }}
57+
labels: ${{ steps.meta.outputs.labels }}
58+
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/${{ matrix.enclave }}/${{ matrix.network }}:buildCache
59+
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/${{ matrix.enclave }}/${{ matrix.network }}:buildCache,mode=max
60+
outputs: type=docker # save the image locally
61+
- name: Test
62+
run: |
63+
# Check whether the MRENCLAVE calculated locally when updating the enclave and
64+
# the MRENCLAVE derived from the Image created in the test case are the same value.
65+
66+
mkdir -p tests/${{ matrix.enclave }}/mrenclaves/${{ matrix.network }}
67+
docker run --rm -v $(pwd)/tests/${{ matrix.enclave }}/mrenclaves/${{ matrix.network }}:/app/tests/mrenclave \
68+
ghcr.io/${{ github.repository }}/${{ matrix.enclave }}/${{ matrix.network }}:${{ github.event.pull_request.head.sha }} \
69+
bash -c "/app/scripts/mrenclave.sh /out /app/tests/mrenclave > mrenclave.log 2>&1 || { cat mrenclave.log; exit 1; }"
70+
71+
mrenclave_local=$(yq -r .${{ matrix.enclave }}.${{ matrix.network }} < mrenclaves.yaml)
72+
mrenclave_test=$(cat tests/${{ matrix.enclave }}/mrenclaves/${{ matrix.network }}/MRENCLAVE)
73+
74+
echo "Local:$mrenclave_local"
75+
echo "Test: $mrenclave_test"
76+
77+
[ "$mrenclave_local" = "$mrenclave_test" ]

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#object file
2+
*.o
3+
4+
#library
5+
*.a
6+
7+
#share object
8+
*.so
9+
*.so.*
10+
11+
#generated proxy
12+
*_u.c
13+
*_u.h
14+
enclave/Enclave_t.c
15+
*_t.h
16+
17+
target/
18+
tests/

Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM ghcr.io/datachainlab/toki-bridge-lcp-enclaves/intel-sgx-sdk:cb5743b676b9547d7cd0700de0192a690b90a033
2+
3+
ARG RUST_TOOLCHAIN_VERSION=nightly-2024-09-05
4+
LABEL org.rust-lang.org.toolchain.version=$RUST_TOOLCHAIN_VERSION
5+
6+
ARG LCP_ELC_TYPE
7+
LABEL finance.toki.lcp.enclave.elc=$LCP_ELC_TYPE
8+
9+
ARG DEPLOYMENT_NETWORK=localnet
10+
LABEL finance.toki.lcp.enclave.network=$DEPLOYMENT_NETWORK
11+
12+
ENV DEBIAN_FRONTEND=noninteractive
13+
14+
ARG UID=1000
15+
ARG GID=1000
16+
ARG USERNAME=app
17+
18+
RUN set -eux; \
19+
# If a user with the same ID exists, delete and create.
20+
if getent passwd "$UID" > /dev/null; then \
21+
OLD_USER=$(getent passwd "$UID" | cut -d: -f1); \
22+
echo "Removing existing user: $OLD_USER"; \
23+
userdel -r "$OLD_USER" || true; \
24+
fi; \
25+
# If group does not exist, create group.
26+
if ! getent group "$GID" > /dev/null; then \
27+
groupadd -g "$GID" "$USERNAME"; \
28+
fi; \
29+
useradd -u "$UID" -g "$GID" -m "$USERNAME";
30+
31+
RUN mkdir -p /app && chown $UID:$GID /app
32+
RUN mkdir -p /out && chown $UID:$GID /out
33+
34+
USER $USERNAME
35+
WORKDIR /app
36+
37+
ADD --chown=$UID:$GID ./scripts ./scripts
38+
ENV rust_toolchain=$RUST_TOOLCHAIN_VERSION
39+
RUN bash ./scripts/install_rust.sh
40+
41+
SHELL ["/bin/bash", "-c", "-l"]
42+
43+
ADD --chown=$UID:$GID ./buildcommon.mk ./buildcommon.mk
44+
ADD --chown=$UID:$GID ./buildenv.mk ./buildenv.mk
45+
ADD --chown=$UID:$GID ./enclaves/$LCP_ELC_TYPE ./enclaves/$LCP_ELC_TYPE
46+
47+
ARG SGX_MODE=HW
48+
ENV SGX_MODE=$SGX_MODE
49+
ENV LCP_ELC_TYPE=$LCP_ELC_TYPE
50+
ENV DEPLOYMENT_NETWORK=$DEPLOYMENT_NETWORK
51+
52+
RUN make -C enclaves/$LCP_ELC_TYPE enclave/enclave_sig.dat
53+
54+
RUN cp enclaves/$LCP_ELC_TYPE/enclave/enclave.so \
55+
enclaves/$LCP_ELC_TYPE/enclave/Enclave.config.xml \
56+
enclaves/$LCP_ELC_TYPE/enclave/enclave_sig.dat \
57+
/out/
58+
59+
WORKDIR /out

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2025 Datachain, Inc
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
DOCKER ?= docker
2+
3+
ENCLAVES_DIRS := $(shell find enclaves -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
4+
NETWORKS := testnet mainnet
5+
ENCLAVES := $(foreach e,$(ENCLAVES_DIRS),$(foreach n,$(NETWORKS),$(e)/$(n)))
6+
7+
# docker image
8+
REPOSITORY ?= ghcr.io/datachainlab/toki-bridge-enclaves
9+
TAG ?= $(shell git rev-parse HEAD)
10+
11+
# docker build parameter
12+
UID ?= $(shell id -u)
13+
GID ?= $(shell id -g)
14+
15+
.PHONY: all
16+
all:
17+
make $(ENCLAVES)
18+
19+
.PHONY: $(ENCLAVES)
20+
$(ENCLAVES):
21+
enclave=$(word 1,$(subst /, ,$@)); \
22+
deployment_network=$(word 2,$(subst /, ,$@)); \
23+
make mrenclave LCP_ELC_TYPE=$$enclave DEPLOYMENT_NETWORK=$$deployment_network
24+
25+
.PHONY: build
26+
build:
27+
$(DOCKER) build -t $(REPOSITORY)/$(LCP_ELC_TYPE)/$(DEPLOYMENT_NETWORK):$(TAG) \
28+
--build-arg LCP_ELC_TYPE=$(LCP_ELC_TYPE) \
29+
--build-arg DEPLOYMENT_NETWORK=$(DEPLOYMENT_NETWORK) \
30+
--build-arg UID=$(UID) --build-arg GID=$(GID) \
31+
.
32+
33+
.PHONY: mrenclave
34+
mrenclave: build
35+
mkdir -p $(PWD)/tests/$(LCP_ELC_TYPE)/mrenclaves/$(DEPLOYMENT_NETWORK)
36+
$(DOCKER) run --rm $(REPOSITORY)/$(LCP_ELC_TYPE)/$(DEPLOYMENT_NETWORK):$(TAG) \
37+
bash -c "/app/scripts/mrenclave.sh /out /app/tests/mrenclave > mrenclave.log 2>&1 && cat /app/tests/mrenclave/MRENCLAVE || { cat mrenclave.log; exit 1; }" > $(PWD)/tests/$(LCP_ELC_TYPE)/mrenclaves/$(DEPLOYMENT_NETWORK)/MRENCLAVE && \
38+
yq ".$(LCP_ELC_TYPE).$(DEPLOYMENT_NETWORK) = \"$$(cat $(PWD)/tests/$(LCP_ELC_TYPE)/mrenclaves/$(DEPLOYMENT_NETWORK)/MRENCLAVE)\" | .$(LCP_ELC_TYPE).$(DEPLOYMENT_NETWORK) style=\"double\"" -i mrenclaves.yaml || exit 1
39+

0 commit comments

Comments
 (0)