Skip to content

Commit

Permalink
add accumulator into rpc response
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea committed Dec 6, 2023
1 parent 268fae9 commit a7add3e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 32 deletions.
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "5f1ec833718efa0


[patch."https://github.com/axiom-crypto/halo2-lib"]
halo2-base = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [
"halo2-pse",
"display",
"jemallocator",
] }
halo2-ecc = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [
"halo2-pse",
"jemallocator",
] }
zkevm-hashes = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false }
# halo2-base = { path = "../halo2-lib/halo2-base", default-features = false, features = [
# halo2-base = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [
# "halo2-pse",
# "display",
# "jemallocator",
# ] }
# halo2-ecc = { path = "../halo2-lib/halo2-ecc", default-features = false, features = [
# halo2-ecc = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false, features = [
# "halo2-pse",
# "jemallocator",
# ] }
# zkevm-hashes = { path = "../halo2-lib/hashes/zkevm", default-features = false }
# zkevm-hashes = { git = "https://github.com/timoftime/halo2-lib", branch = "feat/zkevm-sha256-builder", default-features = false }
halo2-base = { path = "../halo2-lib/halo2-base", default-features = false, features = [
"halo2-pse",
"display",
] }
halo2-ecc = { path = "../halo2-lib/halo2-ecc", default-features = false, features = [
"halo2-pse",
] }
zkevm-hashes = { path = "../halo2-lib/hashes/zkevm", default-features = false }


