-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
5 changed files
with
58 additions
and
53 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
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
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 |
---|---|---|
@@ -1,44 +1,44 @@ | ||
import { randomBytes } from 'crypto'; | ||
import { expect } from 'chai'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
import { Contract, OPCODES } from 'sevm'; | ||
import { EVM } from 'sevm'; | ||
|
||
import { compile } from '../utils/solc'; | ||
|
||
describe('contracts metadata', function () { | ||
const includesFF = (hash: string) => Buffer.from(hash, 'hex').includes(OPCODES.SELFDESTRUCT); | ||
describe.skip('contracts metadata', function () { | ||
// const includesFF = (hash: string) => Buffer.from(hash, 'hex').includes(OPCODES.SELFDESTRUCT); | ||
const includesFF = (hash: string) => hash.match(/^([0-9a-f]{2})*5b([0-9a-f]{2})*ff/) !== null; | ||
|
||
let contract: Contract; | ||
// let evm: EVM<{functionBranches:ISelectorBranches}>; | ||
|
||
before(function () { | ||
it('should not find `selfdestruct` reachable', function () { | ||
// it('should include selfdestruct `ff` in metadata hash', function () { | ||
this.timeout(100000); | ||
const version = '0.5.5'; | ||
const randomDataPath = join('.solc', `${this.test!.parent!.title}.${version}.data`); | ||
const solTemplate = `contract Test { bytes32 constant data = "[randomData]"; }`; | ||
|
||
let evm; | ||
try { | ||
const randomData = readFileSync(randomDataPath, 'utf8'); | ||
const src = solTemplate.replace('[randomData]', randomData); | ||
contract = new Contract(compile(src, version, this).bytecode); | ||
evm = new EVM(compile(src, version, this).bytecode); | ||
} catch { | ||
let src: string, randomData: string; | ||
do { | ||
randomData = randomBytes(16).toString('hex'); | ||
src = solTemplate.replace('[randomData]', randomData); | ||
contract = new Contract(compile(src, version).bytecode); | ||
} while (contract.metadata && !includesFF(contract.metadata.hash)); | ||
writeFileSync(randomDataPath, randomData); | ||
evm = new EVM(compile(src, version, null).bytecode); | ||
console.log(randomData, evm.metadata?.hash); | ||
} while (!includesFF(evm.metadata!.hash) || !evm.containsOpcode('SELFDESTRUCT')); | ||
// writeFileSync(randomDataPath, randomData); | ||
this.currentTest!.title += ` (random data ${randomData})`; | ||
} | ||
}); | ||
|
||
it('should include selfdestruct `ff` in metadata hash', function () { | ||
expect(includesFF(contract.metadata!.hash)).to.be.true; | ||
}); | ||
|
||
it('should not find `selfdestruct` reachable', function () { | ||
expect(contract.evm.containsOpcode(OPCODES.SELFDESTRUCT)).to.be.false; | ||
expect(contract.evm.containsOpcode('SELFDESTRUCT')).to.be.false; | ||
expect(includesFF(evm.metadata!.hash)).to.be.true; | ||
// expect(evm.containsOpcode(OPCODES.SELFDESTRUCT)).to.be.false; | ||
expect(evm.containsOpcode('SELFDESTRUCT')).to.be.false; | ||
}); | ||
}); |
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
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