@@ -5,6 +5,7 @@ pragma solidity 0.8.23;
5
5
6
6
import {MAX_DEPTH} from "./Constants.sol " ;
7
7
import {SemaphoreVerifierKeyPts} from "./SemaphoreVerifierKeyPts.sol " ;
8
+ import "hardhat/console.sol " ;
8
9
9
10
contract SemaphoreVerifier {
10
11
// Scalar field size
@@ -34,6 +35,87 @@ contract SemaphoreVerifier {
34
35
SemaphoreVerifierKeyPts.checkInvariant (MAX_DEPTH);
35
36
}
36
37
38
+ function test () external view returns (bytes32 [3 ] memory ) {
39
+ // --- 0x06 ecAdd ---
40
+ uint256 [4 ] memory inputAdd = [
41
+ uint256 (5090583730862410755830979584235210054631184460526892606022709842010236308675 ),
42
+ // invalid g1.x
43
+ // uint256(0),
44
+ uint256 (4935746665478263580470501879719907639988899436008466660042851826337922233613 ),
45
+ uint256 (5090583730862410755830979584235210054631184460526892606022709842010236308675 ),
46
+ uint256 (4935746665478263580470501879719907639988899436008466660042851826337922233613 )
47
+ ];
48
+ assembly {
49
+ // ref: https://www.evm.codes/precompiled on ecAdd
50
+ let success := staticcall (150 , 0x06 , inputAdd, 0x80 , inputAdd, 0x40 )
51
+
52
+ if iszero (success) {
53
+ mstore (0 ,0 )
54
+ return (0 , 0x60 )
55
+ }
56
+ }
57
+
58
+ bytes32 addOut = abi.decode (abi.encode (inputAdd), (bytes32 ));
59
+ console.log ("addOut: %i " , uint256 (addOut));
60
+
61
+ // --- 0x07 ecMul ---
62
+ uint256 [3 ] memory inputMul = [
63
+ uint256 (5090583730862410755830979584235210054631184460526892606022709842010236308675 ),
64
+ // invalid g1.x
65
+ // uint256(5090583730862410755830979584235210054631184460526892606022709842010236308674),
66
+ uint256 (4935746665478263580470501879719907639988899436008466660042851826337922233613 ),
67
+ 2
68
+ // infinity scalar
69
+ // 0
70
+ ];
71
+ assembly {
72
+ // ref: https://www.evm.codes/precompiled on ecMul
73
+ let success := staticcall (6000 , 0x07 , inputMul, 0x60 , inputMul, 0x40 )
74
+
75
+ if iszero (success) {
76
+ mstore (0 ,0 )
77
+ return (0 , 0x60 )
78
+ }
79
+ }
80
+
81
+ bytes32 mulOut = abi.decode (abi.encode (inputMul), (bytes32 ));
82
+ console.log ("mulOut: %i " , uint256 (mulOut));
83
+
84
+ // --- 0x08 ecPairing ---
85
+ // The input must always be a multiple of 6 32-byte values.
86
+ uint256 [12 ] memory inputPairing = [
87
+ uint256 (3010198690406615200373504922352659861758983907867017329644089018310584441462 ),
88
+ uint256 (17861058253836152797273815394432013122766662423622084931972383889279925210507 ),
89
+ uint256 (7273165102799931111715871471550377909735733521218303035754523677688038059653 ),
90
+ uint256 (2725019753478801796453339367788033689375851816420509565303521482350756874229 ),
91
+ uint256 (957874124722006818841961785324909313781880061366718538693995380805373202866 ),
92
+ uint256 (2512659008974376214222774206987427162027254181373325676825515531566330959255 ),
93
+ uint256 (4503322228978077916651710446042370109107355802721800704639343137502100212473 ),
94
+ uint256 (6132642251294427119375180147349983541569387941788025780665104001559216576968 ),
95
+ uint256 (14583779054894525174450323658765874724019480979794335525732096752006891875705 ),
96
+ uint256 (18029695676650738226693292988307914797657423701064905010927197838374790804409 ),
97
+ uint256 (11474861747383700316476719153975578001603231366361248090558603872215261634898 ),
98
+ uint256 (2140229616977736810657479771656733941598412651537078903776637920509952744750 )
99
+ // switched y2, y1 to be invalid
100
+ // uint256(2140229616977736810657479771656733941598412651537078903776637920509952744750),
101
+ // uint256(11474861747383700316476719153975578001603231366361248090558603872215261634898)
102
+ ];
103
+ assembly {
104
+ // ref: https://www.evm.codes/precompiled on ecPairing
105
+ // formula: 45000 + 34000 * (bytes/192)
106
+ let success := staticcall (113000 , 0x08 , inputPairing, 0x180 , inputPairing, 0x20 )
107
+
108
+ // Specified 0 gas cost to make it returning false
109
+ if iszero (success) {
110
+ mstore (inputPairing, 0 )
111
+ }
112
+ }
113
+ bytes32 pairingOut = abi.decode (abi.encode (inputPairing), (bytes32 ));
114
+ console.log ("pairingOut: %i " , uint256 (pairingOut));
115
+
116
+ return [addOut, mulOut, pairingOut];
117
+ }
118
+
37
119
function verifyProof (
38
120
uint [2 ] calldata _pA ,
39
121
uint [2 ][2 ] calldata _pB ,
0 commit comments