Working with variable length computations in a circuit is tricky because of the requirement to have a fixed computational graph. This challenge is to implement variable length SHA256 as a circuit. The circuit should have a public input called input_bytes
: a fixed size array of size 10 with 32 byte entries. The other public input should be length
: how many of the array entries should be hashed. The circuit output should be the sha256
hash of the first length
entries in the array. You should only hash length * 32
bytes, and do not hash any extra zero bytes (this is the tricky part to figure out)! Golang pseudocode below:
func VariableLengthHash(input_bytes [10][32]byte, length int) [32]byte {
// Concatenate the bytes
var concatenatedBytes []byte
for i := 0; i < length; i++ {
concatenatedBytes = append(concatenatedBytes, input_bytes[i]...)