This repository was archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathOpHash.sol
More file actions
52 lines (45 loc) · 1.5 KB
/
OpHash.sol
File metadata and controls
52 lines (45 loc) · 1.5 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
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.15;
import "../../run/LibStackPointer.sol";
import "../../../array/LibUint256Array.sol";
import "../../../type/LibCast.sol";
import "../../run/LibInterpreterState.sol";
import "../../deploy/LibIntegrityCheck.sol";
import "hardhat/console.sol";
/// @title OpHash
/// @notice Opcode for hashing a list of values.
library OpHash {
using LibStackPointer for StackPointer;
using LibCast for uint256[];
using LibIntegrityCheck for IntegrityCheckState;
function f(uint256[] memory values_) internal pure returns (uint256) {
return uint256(keccak256(abi.encodePacked(values_)));
}
function integrity(
IntegrityCheckState memory integrityCheckState_,
Operand operand_,
StackPointer stackTop_
) internal pure returns (StackPointer) {
if (Operand.unwrap(operand_) == 0) {
revert OperandUnderflow(1, 0);
}
if (Operand.unwrap(operand_) > 255) {
revert OperandOverflow(255, Operand.unwrap(operand_));
}
return
integrityCheckState_.applyFn(
stackTop_,
f,
Operand.unwrap(operand_)
);
}
// Stack the return of `balanceOfBatch`.
// Operand will be the length
function run(
InterpreterState memory,
Operand operand_,
StackPointer stackTop_
) internal view returns (StackPointer) {
return stackTop_.applyFn(f, Operand.unwrap(operand_));
}
}