1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::fmt::Debug;

use axiom_circuit::axiom_eth::rlc::circuit::builder::RlcCircuitBuilder;
use axiom_sdk::{
    axiom::{AxiomAPI, AxiomComputeFn, AxiomComputeInput, AxiomResult},
    cmd::run_cli,
    halo2_base::{
        gates::{GateInstructions, RangeChip, RangeInstructions},
        AssignedValue,
    },
    Fr,
};

#[AxiomComputeInput]
pub struct RlcInput {
    pub a: u64,
    pub b: u64,
    pub c: u64,
}

impl AxiomComputeFn for RlcInput {
    type FirstPhasePayload = Vec<AssignedValue<Fr>>;

    fn compute(_: &mut AxiomAPI, _: RlcCircuitInput<AssignedValue<Fr>>) -> Vec<AxiomResult> {
        unimplemented!()
    }

    fn compute_phase0(
        _: &mut AxiomAPI,
        assigned_inputs: Self::Input<AssignedValue<Fr>>,
    ) -> (Vec<AxiomResult>, Self::FirstPhasePayload) {
        (
            vec![],
            vec![assigned_inputs.a, assigned_inputs.b, assigned_inputs.c],
        )
    }

    fn compute_phase1(
        builder: &mut RlcCircuitBuilder<Fr>,
        range: &RangeChip<Fr>,
        payload: Self::FirstPhasePayload,
    ) {
        let gate = range.gate();
        let rlc_chip = builder.rlc_chip(gate);
        let (ctx, rlc_ctx) = builder.rlc_ctx_pair();
        gate.add(ctx, payload[0], payload[1]);
        let x = vec![
            ctx.load_constant(Fr::from(1)),
            ctx.load_constant(Fr::from(2)),
        ];
        rlc_chip.compute_rlc_fixed_len(rlc_ctx, x);
    }
}

fn main() {
    env_logger::init();
    run_cli::<RlcInput>();
}