> For the complete documentation index, see [llms.txt](https://zkwasmdoc.gitbook.io/delphinus-zkwasm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zkwasmdoc.gitbook.io/delphinus-zkwasm/c1_beginner/c2_builtin/io.md).

# IO Functions

## Fetch External Inputs

Since a ZKP circuits distinguish between public inputs(instances) and private inputs(witness), ZKWASM supports two different way to fetch inputs from the user, **zkwasm\_input(1)** reads an public instance from the user and **zkwasm\_input(0)** reads a private input(witness).

```
extern "C" {
    zkwasm_input(bool) -> u64/i64
}
```

Suppose that a list of public inputs are specified via --public input1:i64 input2:i64 input3:i64 ..., then the following code should return an array of \[input1, input2, input3]

```
fn get_inputs() -> [u64; 3] {
    [
        wasm_input(1),
        wasm_input(1),
        wasm_input(1),
    ]
}
```

## Witness Queue.

The ZKWASM run time supports multiple queue. When the ZKWASM runs an image, the input witness queues is initialzed by a sequence of u64 specified by the ZKWASM running API (See command line args --private). Once this queue is specified, we can not change it and all the witness can be fetched from the beginning (start from index 0) by **zkwasm\_input(0)** one by one.

Suppose that a list of witness inputs are specified via --private input1:i64 input2:i64 input3:i64 ..., then the following code should return an array of \[input1, input2, input3]

```
fn get_witness() -> [u64; 3] {
    [
        wasm_input(0),
        wasm_input(0),
        wasm_input(0),
    ]
}
```

During the execution, we have another two different kinds of witness queues. The default witness queue and the indexed witness queue.To insert and pop witness to default witness queue we can use **wasm\_witness\_insert** and **wasm\_witness\_pop**. To insert and pop indexed witness queue, we need to follow the convention of specifiying the witness queue index first (via **wasm\_witness\_set\_index(index)**) and then calling **wasm\_witness\_indexed\_pop** or **wasm\_witness\_indexed\_insert**.

## Manipulate witness

extern "C" { /// inserts a witness at the current wasm\_private inputs cursor pub fn wasm\_witness\_insert(u: u64); pub fn wasm\_witness\_pop() -> u64; pub fn wasm\_witness\_set\_index(x: u64); pub fn wasm\_witness\_indexed\_pop() -> u64; pub fn wasm\_witness\_indexed\_insert(x: u64); pub fn wasm\_witness\_indexed\_push(x: u64); pub fn require(cond: bool); }

**Example add some witness to the default witness group**

```
unsafe {
    wasm_witness_set_index(i);
    wasm_witness_indexed_push(0x0);
    wasm_witness_indexed_push(0x1);
    wasm_witness_indexed_insert(0x2);
    let a = wasm_witness_indexed_pop();
    require(a == 0x1);
    let a = wasm_witness_indexed_pop();
    require(a == 0x0);
    let a = wasm_witness_indexed_pop();
    require(a == 0x2);
}
```

**Example add some witness to a witness group = i**

```
unsafe {
    wasm_witness_set_index(i);
    wasm_witness_indexed_push(0x0);
    wasm_witness_indexed_push(0x1);
    wasm_witness_indexed_insert(0x2);
    let a = wasm_witness_indexed_pop();
    require(a == 0x1);
    let a = wasm_witness_indexed_pop();
    require(a == 0x0);
    let a = wasm_witness_indexed_pop();
    require(a == 0x2);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://zkwasmdoc.gitbook.io/delphinus-zkwasm/c1_beginner/c2_builtin/io.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
