Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
635 changes: 635 additions & 0 deletions ValidateUTF8.test.sol

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions ValidateUTF8_examples.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pragma solidity ^0.4.22;
pragma experimental "v0.5.0";
pragma experimental "ABIEncoderV2";

import {ValidateUTF8} from "./ValidateUTF8.slb";

/* solhint-disable max-line-length */

// Examples of UTF-8 validation. All of these functions should execute normally.
contract ValidateUTF8Examples {

using ValidateUTF8 for string;

function stringExampleValidateBrut() public pure {
string memory str = "An preost wes on leoden, Laȝamon was ihoten He wes Leovenaðes sone -- liðe him be Drihten. He wonede at Ernleȝe at æðelen are chirechen, Uppen Sevarne staþe, sel þar him þuhte, Onfest Radestone, þer he bock radde.";
str.validate();
}

function stringExampleValidateOdysseusElytis() public pure {
string memory str = "Τη γλώσσα μου έδωσαν ελληνική το σπίτι φτωχικό στις αμμουδιές του Ομήρου. Μονάχη έγνοια η γλώσσα μου στις αμμουδιές του Ομήρου. από το Άξιον Εστί του Οδυσσέα Ελύτη";
str.validate();
}

function stringExampleValidatePushkinsHorseman() public pure {
string memory str = "На берегу пустынных волн Стоял он, дум великих полн, И вдаль глядел. Пред ним широко Река неслася; бедный чёлн По ней стремился одиноко. По мшистым, топким берегам Чернели избы здесь и там, Приют убогого чухонца; И лес, неведомый лучам В тумане спрятанного солнца, Кругом шумел.";
str.validate();
}

function stringExampleValidateRunePoem() public pure {
string memory str = "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ";
str.validate();
}

function stringExampleValidateBrownFoxHiragana() public pure {
string memory str = "いろはにほへど ちりぬるを わがよたれぞ つねならむ うゐのおくやま けふこえて あさきゆめみじ ゑひもせず";
str.validate();
}

}
/* solhint-enable max-line-length */
7 changes: 7 additions & 0 deletions exec-fuzz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x

echo "Running Fuzz Suite..."
DATE="$(date -u +%FT%TZ)"
sleep 1
npx eslump fuzz.js $DATE/
31 changes: 31 additions & 0 deletions fuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

const prettier = require("prettier");
const testGenerator = require("./generator");
const random = require("./random");
const prettierSolidity = require("prettier-plugin-solidity");

function generate(code, { options }) {
return prettier.format(code, options);
}

function generateRandomOptions({ sourceType }) {
return {
arrowParens: random.item(["avoid", "always"]),
bracketSpacing: random.bool(),
endOfLine: random.item(["auto", "lf", "crlf", "cr"]),
htmlWhitespaceSensitivity: random.item(["css", "strict", "ignore"]),
jsxBracketSameLine: random.bool(),
jsxSingleQuote: random.bool(),
parser: sourceType === "module" ? random.item(["babel"]) : "babel",
printWidth: random.int(200),
proseWrap: random.item(["always", "never", "preserve"]),
semi: random.bool(),
singleQuote: random.bool(),
tabWidth: random.int(12),
trailingComma: random.item(["none", "es5", "all"]),
useTabs: random.bool(),
};
}

module.exports = testGenerator(generate, generateRandomOptions);
29 changes: 29 additions & 0 deletions fuzz.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "always"
}
},
{
"files": "contracts/v1/**/*.sol",
"options": {
"compiler": "0.6.3",
"explicitTypes": "preserve"
}
},
{
"files": "contracts/v2/**/*.sol",
"options": {
"compiler": "0.8.4",
"explicitTypes": "never"
}
}
]
}
53 changes: 53 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";

const expect = require("unexpected");

