forge-exec-ipc-client

Execute a program as a separate process and connect to it via IPC.

Used by forge-exec to establish a open 2-way communication channel with forge

Because forge expect ffi output to be given to stdout after program exit, forge-exec-ipc-client is executed for every message pair and exit on each reply from the program.

how does it work?

forge-exec is used in your forge project and will do the following

ipc-server implementations

While you could write the ipc handling yourself in the program executed by forge-exec-ipc-client it is likely you want that abstracted.

There is currentlty one implemented in typescript which abstract away the flow and let you write the following:

js import { execute } from "forge-exec-ipc-server"; execute(async (forge) => { const address = await forge.create({ from: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", data: "0x608060405234801561001057600080fd5b5060f78061001f6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60006001820160ba57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220f0cfb2159c518c3da0ad864362bad5dc0715514a9ab679237253d506773a0a1b64736f6c63430008130033", }); return { types: [{ type: "address" }], values: [address], }; });

forge-exec-ipc-server also handle timeout.

Note that while nodejs has a startup overhead, once the program is executed it stays alive and so long complicate script are possible.

format

The format of communication between the ipc client and server is as follow:

From the program

The program (which act as the ipc server) can only send one type of message to the ipc client.

All of them must end with the \n character which act as the ipc message delimiter

These are abi encoded message represented as hex string and are forwarded as is (minus the \n character) to forge-exec solidity code.

The format to encode is a tuple (uint32, bytes) where the uint32 represent the type of request and bytes is the abi encoded data specific to the request type.

The request type 0 is the termination signal and indicate that the program has finished executing, the bytes data represent whatever the program want and is what is returned by forge-exec execute function call.

Else there is currently 2 more request with more going to be added soon

See list of requests

From forge

there is only 2 type of data send to the ipc server: response and terminate.

All of them must end with the \n character

Responses

Responses are prefixed with response:

the first message the program actually receive is a special one : response:0x\n and just indicate that the program can start executing and make request back to forge.

Apart form this special request, there are currently on 2 types of request that a program can send back to forge and so there are only 2 types of response as of now

See list of requests

examples

Termination

Termination request are prefixed with terminate:

After the prefix is the error message

examples

List of Requests

termination

from the program

example:

encode(["uint32", "bytes"],[0, "0x01"])

This will terminate execution and return 0x1 as bytes

Nothing is expected from forge back

send transaction

from the program

example:

encode(["uint32", "bytes"],[1, encode(["","","",""], [])])

from forge-exec-ipc-client

example:

"response:0xFFEEFFEEFFEEFFEEFFEEFFEEFFEEFFEEFFEEFFEE\n"

this return the deployed contract address