The Blocky Attestation Service (Blocky AS) gives you access to verifiable serverless computing. You can use it to create TEE attestations over function calls. You can also verify these attestations on chain in your smart contracts or locally.
To use Blocky AS, you need to install and configure the Blocky AS CLI, bky-as, and configure it. You'll also need to install the Blocky Compiler and several utility tools, if you don't have them already on your system.
Install
bky-asby running:curl -s https://raw.githubusercontent.com/blocky/attestation-service-cli/refs/tags/v0.1.0-beta.12/install.sh | bashAlthough you can run
bky-asfrom the current directory, we recommend you move it into your$PATH, so that you can run it from any directory, including the directories used in our examples throughout the documentation. You can putbky-asin/usr/local/binby running:sudo mv bky-as /usr/local/binThe
bky-asinstall script also downloadsconfig.toml, the defaultbky-asconfiguration file. Set the code measurement of the current release of the Blocky AS server application in theacceptable_measurementssection ofconfig.tomlby running:CODE_MEASUREMENT=$(curl -s https://docs.blocky.rocks/v0.1.0-beta.12/code_measurement.toml) RELEASE_CODE=$(grep -oP 'code\s*=\s*"\K[^"]+' <<<"$CODE_MEASUREMENT") sed -i "s/[0]\{96\}\.[0]\{96\}\.[0]\{96\}/$RELEASE_CODE/" config.tomlThe releases page documents the code measurements of the Blocky AS server application for each release. You can learn more about the role of code measurements in the verification process.
(Optional) Configure
config.tomlto call Blocky AS on cloud TEE servers. Go to the Blocky Developer Portal to create an account and get your free Blocky AS API key. Set the API key and the URL of the Blocky AS server inconfig.tomlby running:BKY_AS_API_KEY=your_api_key_here BKY_AS_HOST=http://api.bky.sh/prod/delphi/v0.1.0-beta.12 sed -i \ -e "s|^\(auth_token *= *\)\".*\"|\1\"$BKY_AS_API_KEY\"|" \ -e "s|^\(host *= *\)\".*\"|\1\"$BKY_AS_HOST\"|" \ config.tomlNote that if you skip this step and leave the
host="local-server"inconfig.toml,bky-aswill start a local, non-TEE server for local testing and development.(Recommended) Move
config.tomlto a well-known location. Thebky-ascommand will look forconfig.tomlin the current directory,./configs,$HOME/.config/bky/bky-asor you can specify the location using the--configcommand line argument tobky-as. You can moveconfig.tomlto$HOME/.config/bky/bky-asby running:mkdir -p $HOME/.config/bky/bky-as mv config.toml $HOME/.config/bky/bky-as/Install the Blocky Compiler,
bky-c, to compile your code to WebAssembly (WASM) for execution by Blocky AS.curl -s https://raw.githubusercontent.com/blocky/compiler/refs/heads/main/install.sh \ | bash -s -- -v v0.1.0-beta.2Although you can run
bky-cfrom the current directory, we recommend you move it into your$PATH, so that you can run it from any directory, including the directories used in our examples throughout the documentation. You can putbky-cin/usr/local/binby running:sudo mv bky-c /usr/local/binIf you don't have it already on your system, install jq to parse JSON data.
If you don't have it already on your system, install npm to run smart contract tests.
The Attestation Service CLI supports the attest-fn-call command which allows you to send WebAssembly (WASM) functions for execution on a TEE in a serverless compute model. Use the attest-fn-call command to execute resource-intensive tasks over API data to accelerate your smart contracts and lower your gas costs.
At a high level, a User invokes the attest-fn-call command and sends a compiled WASM Function and an Encrypted Environment, containing function parameters, to the Attestation Service running on a TEE. The Attestation Service decrypts the Environment, starts a WASM Runtime, and invokes the user Function with the decrypted parameters. As a part of its execution, the function may also make requests to external web2 APIs. Finally, the Attestation Service returns a TEE Attestation over the WASM function execution and its results to the User.
To attest a simple function call using Blocky AS, follow these steps:
Clone the Blocky AS examples repository and navigate to the
attest_fn_calldirectory:git clone --branch v0.1.0-beta.12 git@github.com:blocky/attestation-service-examples.git cd attestation-service-examples/attest_fn_callInspect the
helloWorldfunction in main.go://export helloWorld func helloWorld(inputPtr uint64, secretPtr uint64) uint64 { msg := "Hello, World!" return basm.WriteToHost([]byte(msg)) }Compile main.go to WASM:
bky-c build --reproducible . ./main.wasmInvoke the function on a Blocky AS server with the
bky-asCLI and save its response toout.json:cat fn-call.json | bky-as attest-fn-call > out.jsonParse the attested function call output from
out.json:which outputsjq -r ".transitive_attested_function_call.claims.output | @base64d" out.jsonHello, World!
To learn more the about the attest-fn-call command, explore Attesting Function Calls page.
You can bring attested function calls onchain and trustlessly verify them in your smart contracts to bring the power of TEEs into your dApp or ecosystem to unlock developer creativity.
At a high level, the User invokes the Blocky Attestation Service and obtains a TEE Attestation. The User calls a Smart Contract with the serialized Attestation as a parameter. Finally, the Smart Contract verifies the Attestation and makes use of the attested data.
To verify a Blocky AS function call attestation in a smart contract, follow these steps:
Change to the
on_chaindirectory of theattestation-service-examplesrepository:cd ../on_chainInstall dependencies by running:
npm installInvoke the contracts/User.sol contract to verify the attestations you created in Attesting WASM Function Calls:
which outputsTA_FILE=$(realpath ../attest_fn_call/out.json) npx hardhat test --grep "User contract"Compiled 3 Solidity files successfully (evm target: paris). User contract test processTransitiveAttestedFunctionCall emitted AttestedFunctionCallOutput(Hello, World!) ✔ Verify transitive attested function call (390ms) 1 passing (391ms)The call runs a Hardhat test that starts a local Ethereum testnet, deploys the User, contract and calls it with the attested function call as calldata.
To learn more the about bringing attestations on chain, explore Bringing Attestations On Chain page.