Skip to content

Commit c077781

Browse files
chore: bump SP1 version in ZK game tutorial (#133)
Bumps the version of SP1 in the ZK game tutorial
1 parent ed4225b commit c077781

File tree

15 files changed

+886
-1280
lines changed

15 files changed

+886
-1280
lines changed

code/zk-game/Cargo.lock

Lines changed: 299 additions & 644 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

code/zk-game/backend/api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ edition = "2021"
44

55
[dependencies]
66
rocket = { version = "0.5.1", features = ["json"] }
7-
sp1-sdk = "4.0.0-rc.3"
7+
sp1-sdk = "5.0.0"
88
hex = "0.4.3"
99
uuid = { version = "1.11.0", features = ["v4"] }
1010
rocket_ws = { version ="0.1.1" }
3.04 KB
Binary file not shown.

code/zk-game/backend/script/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
# ANCHOR: script-deps
77
[dependencies]
8-
sp1-sdk = "4.0.0-rc.3"
8+
sp1-sdk = "5.0.0"
99
hex = "0.4.3"
1010
alloy-sol-types = { workspace = true }
1111
game-lib = { path = "../../game_lib" }

code/zk-game/backend/sp1_program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ edition = "2021"
66
# ANCHOR: program-deps
77
[dependencies]
88
alloy-sol-types = { workspace = true }
9-
sp1-zkvm = "4.0.0-rc.3"
9+
sp1-zkvm = "5.0.0"
1010
game-lib = { path = "../../game_lib" }
1111
# ANCHOR_END: program-deps

code/zk-game/contracts/bun.lock

Lines changed: 35 additions & 33 deletions
Large diffs are not rendered by default.

code/zk-game/contracts/contracts/Groth16Verifier.sol

Lines changed: 496 additions & 543 deletions
Large diffs are not rendered by default.
Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,53 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.20;
33

4-
import {ISP1Verifier, ISP1VerifierWithHash} from "./ISP1Verifier.sol";
5-
import {Groth16Verifier} from "./Groth16Verifier.sol";
4+
import { ISP1Verifier, ISP1VerifierWithHash } from './ISP1Verifier.sol';
5+
import { Groth16Verifier } from './Groth16Verifier.sol';
66

77
/// @title SP1 Verifier
88
/// @author Succinct Labs
99
/// @notice This contracts implements a solidity verifier for SP1.
1010
contract SP1Verifier is Groth16Verifier, ISP1VerifierWithHash {
11-
/// @notice Thrown when the verifier selector from this proof does not match the one in this
12-
/// verifier. This indicates that this proof was sent to the wrong verifier.
13-
/// @param received The verifier selector from the first 4 bytes of the proof.
14-
/// @param expected The verifier selector from the first 4 bytes of the VERIFIER_HASH().
15-
error WrongVerifierSelector(bytes4 received, bytes4 expected);
16-
17-
/// @notice Thrown when the proof is invalid.
18-
error InvalidProof();
19-
20-
function VERSION() external pure returns (string memory) {
21-
return "v4.0.0-rc.3";
22-
}
23-
24-
/// @inheritdoc ISP1VerifierWithHash
25-
function VERIFIER_HASH() public pure returns (bytes32) {
26-
return 0x11b6a09d63d255ad425ee3a7f6211d5ec63fbde9805b40551c3136275b6f4eb4;
11+
/// @notice Thrown when the verifier selector from this proof does not match the one in this
12+
/// verifier. This indicates that this proof was sent to the wrong verifier.
13+
/// @param received The verifier selector from the first 4 bytes of the proof.
14+
/// @param expected The verifier selector from the first 4 bytes of the VERIFIER_HASH().
15+
error WrongVerifierSelector(bytes4 received, bytes4 expected);
16+
17+
/// @notice Thrown when the proof is invalid.
18+
error InvalidProof();
19+
20+
function VERSION() external pure returns (string memory) {
21+
return 'v5.0.0';
22+
}
23+
24+
/// @inheritdoc ISP1VerifierWithHash
25+
function VERIFIER_HASH() public pure returns (bytes32) {
26+
return 0xa4594c59bbc142f3b81c3ecb7f50a7c34bc9af7c4c444b5d48b795427e285913;
27+
}
28+
29+
/// @notice Hashes the public values to a field elements inside Bn254.
30+
/// @param publicValues The public values.
31+
function hashPublicValues(bytes calldata publicValues) public pure returns (bytes32) {
32+
return sha256(publicValues) & bytes32(uint256((1 << 253) - 1));
33+
}
34+
35+
/// @notice Verifies a proof with given public values and vkey.
36+
/// @param programVKey The verification key for the RISC-V program.
37+
/// @param publicValues The public values encoded as bytes.
38+
/// @param proofBytes The proof of the program execution the SP1 zkVM encoded as bytes.
39+
function verifyProof(bytes32 programVKey, bytes calldata publicValues, bytes calldata proofBytes) external view {
40+
bytes4 receivedSelector = bytes4(proofBytes[:4]);
41+
bytes4 expectedSelector = bytes4(VERIFIER_HASH());
42+
if (receivedSelector != expectedSelector) {
43+
revert WrongVerifierSelector(receivedSelector, expectedSelector);
2744
}
2845

29-
/// @notice Hashes the public values to a field elements inside Bn254.
30-
/// @param publicValues The public values.
31-
function hashPublicValues(bytes calldata publicValues) public pure returns (bytes32) {
32-
return sha256(publicValues) & bytes32(uint256((1 << 253) - 1));
33-
}
34-
35-
/// @notice Verifies a proof with given public values and vkey.
36-
/// @param programVKey The verification key for the RISC-V program.
37-
/// @param publicValues The public values encoded as bytes.
38-
/// @param proofBytes The proof of the program execution the SP1 zkVM encoded as bytes.
39-
function verifyProof(
40-
bytes32 programVKey,
41-
bytes calldata publicValues,
42-
bytes calldata proofBytes
43-
) external view {
44-
bytes4 receivedSelector = bytes4(proofBytes[:4]);
45-
bytes4 expectedSelector = bytes4(VERIFIER_HASH());
46-
if (receivedSelector != expectedSelector) {
47-
revert WrongVerifierSelector(receivedSelector, expectedSelector);
48-
}
49-
50-
bytes32 publicValuesDigest = hashPublicValues(publicValues);
51-
uint256[2] memory inputs;
52-
inputs[0] = uint256(programVKey);
53-
inputs[1] = uint256(publicValuesDigest);
54-
uint256[8] memory proof = abi.decode(proofBytes[4:], (uint256[8]));
55-
this.Verify(proof, inputs);
56-
}
57-
}
46+
bytes32 publicValuesDigest = hashPublicValues(publicValues);
47+
uint256[2] memory inputs;
48+
inputs[0] = uint256(programVKey);
49+
inputs[1] = uint256(publicValuesDigest);
50+
uint256[8] memory proof = abi.decode(proofBytes[4:], (uint256[8]));
51+
this.Verify(proof, inputs);
52+
}
53+
}

code/zk-game/contracts/hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const config: HardhatUserConfig = {
4242
},
4343
},
4444
zksolc: {
45-
version: 'latest',
45+
version: '1.5.15',
4646
settings: {
4747
codegen: 'yul',
4848
// find all available options in the official documentation

code/zk-game/contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@matterlabs/hardhat-zksync": "^1.5.0",
19-
"@matterlabs/zksync-contracts": "^1.0.0-beta.8",
19+
"@matterlabs/zksync-contracts": "^1.0.0-alpha.9",
2020
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
2121
"@nomicfoundation/hardhat-verify": "^2.0.13",
2222
"@openzeppelin/contracts": "^5.3.0",

0 commit comments

Comments
 (0)