-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2af0bcd
commit 0bbd8d7
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
pragma circom 2.1.9; | ||
|
||
include "parser/language.circom"; | ||
include "../utils/array.circom"; | ||
|
||
/* TODO: | ||
Notes -- | ||
- This is a pretty efficient way to simply check what the method used in a request is by checking | ||
the first `DATA_LENGTH` number of bytes. | ||
- Certainly this could be more modular. | ||
*/ | ||
template YieldMethod(DATA_LENGTH) { | ||
signal input bytes[DATA_LENGTH]; | ||
signal output MethodTag; | ||
|
||
component RequestMethod = RequestMethod(); | ||
component RequestMethodTag = RequestMethodTag(); | ||
|
||
component IsGet = IsEqualArray(3); | ||
for(var byte_idx = 0; byte_idx < 3; byte_idx++) { | ||
IsGet.in[0][byte_idx] <== bytes[byte_idx]; | ||
IsGet.in[1][byte_idx] <== RequestMethod.GET[byte_idx]; | ||
} | ||
signal TagGet <== IsGet.out * RequestMethodTag.GET; | ||
|
||
component IsPost = IsEqualArray(4); | ||
for(var byte_idx = 0; byte_idx < 4; byte_idx++) { | ||
IsPost.in[0][byte_idx] <== bytes[byte_idx]; | ||
IsPost.in[1][byte_idx] <== RequestMethod.POST[byte_idx]; | ||
} | ||
signal TagPost <== IsPost.out * RequestMethodTag.POST; | ||
|
||
MethodTag <== TagGet + TagPost; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { circomkit, WitnessTester, generateDescription } from "../common"; | ||
|
||
describe("HTTP :: Interpreter", async () => { | ||
describe("YieldMethod", async () => { | ||
let circuit: WitnessTester<["bytes"], ["MethodTag"]>; | ||
|
||
function generatePassCase(input: any, expected: any, depth: number, desc: string) { | ||
const description = generateDescription(input); | ||
|
||
it(`(valid) witness: ${description} ${desc}`, async () => { | ||
circuit = await circomkit.WitnessTester(`YieldMethod`, { | ||
file: "circuits/http/interpreter", | ||
template: "YieldMethod", | ||
params: [4], | ||
}); | ||
console.log("#constraints:", await circuit.getConstraintCount()); | ||
|
||
await circuit.expectPass(input, expected); | ||
}); | ||
} | ||
|
||
// The string `"GET "` | ||
generatePassCase({ bytes: [71, 69, 84, 32] }, { MethodTag: 1 }, 0, ""); | ||
}); | ||
}); |