Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriian Chestnykh committed Jan 15, 2024
1 parent 311793d commit 82fa02d
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions contracts/verifiers/UniversalVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import {ICircuitValidator} from "../interfaces/ICircuitValidator.sol";
import {IZKPVerifier} from "../interfaces/IZKPVerifier.sol";
import {ArrayUtils} from "../lib/ArrayUtils.sol";

// TODO scripts (do we need it?)
//1. Who requested
//2. Who submitted

/// @title Universal Verifier Contract
/// @notice A contract to manage ZKP (Zero-Knowledge Proof) requests and proofs.
contract UniversalVerifier is OwnableUpgradeable {
Expand Down Expand Up @@ -270,6 +266,32 @@ contract UniversalVerifier is OwnableUpgradeable {
_callVerifyWithSender(requestId, inputs, a, b, c, _msgSender());
}

/// @notice Adds a raw value to the proof storage item for a given user, request ID and key
/// @param requestId The ID of the ZKP request
/// @param key The key of the storage item
/// @param rawValue The raw value to add
function addStorageFieldRawValue(
uint64 requestId,
string memory key,
bytes memory rawValue
) public {
address signer = _msgSender();
_getMainStorage().proofs[signer][requestId].storageFields[key].rawValue = rawValue;
emit AddStorageFieldRawValue(signer, requestId, key, rawValue);
}

/// @notice Gets the proof storage item for a given user, request ID and key
/// @param user The user's address
/// @param requestId The ID of the ZKP request
/// @return The proof
function getProofStorageField(
address user,
uint64 requestId,
string memory key
) public view returns (StorageField memory) {
return _getMainStorage().proofs[user][requestId].storageFields[key];
}

function _callVerifyWithSender(
uint64 requestId,
uint256[] calldata inputs,
Expand Down Expand Up @@ -299,30 +321,4 @@ contract UniversalVerifier is OwnableUpgradeable {
}
return request.validator.getSpecialInputPairs();
}

/// @notice Adds a raw value to the proof storage item for a given user, request ID and key
/// @param requestId The ID of the ZKP request
/// @param key The key of the storage item
/// @param rawValue The raw value to add
function addStorageFieldRawValue(
uint64 requestId,
string memory key,
bytes memory rawValue
) public {
address signer = _msgSender();
_getMainStorage().proofs[signer][requestId].storageFields[key].rawValue = rawValue;
emit AddStorageFieldRawValue(signer, requestId, key, rawValue);
}

/// @notice Gets the proof storage item for a given user, request ID and key
/// @param user The user's address
/// @param requestId The ID of the ZKP request
/// @return The proof
function getProofStorageField(
address user,
uint64 requestId,
string memory key
) public view returns (StorageField memory) {
return _getMainStorage().proofs[user][requestId].storageFields[key];
}
}

0 comments on commit 82fa02d

Please sign in to comment.