How to enter return values in publicInputs in case of array type?

My main function takes 2 public inputs and returns a public array of length 2 .

During verify(), How to enter the return values in publicInputs[]?
Currently I am entering them using a bytes32 array of length 4 . But it says it expects only 3 .

How to do this in solidity?

Thanks

29 Likes

Hey there, would you like to share a snippet and example inputs of your Noir code?

41 Likes
fn main(
  recipient: pub Field,        // Recipient of funds
  priv_key: Field,             // Private key of note
  note_root: pub Field,        // Merkle membership proof
  index: Field,                // Index of note in merkle tree
  note_hash_path: [Field; 3],  // Merkle path of note
  secret: Field,               // Private key
) -> pub [Field; 2] {
    // Derive public key from private key to show ownership
    let pubkey = derive_public_key(priv_key);
    
    // Compute commitment for note
    let note_commitment = create_commitment(pubkey[0], pubkey[1], secret);
    // std::println(note_commitment);
    // Compute nullifier for note
    let nullifier = check_nullifier(note_commitment, index, priv_key);
    std::println(nullifier);
    // Check that the input note commitment is in the root
    let is_member = test_merkle_membership(note_root, note_commitment, index, note_hash_path);

    // std::println(is_member);
    // Constraint check
    constrain is_member == 1;
    
    // Cannot have unused variables, return the recipient as public output of the circuit
    [nullifier, recipient]
}

42 Likes

the verifier takes an array of bytes32,
This is what I tried

function testClaim() public {
        splitter.LaunchTorpedo{value: 1 ether}(1 ether,0x10ab75288f0f92639577be3a15ee21d9a1fa41f236f0e88f3a61bda7c55ebae8);
        string memory proof = vm.readLine("./proofs/p.proof");
        bytes memory proof_in_bytes = vm.parseBytes(proof);
        bytes32[] memory publicInputs =  new bytes32[](4);
        publicInputs[0] = bytes32(0x0000000000000000000000001b37B1EC6B7faaCbB9AddCCA4043824F36Fb88D8);
        publicInputs[1] = bytes32(0x10ab75288f0f92639577be3a15ee21d9a1fa41f236f0e88f3a61bda7c55ebae8);
        publicInputs[2] = bytes32(0x2fdc3f51f01ae83932eb9755616a3a37715aff17f15c31ae1f19ce5d2e6429d6);
        publicInputs[3] = bytes32(0x0000000000000000000000001b37B1EC6B7faaCbB9AddCCA4043824F36Fb88D8);
        splitter.claimFuel(proof_in_bytes,publicInputs);
    }
8 Likes

It worked when I removed the last public Input[4] as it was repeating

44 Likes

Seems to be that noir recognize it as only 3 different values [recipient, note_root, nullifier].
@kevaundray, as I recall noir is normally yelling at you for returning inputs, should this not be the case when in lists? Seems like it should be either:

  • Don’t allow in and out
  • Allow both so there are 4 public outputs.

Right not it seems to land a bit in the middle where it is not clear what is really going on when building.

2 Likes