module.exports = (generate, generateRandomOptions) => ({
code,
sourceType,
reproductionData = undefined,
}) => {
const isReproduction = reproductionData != null;
const options =
reproductionData != null
? reproductionData.options
: generateRandomOptions({ sourceType });
const generateData = { sourceType, options };
const artifacts = {};

function makeErrorData(error) {
return { error, reproductionData: { options }, artifacts };
}

let generatedCode1 = undefined;
try {
generatedCode1 = generate(code, generateData);
} catch (error) {
// Ignore parse errors: We’re testing the printer here, not the parsers.
if (
!isReproduction &&
(String(error).includes("SyntaxError") ||
(error && typeof error.column === "number"))
) {
return undefined;
}
return makeErrorData(error);
}
artifacts["generated1.js"] = generatedCode1;

let generatedCode2 = undefined;
try {
generatedCode2 = generate(generatedCode1, generateData);
} catch (error) {
return makeErrorData(error);
}
artifacts["generated2.js"] = generatedCode2;

try {
expect(generatedCode1, "to equal", generatedCode2);
} catch (error) {
return makeErrorData(error);
}

return undefined;
};
95 changes: 95 additions & 0 deletions output/generated1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'Ó';
for (var async in this)
do break;
while (this instanceof false);
for (
;
((0 !== null).qeru >>>= ([], q = true) => {
'VLÜ¡ò';
'J';
' dÉ';
while (true) break;
async function async() {}
for (;;);
})`¢ Û™${`${/|\B$(?:)|(?!)[^\--8-]Y{76003}?\4(?:)*?|\ud956\uDfDd??[^\t-h9-C\*-\^-]^\4|!+?\2()()()()/iuy}E${'B'}p`}Ù#ƒß${new (i
? this
: r.for)(
...async function (async, async, j) {
'use strict';
},
2e308,
async function emvpr(h, {}, async = null) {
'';
},
)}N•u(${false}a${() => {
'use strict';
switch ((async += 9926)) {
case this:
case null:
default:
}
function uru(r = 0x664888bcbc268, async, [], ...b) {
'w\
';
'§';
'\N';
try {
} catch (l) {}
}
switch (null) {
case true:
default:
case false:
}
}}u${new null('àp—iÙ'[2e308])}–` + [,];

)
throw (async (
async,
async = /9(?=)*(?=){85177,93994}/ ** async,
...{[0xc407fd521212e]: n = false, 'fŠ™êï': async, ...async}
) =>
function* (bqwoeqvnfpycks, t) {
'';
'use strict';
'–&';
'use strict';
'use strict';
} <= [`Ôñ9`, 2e308 ? 2e308 : t, ,]).yfbbhsxhabb;
async function async() {
'Â?á';
'use strict';
if (await (async = '¬Ù'))
for (null.constructor in async--)
try {
debugger;
var async;
try {
} finally {
}
} catch ({}) {
} finally {
('È¡');
while ('¶Ée\n');
for (;;) continue;
}
throw class eput {
'v–À'() {}
static get [`Våo`]() {
debugger;
this;
try {
} finally {
}
for (_async of 0.87) debugger;
}
static async [new.target](e, d, x, async) {
"'Ä";
'';
'M';
'use strict';
}
};
for await (c of 0x1839f07ea90cba) var o, c, [] = `„ÏÜ`;
}
import async, * as k from '';
66 changes: 66 additions & 0 deletions output/random.backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"Ó"
for (var async in (this)) do break; while ((((this) instanceof false)));
for (; ((((((((0) !== (null))).qeru >>>= (([], q = (true)) => {
"VLÜ¡ò";
"J"
" dÉ";
while ((((true)))) break
async function async() {}
for (;;) ;
})))`¢ Û™${((`${((/|\B$(?:)|(?!)[^\--8-]Y{76003}?\4(?:)*?|\ud956\uDfDd??[^\t-h9-C\*-\^-]^\4|!+?\2()()()()/iuy))}E${("B")}p`))}Ù#ƒß${((new (((((i) ? (((this))) : (((r).for))))))(...(async function (async, async, j) {
"use strict";
}), (2e308), (async function emvpr(h, {}, async = (null)) {
"";
}))))}N•u(${((false))}a${(() => {
"use strict";
switch ((((async += (9926))))) {
case (this):
case (null):
default:
}
function uru(r = (0x664888BCBC268), async, [], ...b) {
"w\
"
"§" "\N" try {} catch (l) {}
}
switch ((null)) {
case (true):
default:
case ((false)):
}
})}u${((new ((null))((((("àp—iÙ")))[(2e308)]))))}–`)) + (([, ])));) throw ((async (async, async = (/9(?=)*(?=){85177,93994}/) ** ((async)), ...{[((0xC407FD521212E))]: n = (false), "fŠ™êï": async, ...async}) => (((function* (bqwoeqvnfpycks, t) {
"" "use strict";
"–&";
"use strict" "use strict";
}) <= ((([(`Ôñ9`), (((((2e308)) ? (2e308) : (t)))), , ]))))))).yfbbhsxhabb;
;
async function async() {
"Â?á"
"use strict";
if ((await ((async = ("¬Ù"))))) for ((null).constructor in (async --)) try {
debugger;
var async;
try {} finally {}
} catch ({}) {} finally {
("È¡");
while (((("¶Ée\n")))) ;
for (;;) continue;
}
throw (class eput {
"v–À"() {}
static get [(`Våo`)]() {
debugger
;(((this)))
try {} finally {}
for (_async of ((.87))) debugger
}
static async [(new.target)](e, d, x, async) {
"'Ä" "";
"M";
"use strict";
}
})
for await (c of (0x1839F07EA90CBA)) var o, c, [] = (`„ÏÜ`);

}
import async, * as k from "";
Expand Down
66 changes: 66 additions & 0 deletions output/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"Ó"
for (var async in (this)) do break; while ((((this) instanceof false)));
for (; ((((((((0) !== (null))).qeru >>>= (([], q = (true)) => {
"VLÜ¡ò";
"J"
" dÉ";
while ((((true)))) break
async function async() {}
for (;;) ;
})))`¢ Û™${((`${((/|\B$(?:)|(?!)[^\--8-]Y{76003}?\4(?:)*?|\ud956\uDfDd??[^\t-h9-C\*-\^-]^\4|!+?\2()()()()/iuy))}E${("B")}p`))}Ù#ƒß${((new (((((i) ? (((this))) : (((r).for))))))(...(async function (async, async, j) {
"use strict";
}), (2e308), (async function emvpr(h, {}, async = (null)) {
"";
}))))}N•u(${((false))}a${(() => {
"use strict";
switch ((((async += (9926))))) {
case (this):
case (null):
default:
}
function uru(r = (0x664888BCBC268), async, [], ...b) {
"w\
"
"§" "\N" try {} catch (l) {}
}
switch ((null)) {
case (true):
default:
case ((false)):
}
})}u${((new ((null))((((("àp—iÙ")))[(2e308)]))))}–`)) + (([, ])));) throw ((async (async, async = (/9(?=)*(?=){85177,93994}/) ** ((async)), ...{[((0xC407FD521212E))]: n = (false), "fŠ™êï": async, ...async}) => (((function* (bqwoeqvnfpycks, t) {
"" "use strict";
"–&";
"use strict" "use strict";
}) <= ((([(`Ôñ9`), (((((2e308)) ? (2e308) : (t)))), , ]))))))).yfbbhsxhabb;
;
async function async() {
"Â?á"
"use strict";
if ((await ((async = ("¬Ù"))))) for ((null).constructor in (async --)) try {
debugger;
var async;
try {} finally {}
} catch ({}) {} finally {
("È¡");
while (((("¶Ée\n")))) ;
for (;;) continue;
}
throw (class eput {
"v–À"() {}
static get [(`Våo`)]() {
debugger
;(((this)))
try {} finally {}
for (_async of ((.87))) debugger
}
static async [(new.target)](e, d, x, async) {
"'Ä" "";
"M";
"use strict";
}
})
for await (c of (0x1839F07EA90CBA)) var o, c, [] = (`„ÏÜ`);

}
import async, * as k from "";
Expand Down
Loading