Skip to content

Instantly share code, notes, and snippets.

@puma314
Last active August 18, 2023 01:46
Show Gist options
  • Save puma314/6bf27edd39a30419f8feeee884f41488 to your computer and use it in GitHub Desktop.
Save puma314/6bf27edd39a30419f8feeee884f41488 to your computer and use it in GitHub Desktop.

Succinct Open Source Challenge

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]...)
	}

	// Compute SHA256 hash
	hash := sha256.Sum256(concatenatedBytes)

	return hash
}

Feel free to use any proving system of your choice. There is a naive solution and an optimized solution, so try to minimize your constraint count! We have provided helpful links for both circom and plonky2. When complete, send us a link to a Github repository or a Gist/pastebin of your implementation to opensource@succinct.xyz along with a short writeup describing the approach.

Circom resources

When using circom, you can get started by pasting the starter template into https://zkrepl.dev/, an online IDE for circom. There are other helpful resources below.

Plonky2 Resources (Rust-based proving framework)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment