feat: support multi-cycle instruction and add sha extend precompile. #1213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Sha extend circuit
This PR adds sha extend precompile, computing the parameter
w[0..64]defined as follows:The sha extend circuit consists of 48 cycles. In each cycle, it fetches the instruction at the same pc as the first cycle, reads the same register, and defines the global state with increasing cycles. I each instance, it reads w[i - 2], w[i - 7], w[i - 15], w[i - 16] from the memory and computes w[i] and writes it back.
Support multi-cycle instruction in
ceno_emulTo support multi-cycle instruction in
ceno_emul, we store aOption<MultiCycleState>objectpending_multi_cycle_insninVMState, and if it isSome(insn, state), we generate the nextstepfromstate.Support rotation with length 63
Since the number of rounds in SHA256 is 64, we support the 63-element cycle defined by
X^6 + X + 1. The indices could be generated by the following sage code:Tiny change of
SelectTypeLayoutThe original definition is as follows:
while they are sometimes duplicated and in sha extend circuit, it needs to set
round_i = 16in the first round and updatepcduring the last round. Therefore, the definition is changed as follows: