-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathStateTransition.sol
More file actions
67 lines (56 loc) · 1.96 KB
/
StateTransition.sol
File metadata and controls
67 lines (56 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract StateTransition {
event StateUpdated(bytes32);
event ProgramIdUpdated(bytes32);
error OnlyOwner(address);
error AlignedVerifyProofInclusionCallFailed();
error ProofVerificationFailed();
error PrevStateRootDidNotMatch();
bytes32 public PROGRAM_ID;
bytes32 public stateRoot;
address public alignedProofAggregator;
address public owner;
constructor(bytes32 programId, bytes32 initialStateRoot, address _alignedProofAggregator, address _owner) {
alignedProofAggregator = _alignedProofAggregator;
owner = _owner;
PROGRAM_ID = programId;
stateRoot = initialStateRoot;
}
function updateState(uint8 provingSystemId, bytes calldata publicInputs, bytes32[] calldata merkleProof)
public
onlyOwner
{
bytes memory callData = abi.encodeWithSignature(
"verifyProofInclusion(bytes32[],uint8,bytes32,bytes)",
merkleProof,
provingSystemId,
PROGRAM_ID,
publicInputs
);
(bool callResult, bytes memory response) = alignedProofAggregator.staticcall(callData);
if (!callResult) {
revert AlignedVerifyProofInclusionCallFailed();
}
bool proofVerified = abi.decode(response, (bool));
if (!proofVerified) {
revert ProofVerificationFailed();
}
(bytes32 prevStateRoot, bytes32 newStateRoot) = abi.decode(publicInputs, (bytes32, bytes32));
if (prevStateRoot != stateRoot) {
revert PrevStateRootDidNotMatch();
}
stateRoot = newStateRoot;
emit StateUpdated(stateRoot);
}
function setProgramId(bytes32 programId) public onlyOwner {
PROGRAM_ID = programId;
emit ProgramIdUpdated(PROGRAM_ID);
}
modifier onlyOwner() {
if (msg.sender != owner) {
revert OnlyOwner(msg.sender);
}
_;
}
}