Usage


⚠️ Before you continue: Please read the Disclaimer.
By using this site, software, or contracts, you acknowledge that you have read and accepted it.


Requirements

We will illustrate the necessary steps via small commandline executions using cast and Java

Required Installations

You need foundry (for the chain tooling) and Java 21 or later (to launch a tool that encrypts the arguments). Build the CLI JAR using the deployment guide. For installation instructions see the setup page. Apart from this we assume that openssl, cat, tr, xxd and sed 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.

In the following we construct the call descriptor and the encrypted arguments step-by-step.

Encrypt Arguments

1) Create plain representation of the arguments

Create a bytes representation of your arguments via abi.encode.

For example, for (uint256(20), string("Peach"), uint256(990)) this would be in Solidity

bytes memory encoded = abi.encode(uint256(20), string("Peach"), uint256(990));

You can do this on the command line via cast. For example, to encode an integer value (20), a string (“Peach”), an integer (990) you can write

ARGS_PLAIN=$(cast abi-encode "func(uint256,string,uint256)" 20 "Peach" 990)
echo $ARGS_PLAIN

This example would result in

0x0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000003de00000000000000000000000000000000000000000000000000000000000000055065616368000000000000000000000000000000000000000000000000000000

This is the value of argsPlain.

2) Calculate the Hash

Calculate the hash value for the plain arguments. This can be done via

ARGS_HASH=$(cast keccak "$ARGS_PLAIN")
echo $ARGS_HASH

This example would result in

0xd8e3ac299d2e28bbd43fb9fcad763e6ad27c1cbab4e50c24618138452b4ae75c

This is the value of argsHash.

3) Build the arguments descriptor

The final argument descriptor may contain an array of addresses with eligibleCallers. If we leave it empty, we just set

export ARGS_DESCRIPTOR=$(cast abi-encode "wrap(address[],bytes)" [] $ARGS_PLAIN)
echo $ARGS_DESCRIPTOR

Next step is to encrypt this argument descriptor.

4) Fetch the public key for encryption

A call decryption oracle is available on different networks. The oracle itself provides the public key that can be used to encrypt arguments. You can fetch it directly from the oracle.

Depending on the chosen network, set the following from the repository root. The address files are produced by the deployment guide:

Ethereum Mainnet

source deployment/generated/ethereum/calls/contracts.env
RPC_URL="https://ethereum-rpc.publicnode.com"
ORACLE_CONTRACT="$CALL_ORACLE_CONTRACT"

Polygon Mainnet

source deployment/generated/polygon/calls/contracts.env
RPC_URL="https://polygon-rpc.com"
ORACLE_CONTRACT="$CALL_ORACLE_CONTRACT"

Sepolia (Ethereum Testnet)

source deployment/generated/sepolia/calls/contracts.env
RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
ORACLE_CONTRACT="$CALL_ORACLE_CONTRACT"

Amoy (Polygon Testnet)

source deployment/generated/amoy/calls/contracts.env
RPC_URL="https://rpc-amoy.polygon.technology"
ORACLE_CONTRACT="$CALL_ORACLE_CONTRACT"

You can replace the public RPC endpoint with your own. Check that it matches the selected network:

test "$(cast chain-id --rpc-url "$RPC_URL")" = "$EXPECTED_CHAIN_ID"

With these definition you can fetch the current public key via

export ORACLE_PUBLIC_KEY=$(cast call "$ORACLE_CONTRACT" "getPublicKey()(bytes,bytes32)" --rpc-url "$RPC_URL" | head -n 1)
echo $ORACLE_PUBLIC_KEY

5) Encrypt the ArgumentDescriptor

ENCRYPTED_ARGS=$(java -jar oracle-base/target/finmath-decryption-oracle-base-4.0.2-SNAPSHOT-cli.jar)
echo $ENCRYPTED_ARGS

6) Build the CallDescriptor

Specific the target contract (the contract that should receive the decrypted arguments) and the target method (the function name, e.g. myFunction on contract 0x1234567812345678123456781234567812345678). The signature of this function needs to be (uint256,bytes). The second argument is an abi-encode of a typed argument vector.

TARGET_CONTRACT=0x1234567812345678123456781234567812345678
TARGET_METHOD="myFunction"
TARGET_VALID_UNTIL_BLOCK=0

where myFunction is the name of the method.

With these definitions specify the SELECTOR and build the CallDescriptor via

SELECTOR=$(cast sig "$TARGET_METHOD(uint256,bytes)")
CALL_DESCRIPTOR=$(cast abi-encode "CallDescriptor(address,bytes4,uint256)" $TARGET_CONTRACT $SELECTOR $TARGET_VALID_UNTIL_BLOCK)
echo "$CALL_DESCRIPTOR"

Done

The output of step 6 (the CALL_DESCRIPTOR) and step 5 (the ENCRYPTED_ARGS) can now be passed to a smart contract of your own and stored for later execution.

Once the pre-conditions of your specific use case are fulfilled, your smart contract can call the oracles requestCall method

function requestCall(CallDescriptor calldata callDescriptor, EncryptedHashedArguments calldata encArgs, bytes calldata secondFactor) external payable returns (uint256 requestId);

and trigger the call the specific function (in the example above func(uint256,bytes)) on the specified TARGET_CONTRACT, where the second argument will be the ARGS_PLAIN (the decrypted arguments).

Your target contract may resolve the typed arguments using an abi-decode or route to a correspondingly typed function like

(bool success, ) = address(this).call(abi.encodePacked(this.finalTargetFunction.selector, argsPlain));

and continue with its business logic from there.

Continue (1): Router

We provide a generic router for testing purposes that may also used for demonstration.

The router provides three methods:

  • store(clientId, callDescriptor, encryptedArgs, argsHash): store a callDescriptor, encryptedArgs, argsHash under a freely choosen clientId
  • decrypt(clientId): trigger the decryption of the stored encryptedArgs and validate the result against argsHash.
  • execute(clientId): execute the method specifed by the callDescriptor with the decrypted arguments.

The router provides a view getResult to view the current state associated with a clientId.

The same deployment creates an instance of the router. Select its address for the same network used above:

Ethereum Mainnet

source deployment/generated/ethereum/calls/contracts.env
RPC_URL="https://ethereum-rpc.publicnode.com"
ROUTER_CONTRACT="$CALL_ROUTER_CONTRACT"

Polygon Mainnet

source deployment/generated/polygon/calls/contracts.env
RPC_URL="https://polygon-rpc.com"
ROUTER_CONTRACT="$CALL_ROUTER_CONTRACT"

Sepolia (Ethereum Testnet)

source deployment/generated/sepolia/calls/contracts.env
RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
ROUTER_CONTRACT="$CALL_ROUTER_CONTRACT"

Amoy (Polygon Testnet)

source deployment/generated/amoy/calls/contracts.env
RPC_URL="https://rpc-amoy.polygon.technology"
ROUTER_CONTRACT="$CALL_ROUTER_CONTRACT"

Its oracle() must equal CALL_ORACLE_CONTRACT on the selected network.

Continue (2): Demo

For demonstation purposes the router may be choosen as target contract for the routed call. For this it offers a method demoTargetFunction(uint256,string,uint256). If the plain arguments are initialized to this selector, you can observe the three arguments via the view getDemoTargetValues(clientId).

The required call descriptor is given by

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)
echo $DEMO_CALL_DESCRIPTOR

See the Try It page for a test via Remix.

The paths above use the separate oracle/demo workflow. With the optional combined workflow, omit the calls/ directory from each address-file path.