Skip to content

Commit

Permalink
refactor(contracts): change some public modifiers to external
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocao committed Dec 12, 2024
1 parent acbbab6 commit 1f7eb9d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion contracts/core/SedaCoreV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract SedaCoreV1 is ISedaCore, RequestHandlerBase, ResultHandlerBase, UUPSUpg
__UUPSUpgradeable_init();
}

// ============ External Functions ============
// ============ Public Functions ============

/// @inheritdoc RequestHandlerBase
/// @dev Overrides the base implementation to also add the request ID and timestamp to storage
Expand Down
16 changes: 9 additions & 7 deletions contracts/core/abstract/RequestHandlerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ abstract contract RequestHandlerBase is IRequestHandler {

// ============ External Functions ============

/// @notice Derives a request ID from the given inputs
/// @param inputs The request inputs
/// @return The derived request ID
function deriveRequestId(SedaDataTypes.RequestInputs calldata inputs) external pure returns (bytes32) {
return SedaDataTypes.deriveRequestId(inputs);
}

// ============ Public Functions ============

/// @inheritdoc IRequestHandler
function postRequest(
SedaDataTypes.RequestInputs calldata inputs
Expand Down Expand Up @@ -67,13 +76,6 @@ abstract contract RequestHandlerBase is IRequestHandler {
return _requestHandlerStorage().requests[requestId];
}

/// @notice Derives a request ID from the given inputs
/// @param inputs The request inputs
/// @return The derived request ID
function deriveRequestId(SedaDataTypes.RequestInputs calldata inputs) public pure returns (bytes32) {
return SedaDataTypes.deriveRequestId(inputs);
}

// ============ Internal Functions ============

/// @notice Returns the storage struct for the contract
Expand Down
64 changes: 32 additions & 32 deletions contracts/core/abstract/ResultHandlerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ abstract contract ResultHandlerBase is IResultHandler, Initializable {

// ============ External Functions ============

/// @inheritdoc IResultHandler
function getSedaProver() external view override(IResultHandler) returns (address) {
return address(_resultHandlerStorage().sedaProver);
}

/// @notice Verifies the result without storing it
/// @param result The result to verify
/// @param batchHeight The height of the batch the result belongs to
/// @param proof The proof associated with the result
/// @return A boolean indicating whether the result is valid
function verifyResult(
SedaDataTypes.Result calldata result,
uint64 batchHeight,
bytes32[] calldata proof
) external view returns (bytes32) {
bytes32 resultId = SedaDataTypes.deriveResultId(result);
if (!_resultHandlerStorage().sedaProver.verifyResultProof(resultId, batchHeight, proof)) {
revert InvalidResultProof(resultId);
}

return resultId;
}

/// @notice Derives a result ID from the given result
/// @param result The result data
/// @return The derived result ID
function deriveResultId(SedaDataTypes.Result calldata result) external pure returns (bytes32) {
return SedaDataTypes.deriveResultId(result);
}

// ============ Public Functions ============

/// @inheritdoc IResultHandler
function postResult(
SedaDataTypes.Result calldata result,
Expand All @@ -62,8 +94,6 @@ abstract contract ResultHandlerBase is IResultHandler, Initializable {
return resultId;
}

// ============ Public View Functions ============

/// @inheritdoc IResultHandler
function getResult(bytes32 requestId) public view override(IResultHandler) returns (SedaDataTypes.Result memory) {
SedaDataTypes.Result memory result = _resultHandlerStorage().results[requestId];
Expand All @@ -73,36 +103,6 @@ abstract contract ResultHandlerBase is IResultHandler, Initializable {
return _resultHandlerStorage().results[requestId];
}

/// @inheritdoc IResultHandler
function getSedaProver() public view override(IResultHandler) returns (address) {
return address(_resultHandlerStorage().sedaProver);
}

/// @notice Verifies the result without storing it
/// @param result The result to verify
/// @param batchHeight The height of the batch the result belongs to
/// @param proof The proof associated with the result
/// @return A boolean indicating whether the result is valid
function verifyResult(
SedaDataTypes.Result calldata result,
uint64 batchHeight,
bytes32[] calldata proof
) public view returns (bytes32) {
bytes32 resultId = SedaDataTypes.deriveResultId(result);
if (!_resultHandlerStorage().sedaProver.verifyResultProof(resultId, batchHeight, proof)) {
revert InvalidResultProof(resultId);
}

return resultId;
}

/// @notice Derives a result ID from the given result
/// @param result The result data
/// @return The derived result ID
function deriveResultId(SedaDataTypes.Result calldata result) public pure returns (bytes32) {
return SedaDataTypes.deriveResultId(result);
}

// ============ Internal Functions ============

/// @notice Returns the storage struct for the contract
Expand Down
12 changes: 6 additions & 6 deletions contracts/provers/Secp256k1ProverV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract Secp256k1ProverV1 is ProverBase, Initializable, UUPSUpgradeable, Ownabl
SedaDataTypes.Batch calldata newBatch,
bytes[] calldata signatures,
SedaDataTypes.ValidatorProof[] calldata validatorProofs
) public override {
) external override(ProverBase) {
Secp256k1ProverStorage storage s = _storageV1();
// Check that new batch invariants hold
if (newBatch.batchHeight <= s.lastBatchHeight) {
Expand Down Expand Up @@ -117,7 +117,7 @@ contract Secp256k1ProverV1 is ProverBase, Initializable, UUPSUpgradeable, Ownabl
emit BatchPosted(newBatch.batchHeight, batchId);
}

// ============ Public View Functions ============
// ============ External View Functions ============

/// @notice Verifies a result proof against a batch's results root
/// @param resultId The ID of the result to verify
Expand All @@ -128,28 +128,28 @@ contract Secp256k1ProverV1 is ProverBase, Initializable, UUPSUpgradeable, Ownabl
bytes32 resultId,
uint64 batchHeight,
bytes32[] calldata merkleProof
) public view override returns (bool) {
) external view override(ProverBase) returns (bool) {
Secp256k1ProverStorage storage s = _storageV1();
bytes32 leaf = keccak256(abi.encodePacked(RESULT_DOMAIN_SEPARATOR, resultId));
return MerkleProof.verify(merkleProof, s.batchToResultsRoot[batchHeight], leaf);
}

/// @notice Returns the last processed batch height
/// @return The height of the last batch
function getLastBatchHeight() public view override returns (uint64) {
function getLastBatchHeight() external view override returns (uint64) {
return _storageV1().lastBatchHeight;
}

/// @notice Returns the last validators root hash
/// @return The Merkle root of the last validator set
function getLastValidatorsRoot() public view returns (bytes32) {
function getLastValidatorsRoot() external view returns (bytes32) {
return _storageV1().lastValidatorsRoot;
}

/// @notice Returns the results root for a specific batch height
/// @param batchHeight The batch height to query
/// @return The results root for the specified batch
function getBatchResultsRoot(uint64 batchHeight) public view returns (bytes32) {
function getBatchResultsRoot(uint64 batchHeight) external view returns (bytes32) {
return _storageV1().batchToResultsRoot[batchHeight];
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/provers/abstract/ProverBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ abstract contract ProverBase is IProver {
SedaDataTypes.Batch calldata newBatch,
bytes[] calldata signatures,
SedaDataTypes.ValidatorProof[] calldata validatorProofs
) public virtual override(IProver);
) external virtual override(IProver);

/// @inheritdoc IProver
function verifyResultProof(
bytes32 resultId,
uint64 batchHeight,
bytes32[] calldata merkleProof
) public view virtual override(IProver) returns (bool);
) external view virtual override(IProver) returns (bool);

/// @inheritdoc IProver
function getLastBatchHeight() external view virtual override(IProver) returns (uint64);
Expand Down

0 comments on commit 1f7eb9d

Please sign in to comment.