Skip to main content

External Signer

When the validator runs in an unsafe environmet, it is possible to start it without private keys and connect it via HTTP to a remote signing service. This section explains how to achieve that.

HTTP Protocol​

The external/remote signer must implement a simple HTTP server that waits for POST requests on an endpoint with the form <signer_address>/sign. This <signer_address> has to be specified in the Validator during startup via the --signer-url flag (or equivalent environment var or config file).

Request Format​

The external signer server will receive a POST request from the validator. This request will include all the transaction data required for signing. Request example:

{
"transaction": {
"type": "INVOKE",
"sender_address": "0x11efbf2806a9f6fe043c91c176ed88c38907379e59d2d3413a00eeeef08aa7e",
"calldata": [
"0x1",
"0x4862e05d00f2d0981c4a912269c21ad99438598ab86b6e70d1cee267caaa78d",
"0x37446750a403c1b4014436073cf8d08ceadc5b156ac1c8b7b0ca41a0c9c1c54",
"0x1",
"0x6521dd8f51f893a8580baedc249f1afaf7fd999c88722e607787970697dd76"
],
"version": "0x3",
"signature": [
"0x6711bfe51870a9874af883ca974b94fef85200d5772db5792013644dc9dd16a",
"0x23e345b39ffc43a92ab6735bf3f11e7dac1aa931d8c9647a1a2957f759b8baa"
],
"nonce": "0x194",
"resource_bounds": {
"l1_gas": {
"max_amount": "0x0",
"max_price_per_unit": "0x57e48bc504e79"
},
"l1_data_gas": {
"max_amount": "0x450",
"max_price_per_unit": "0xa54"
},
"l2_gas": {
"max_amount": "0xc92ca0",
"max_price_per_unit": "0x1b5aea1cb"
}
},
"tip": "0x0",
"paymaster_data": [],
"account_deployment_data": [],
"nonce_data_availability_mode": "L1",
"fee_data_availability_mode": "L1"
},
"chain_id": "0x534e5f5345504f4c4941"
}

Each transaction is sent to the signer twice. The first request has the query version 0x100000000000000000000000000000003, which the validator uses only to estimate the fee: a transaction with this version can't be included in a block. The second request has version 0x3, with the resource bounds set from that estimate, and its signature is the one sent to the network. The signer must hash the transaction with the version it receives, as the provided implementation does.

Response Format​

The signer wil then respond with the ECDSA signature values r and s, any other response not matching this format will fail loudly on the Validator side. The validator waits up to 15 seconds for the answer, exceeding data, it will log an error. Response example format:

{
"signature": [
"0xabc",
"0xdef"
]
}

In-House Signer​

As part of the validator, a remote signing server is provided for users to use or take as inspiration. Some certain level of development knowledge is expected here onwards.

To build the in-house signer service, from the project root, run:

make signer

Then set a private key which will be used to sign transactions and the HTTP address where the signer will receive POST requests from the validator program. For example using private key 0x123:

Start the compiled binary with an associated private key and an HTTP address from which it will receive the POST requests:

SIGNER_PRIVATE_KEY="0x123" ./build/signer \
--address localhost:8080

On a separate terminal, simulate a transaction POST request:

curl -X POST http://localhost:8080/sign \
-H "Content-Type: application/json" \
-d '{
"transaction": {
"type": "INVOKE",
"sender_address": "0x11efbf2806a9f6fe043c91c176ed88c38907379e59d2d3413a00eeeef08aa7e",
"calldata": [
"0x1",
"0x4862e05d00f2d0981c4a912269c21ad99438598ab86b6e70d1cee267caaa78d",
"0x37446750a403c1b4014436073cf8d08ceadc5b156ac1c8b7b0ca41a0c9c1c54",
"0x1",
"0x6521dd8f51f893a8580baedc249f1afaf7fd999c88722e607787970697dd76"
],
"version": "0x3",
"signature": [
"0x6711bfe51870a9874af883ca974b94fef85200d5772db5792013644dc9dd16a",
"0x23e345b39ffc43a92ab6735bf3f11e7dac1aa931d8c9647a1a2957f759b8baa"
],
"nonce": "0x194",
"resource_bounds": {
"l1_gas": {
"max_amount": "0x0",
"max_price_per_unit": "0x57e48bc504e79"
},
"l1_data_gas": {
"max_amount": "0x450",
"max_price_per_unit": "0xa54"
},
"l2_gas": {
"max_amount": "0xc92ca0",
"max_price_per_unit": "0x1b5aea1cb"
}
},
"tip": "0x0",
"paymaster_data": [],
"account_deployment_data": [],
"nonce_data_availability_mode": "L1",
"fee_data_availability_mode": "L1"
},
"chain_id": "0x534e5f5345504f4c4941"
}'

You should immediately get the following answer. Signature should match given that the same private key and transaction data was used in both console commands.

{
"signature": [
"0x12bf16c46782eb88570942ce126b2284bfb46b21c4b071a116bc0a6cffff35e",
"0x69abdfe5ba5b24dbbb2b9ccc3c02b03f46c505d3aa8b37d3a4bb3d6b1a81ded"
]
}

This shows that the signer is working correctly.

You can now start the validator with the signer URL and operational address so it signs attestation transactions remotely. See the external signing example for the Docker and binary commands.