[patch."https://github.com/axiom-crypto/snark-verifier.git"]
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/RotateLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ library RotateLib {
* @param args The arguments for the sync step
* @return The public input commitment that can be sent to the verifier contract.
*/
function toPublicInputs(RotateInput memory args, bytes32 finalizedHeaderRoot, uint256[12] memory blsAccumulator) internal pure returns (uint256[77] memory) {
function toPublicInputs(RotateInput memory args, bytes32 finalizedHeaderRoot, uint256[12] memory accumulator) internal pure returns (uint256[77] memory) {
uint256[77] memory inputs;

for (uint256 i = 0; i < blsAccumulator.length; i++) {
inputs[i] = blsAccumulator[i];
for (uint256 i = 0; i < accumulator.length; i++) {
inputs[i] = accumulator[i];
}

inputs[blsAccumulator.length] = uint256(EndianConversions.toLittleEndian(uint256(args.syncCommitteePoseidon)));
inputs[accumulator.length] = uint256(EndianConversions.toLittleEndian(uint256(args.syncCommitteePoseidon)));

uint256 syncCommitteeSSZNumeric = uint256(args.syncCommitteeSSZ);
for (uint256 i = 0; i < 32; i++) {
inputs[blsAccumulator.length + 32 - i] = syncCommitteeSSZNumeric % 2 ** 8;
inputs[accumulator.length + 32 - i] = syncCommitteeSSZNumeric % 2 ** 8;
syncCommitteeSSZNumeric = syncCommitteeSSZNumeric / 2 ** 8;
}

uint256 finalizedHeaderRootNumeric = uint256(finalizedHeaderRoot);
for (uint256 j = 0; j < 32; j++) {
inputs[blsAccumulator.length + 64 - j] = finalizedHeaderRootNumeric % 2 ** 8;
inputs[accumulator.length + 64 - j] = finalizedHeaderRootNumeric % 2 ** 8;
finalizedHeaderRootNumeric = finalizedHeaderRootNumeric / 2 ** 8;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/src/Spectre.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract Spectre {
/// @param rotateProof The proof for the rotation
/// @param stepInput The input to the sync step.
/// @param stepProof The proof for the sync step
function rotate(RotateLib.RotateInput calldata rotateInput, bytes calldata rotateProof, SyncStepLib.SyncStepInput calldata stepInput, bytes calldata stepProof, uint256[12] memory blsAccumulator) external {
function rotate(RotateLib.RotateInput calldata rotateInput, bytes calldata rotateProof, SyncStepLib.SyncStepInput calldata stepInput, bytes calldata stepProof, uint256[12] memory accumulator) external {
// *step phase*
// This allows trusting that the current sync committee has signed off on the finalizedHeaderRoot which is used as the base of the SSZ proof
// that checks the new committee is in the beacon state 'next_sync_committee' field. It also allows trusting the finalizedSlot which is
Expand All @@ -85,7 +85,7 @@ contract Spectre {
// that there exists an SSZ proof that can verify this SSZ commitment to the committee is in the state
uint256 currentPeriod = getSyncCommitteePeriod(stepInput.finalizedSlot);
uint256 nextPeriod = currentPeriod + 1;
uint256[77] memory verifierInput = rotateInput.toPublicInputs(stepInput.finalizedHeaderRoot, blsAccumulator);
uint256[77] memory verifierInput = rotateInput.toPublicInputs(stepInput.finalizedHeaderRoot, accumulator);
bool rotateSuccess = committeeUpdateVerifier.verify(verifierInput, rotateProof);
if (!rotateSuccess) {
revert("Rotation proof verification failed");
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/RotateExternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { RotateLib } from "../src/RotateLib.sol";
contract RotateExternal {
using RotateLib for RotateLib.RotateInput;

function toPublicInputs(RotateLib.RotateInput calldata args, bytes32 finalizedHeaderRoot, uint256[12] memory blsAccumulator) public pure returns (uint256[] memory) {
uint256[77] memory commitment = args.toPublicInputs(finalizedHeaderRoot, blsAccumulator);
function toPublicInputs(RotateLib.RotateInput calldata args, bytes32 finalizedHeaderRoot, uint256[12] memory accumulator) public pure returns (uint256[] memory) {
uint256[77] memory commitment = args.toPublicInputs(finalizedHeaderRoot, accumulator);
// copy all elements into a dynamic array. We need to do this because ethers-rs has a bug that can't support uint256[65] return types
uint256[] memory result = new uint256[](77);
for (uint256 i = 0; i < commitment.length; i++) {
Expand Down
1 change: 0 additions & 1 deletion lightclient-circuits/src/gadget/crypto/sha256_wide/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ impl<F: Field> VirtualRegionManager<F> for ShaBitGateManager<F> {
type Config = Sha256CircuitConfig<F>;

fn assign_raw(&self, config: &Self::Config, region: &mut Region<F>) {
// config.annotate_columns_in_region(region);
let mut copy_manager = self.copy_manager.lock().unwrap();

config
Expand Down
24 changes: 16 additions & 8 deletions prover/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use url::Url;
pub type JsonRpcServerState = Arc<JsonRpcServer<JsonRpcMapRouter>>;

use crate::rpc_api::{
EvmProofResult, GenProofRotationParams, GenProofRotationWithWitnessParams, GenProofStepParams,
GenProofStepWithWitnessParams, SyncCommitteePoseidonParams, SyncCommitteePoseidonResult,
EVM_PROOF_ROTATION_CIRCUIT, EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS, EVM_PROOF_STEP_CIRCUIT,
AggregatedEvmProofResult, EvmProofResult, GenProofRotationParams,
GenProofRotationWithWitnessParams, GenProofStepParams, GenProofStepWithWitnessParams,
SyncCommitteePoseidonParams, SyncCommitteePoseidonResult, EVM_PROOF_ROTATION_CIRCUIT,
EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS, EVM_PROOF_STEP_CIRCUIT,
EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS, SYNC_COMMITTEE_POSEIDON_COMPRESSED,
SYNC_COMMITTEE_POSEIDON_UNCOMPRESSED,
};
Expand Down Expand Up @@ -142,17 +143,20 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_handler(
let public_inputs = instances[0]
.iter()
.map(|pi| U256::from_little_endian(&pi.to_bytes()))
.collect();
.collect_vec();
let mut accumulator = [U256::zero(); 12];
accumulator.clone_from_slice(&public_inputs[0..12]);

Ok(EvmProofResult {
Ok(AggregatedEvmProofResult {
proof,
accumulator,
public_inputs,
})
}

pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler(
Params(params): Params<GenProofRotationWithWitnessParams>,
) -> Result<EvmProofResult, JsonRpcError> {
) -> Result<AggregatedEvmProofResult, JsonRpcError> {
let GenProofRotationWithWitnessParams {
spec,
light_client_update,
Expand Down Expand Up @@ -221,9 +225,13 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler(
let public_inputs = instances[0]
.iter()
.map(|pi| U256::from_little_endian(&pi.to_bytes()))
.collect();
Ok(EvmProofResult {
.collect_vec();
let mut accumulator = [U256::zero(); 12];
accumulator.clone_from_slice(&public_inputs[0..12]);

Ok(AggregatedEvmProofResult {
proof,
accumulator,
public_inputs,
})
}
Expand Down
7 changes: 7 additions & 0 deletions prover/src/rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ pub struct EvmProofResult {
pub public_inputs: Vec<U256>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AggregatedEvmProofResult {
pub proof: Vec<u8>,
pub accumulator: [U256; 12],
pub public_inputs: Vec<U256>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncCommitteePoseidonParams {
pub pubkeys: Vec<Vec<u8>>,
Expand Down

0 comments on commit a7add3e

Please sign in to comment.