Try the Call Decryption Oracle Locally
What you’ll do
- Start a local test chain (anvil).
- Deploy the on-chain Call Decryption Oracle Contract.
- Deploy the on-chain demo contract that talks to the call decryption oracle contract.
- Start the off-chain Call Decryption Oracle.
- Check the results stored in the demo contract.
Required Installations
You need foundry (for the chain tooling), JDK 21 or later (to build and start the service),
and Python 3 (to read the deployment receipts). For Foundry installation instructions see
the setup page.
Apart from this we assume that openssl, cat, tr, xxd, sed and awk are present.
The following commands should be run in a shell (macOS Terminal, Windows GitBash). You may use the copy button and just paste them into the shell.
Step-by-Step
1. Launch a local chain for testing
Run:
anvil --host 127.0.0.1 --port 8545 --chain-id 31337
After this switch to a new shell in the root of this repository checkout. Keep this shell for the remaining steps. The test accounts below are for Anvil only; for Sepolia, Ethereum, Polygon and Amoy, use the network deployment guide.
2. Generate the private and public key (used by the decryption oracle)
2.1. Use the key-generation script from the current checkout
Run:
export LOCAL_DEMO_DIR=$(mktemp -d "${TMPDIR:-/tmp}/finmath-call-demo.XXXXXX")
export RPC_URL=http://127.0.0.1:8545
The temporary directory keeps this local demo's keys and state separate from any existing service.
2.2. Generate the private key for the call decryption oracle
export SECRETS_DIR="$LOCAL_DEMO_DIR/secrets"
bash scripts/generate-keys.sh --secrets-dir "$SECRETS_DIR"
2.3. Extract the public key (used to encrypt the arguments of function calls)
CERT="$SECRETS_DIR/oracle.crt.pem"
export PUBLIC_KEY="$(openssl x509 -in "$CERT" -noout -pubkey | openssl pkey -pubin -outform DER | xxd -p -c 1000000 | tr -d '\r\n' | sed 's/^/0x/')"
echo "$PUBLIC_KEY"
3. Deploy the Call Decryption Oracle Contract and the Demo Contract
3.1. Build the service and CLI from the same checkout
Run:
./mvnw -B -ntp -pl oracle-execution -am -Dgpg.skip=true package
The contracts are in oracle-execution/src/main/solidity. The Foundry configuration
selects Solidity 0.8.30, optimization, viaIR and the Paris EVM target.
3.2. Build and deploy CallDecryptionOracle and CallDecryptionOracleRouter
The Foundry script deploys both contracts and sets their fees. It uses Anvil account 0 for deployment; the Java service fulfills requests using account 1.
Run:
export EXPECTED_CHAIN_ID=31337
export DEPLOYER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
export OWNER_ADDRESS="$DEPLOYER_ADDRESS"
export ORACLE_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
export FEE_CALL_WEI=3000000000000
export FEE_ENCRYPTED_CALL_WEI=3000000000000
export GAS_RESERVE=50000
export FOUNDRY_BROADCAST="$LOCAL_DEMO_DIR/broadcast"
test "$(cast chain-id --rpc-url "$RPC_URL")" = "$EXPECTED_CHAIN_ID"
(
cd oracle-execution
forge script script/DeployCallDemo.s.sol:DeployCallDemo \
--rpc-url "$RPC_URL" --sender "$DEPLOYER_ADDRESS" --unlocked --broadcast --slow
)
--unlocked uses Anvil's disposable accounts. On public networks, use the Foundry
wallet workflow in the deployment guide.
3.3. Read the deployed contract addresses
Run:
python3 - <<'PY'
import json, os, re
from pathlib import Path
root = Path(os.environ['LOCAL_DEMO_DIR'])
run = json.loads((root / 'broadcast/DeployCallDemo.s.sol/31337/run-latest.json').read_text())
assert run['chain'] == 31337
receipts = {r['transactionHash']: r for r in run['receipts']}
assert len(receipts) == len(run['transactions'])
addresses = {}
for tx in run['transactions']:
receipt = receipts[tx['hash']]
assert int(receipt['status'], 16) == 1
if tx['transactionType'] == 'CREATE':
address = receipt['contractAddress']
assert re.fullmatch(r'0x[0-9a-fA-F]{40}', address)
addresses[tx['contractName']] = address
(root / 'contracts.env').write_text(
f"ORACLE_CONTRACT={addresses['CallDecryptionOracle']}\n"
f"ROUTER_CONTRACT={addresses['CallDecryptionOracleRouter']}\n")
PY
source "$LOCAL_DEMO_DIR/contracts.env"
echo "Oracle deployed at $ORACLE_CONTRACT"
echo "Router deployed at $ROUTER_CONTRACT"
4. Launch the CallDecryptionOracle service (locally)
4.1. Launch the CallDecryptionOracle service (locally)
Run (in the same shell that deployed the contracts):
ANVIL_ORACLE_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
java -jar oracle-execution/target/finmath-decryption-oracle-encrypted-hashed-execution-4.0.2-SNAPSHOT.jar \
--server.address=127.0.0.1 --server.port=9099 \
--ethereum.rpcUrl="$RPC_URL" --ethereum.httpRpcUrl="$RPC_URL" \
--ethereum.chainId="$EXPECTED_CHAIN_ID" \
--ethereum.sender.address="$ORACLE_ADDRESS" \
--ethereum.sender.privateKey="$ANVIL_ORACLE_PRIVATE_KEY" \
--ethereum.calldecryptionoracle.contract="$ORACLE_CONTRACT" \
--ethereum.calldecryptionoracle.listenerMode=poll \
--ethereum.calldecryptionoracle.fromBlock=1 \
--ethereum.calldecryptionoracle.finalityBlocks=0 \
--ethereum.calldecryptionoracle.stateFile="$LOCAL_DEMO_DIR/lastBlock" \
--ethereum.listener.pollIntervalMs=1000 \
--ethereum.gas.limit-default=2000000 \
--ethereum.gas.min-priority-fee-wei=1000000000 \
--ethereum.gas.max-fee-wei=100000000000 \
--oracle.keystore.path="$SECRETS_DIR/oracle.p12" \
--oracle.keystore.password-file="$SECRETS_DIR/oracle.pw" \
--oracle.key.alias=oracle-rsa --api.rsa.enabled=false \
> "$LOCAL_DEMO_DIR/service.log" 2>&1 &
ORACLE_SERVICE_PID=$!
The sender key is Anvil account 1's publicly known private key. The service uses the same chain ID, operator address and RSA keystore as the deployment. Its state file is in the temporary demo directory; use a fresh directory when resetting Anvil. The explicit callback gas limit is needed because a fulfillment can catch callback failures.
4.2. Show the log of the CallDecryptionOracle
(Optional): In a new window / shell, run tail -f on the service log. To print its path
in the shell used above:
printf 'Service log: %s/service.log\n' "$LOCAL_DEMO_DIR"
tail -n 30 "$LOCAL_DEMO_DIR/service.log"
This allows you to observe the log of the decryption oracle service. Wait for startup.
Then return to the previous shell that deployed the contracts (this is important, because we will use the environment variables $ORACLE_CONTRACT and $ROUTER_CONTRACT).
The decryption oracle is up and running now. We now perform a test, generating encrypted arguments, storing them, requesting decryption and execution of a function call.
5. Encrypted Arguments Generation
Pasting the following lines in your shell (e.g. bash) will generate the encrypted arguments for (uint256) 20, (string) “Peach” (uint256) 990. It will construct a call descriptor for a function that has that signature.
ARGS_PLAIN=$(cast abi-encode "func(uint256,string,uint256)" 20 "Peach" 990)
ARGS_HASH=$(cast keccak "$ARGS_PLAIN")
export ARGS_DESCRIPTOR=$(cast abi-encode "wrap(address[],bytes)" '[]' "$ARGS_PLAIN")
export ORACLE_PUBLIC_KEY=$(cast call "$ORACLE_CONTRACT" "getPublicKey()(bytes,bytes32)" --rpc-url "$RPC_URL" | head -n 1)
ENCRYPTED_ARGS=$(java -jar oracle-base/target/finmath-decryption-oracle-base-4.0.2-SNAPSHOT-cli.jar)
FEE_CALL_DECRYPT=$(cast call "$ORACLE_CONTRACT" "feeCall()(uint256)" --rpc-url "$RPC_URL" | awk '{print $1}')
echo "$FEE_CALL_DECRYPT"
DEMO_TARGET_CONTRACT="$ROUTER_CONTRACT"
DEMO_TARGET_METHOD="demoTargetFunction"
DEMO_TARGET_VALID_UNTIL_BLOCK=0
DEMO_SELECTOR=$(cast sig "$DEMO_TARGET_METHOD(uint256,string,uint256)")
DEMO_CALL_DESCRIPTOR=$(cast abi-encode "CallDescriptor(address,bytes4,uint256)" "$DEMO_TARGET_CONTRACT" "$DEMO_SELECTOR" "$DEMO_TARGET_VALID_UNTIL_BLOCK")
printf "\n\n\e[1mDemo Call Descriptor:\e[0m\n$DEMO_CALL_DESCRIPTOR\n\n\e[1mDemo Encrypted Arguments:\e[0m\n$ENCRYPTED_ARGS\n\n\e[1mArgs Hash:\e[0m\n$ARGS_HASH\n\n\e[1mFee (for Decrypt) in Wei (1E18):\e[0m\n$FEE_CALL_DECRYPT\n\n"
6. Use the encrypted arguments in the demo contract
6.1 Store the encrypted arguments for later use in a function call
Run:
ID=5
cast send "$ROUTER_CONTRACT" \
"store(uint256,bytes,bytes,bytes32)" "$ID" "$DEMO_CALL_DESCRIPTOR" "$ENCRYPTED_ARGS" "$ARGS_HASH" \
--rpc-url "$RPC_URL" --from "$DEPLOYER_ADDRESS" --unlocked --gas-limit 1000000
Use a new ID for each run. Router records are scoped to the requesting account, so
reads and subsequent transactions must use the same --from address.
6.2 Define a Helper Function to Fetch the Result from the Demo Contract
We define a function that fetches the result from the demo contract.
After this function has been defined we may fetch a result from the contract via oracle_get_result <id>.
Run:
oracle_get_result () {
local id="$1"
local sig='getResult(uint256)(uint256,address,address,bytes4,bytes,bytes32,uint256,bytes,bytes32,bool)'
# temp file to avoid subshell issues
local tmpfile
tmpfile="$(mktemp)"
cast call "$ROUTER_CONTRACT" "$sig" "$id" --rpc-url "$RPC_URL" --from "$DEPLOYER_ADDRESS" > "$tmpfile" || {
rm -f "$tmpfile"
echo "cast call failed" >&2
return 1
}
vars=(phase caller targetContract targetSelector argsEncrypted argsHash requestId argsPlain argsHashComputed routingSuccess)
{
for v in "${vars[@]}"; do
IFS= read -r "$v" || break
done
} < "$tmpfile"
rm -f "$tmpfile"
# Optional pretty print
cat <<RESULT
phase.............: $phase (0=new, 1=stored, 2=requested, 3=callback, 4=routed, 5=final)
caller............: $caller
targetContract....: $targetContract
targetSelector....: $targetSelector
argsEncrypted.....: $argsEncrypted
argsHash..........: $argsHash
requestId.........: $requestId
argsPlain.........: $argsPlain
argsHashComputed..: $argsHashComputed
routingSuccess....: $routingSuccess
RESULT
}
6.3 Fetch the Result
Run:
oracle_get_result $ID
This will fetch the result. The encrypted arguments will be stored under $argsEncrypted.
7. Decryption of the Arguments
7.1 Trigger decryption of the arguments (through the demo contract)
Send the exact fee returned by feeCall(). The first-field extraction in step 5 removes
any human-readable annotation that cast adds to numeric output.
Run:
cast send "$ROUTER_CONTRACT" \
"decrypt(uint256)" "$ID" \
--rpc-url "$RPC_URL" --from "$DEPLOYER_ADDRESS" --unlocked \
--value "$FEE_CALL_DECRYPT" --gas-limit 500000
7.2 Fetch the Result
Run:
oracle_get_result $ID
This will fetch and display the result.
Repeating this call, you may first observe that “phase 2 (=requested)”, then a few seconds later “phase 3 (=callback)”. In the log of the decryption oracle service you will see the request and the fulfillment. Wait for phase 3 before continuing. If phase 2 persists, check the service log.
8. Execution of a Function Call
8.1 Trigger execution of a function call with the decrypted arguments (through the demo contract)
Run:
cast send "$ROUTER_CONTRACT" \
"execute(uint256)" "$ID" \
--rpc-url "$RPC_URL" --from "$DEPLOYER_ADDRESS" --unlocked --gas-limit 500000
8.2 Fetch the Result
Run:
oracle_get_result $ID
This will fetch and display the result.
9. Routing
9.1 Fetch the Results of the Routing
The demo contract automatically routes to a function with
typed arguments (uint256,string,uint256) where we should recover the
arguments that were encrypted above.
Run:
cast call "$ROUTER_CONTRACT" "getDemoTargetValues(uint256)(uint256,string,uint256)" "$ID" --rpc-url "$RPC_URL" --from "$DEPLOYER_ADDRESS"
The phase should be 5, routing should be true, and the typed result should be
20, "Peach", and 990. Stop the Java service when finished, then stop Anvil in
its own terminal:
kill "$ORACLE_SERVICE_PID"
Last updated: 2026-11-22
