Skip to content

Commit

Permalink
fix all the linter stuff (#3802)
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 authored Nov 20, 2024
1 parent e86eace commit f364de7
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 515 deletions.
2 changes: 1 addition & 1 deletion config/eslint.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = {
},
},
{
files: ['**/examples/**/*.ts', '**/benchmarks/*.ts', ],
files: ['**/examples/**/*.ts', '**/examples/**/*.js','**/benchmarks/*.ts'],
rules: {
'implicit-dependencies/no-implicit': 'off',
'import/no-extraneous-dependencies': 'off',
Expand Down
86 changes: 43 additions & 43 deletions packages/client/test/sim/snapsync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,49 @@ let stateManager: MerkleStateManager | undefined = undefined
const EOATransferToAccount = '0x3dA33B9A0894b908DdBb00d96399e506515A1009'
let EOATransferToBalance = BigInt(0)

async function createSnapClient(
common: any,
customGenesisState: any,
bootnodes: any,
peerBeaconUrl: any,
datadir: any,
) {
// Turn on `debug` logs, defaults to all client logging
debug.enable(process.env.DEBUG_SNAP ?? '')
const logger = getLogger({ logLevel: 'debug' })
const config = new Config({
common,
bootnodes,
multiaddrs: [],
logger,
accountCache: 10000,
storageCache: 1000,
discDns: false,
discV4: false,
port: 30304,
enableSnapSync: true,
// syncmode: 'none',
// Keep the single job sync range high as the state is not big
maxAccountRange: (BigInt(2) ** BigInt(256) - BigInt(1)) / BigInt(10),
maxFetcherJobs: 10,
})
const peerConnectedPromise = new Promise((resolve) => {
config.events.once(Event.PEER_CONNECTED, (peer: any) => resolve(peer))
})
const snapSyncCompletedPromise = new Promise((resolve) => {
config.events.once(
Event.SYNC_SNAPSYNC_COMPLETE,
(stateRoot: Uint8Array, stateManager: MerkleStateManager) =>
resolve([stateRoot, stateManager]),
)
})

const ejsInlineClient = await createInlineClient(config, common, customGenesisState, datadir)
const beaconSyncRelayer = await setupEngineUpdateRelay(ejsInlineClient, peerBeaconUrl)

return { ejsInlineClient, peerConnectedPromise, snapSyncCompletedPromise, beaconSyncRelayer }
}

export async function runTx(data: PrefixedHexString | '', to?: PrefixedHexString, value?: bigint) {
return runTxHelper({ client, common, sender, pkey }, data, to, value)
}
Expand Down Expand Up @@ -238,49 +281,6 @@ describe('simple mainnet test run', async () => {
}, 60_000)
})

async function createSnapClient(
common: any,
customGenesisState: any,
bootnodes: any,
peerBeaconUrl: any,
datadir: any,
) {
// Turn on `debug` logs, defaults to all client logging
debug.enable(process.env.DEBUG_SNAP ?? '')
const logger = getLogger({ logLevel: 'debug' })
const config = new Config({
common,
bootnodes,
multiaddrs: [],
logger,
accountCache: 10000,
storageCache: 1000,
discDns: false,
discV4: false,
port: 30304,
enableSnapSync: true,
// syncmode: 'none',
// Keep the single job sync range high as the state is not big
maxAccountRange: (BigInt(2) ** BigInt(256) - BigInt(1)) / BigInt(10),
maxFetcherJobs: 10,
})
const peerConnectedPromise = new Promise((resolve) => {
config.events.once(Event.PEER_CONNECTED, (peer: any) => resolve(peer))
})
const snapSyncCompletedPromise = new Promise((resolve) => {
config.events.once(
Event.SYNC_SNAPSYNC_COMPLETE,
(stateRoot: Uint8Array, stateManager: MerkleStateManager) =>
resolve([stateRoot, stateManager]),
)
})

const ejsInlineClient = await createInlineClient(config, common, customGenesisState, datadir)
const beaconSyncRelayer = await setupEngineUpdateRelay(ejsInlineClient, peerBeaconUrl)

return { ejsInlineClient, peerConnectedPromise, snapSyncCompletedPromise, beaconSyncRelayer }
}

process.on('uncaughtException', (err: any, origin: any) => {
console.log({ err, origin })
process.exit()
Expand Down
27 changes: 13 additions & 14 deletions packages/evm/examples/decode-opcodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ const opcodes = getOpcodesForHF(common).opcodes

const data = '0x6107608061000e6000396000f30060003560e060020a90048063141961bc1461006e57806319ac74bd'

nameOpCodes(hexToBytes(data))
function pad(num: number, size: number) {
let s = num + ''
while (s.length < size) s = '0' + s
return s
}

function log(num: number, base: number) {
return Math.log(num) / Math.log(base)
}

function roundLog(num: number, base: number) {
return Math.ceil(log(num, base))
}
function nameOpCodes(raw: Uint8Array) {
let pushData = new Uint8Array()

Expand All @@ -39,16 +50,4 @@ function nameOpCodes(raw: Uint8Array) {
}
}

function pad(num: number, size: number) {
let s = num + ''
while (s.length < size) s = '0' + s
return s
}

function log(num: number, base: number) {
return Math.log(num) / Math.log(base)
}

function roundLog(num: number, base: number) {
return Math.ceil(log(num, base))
}
nameOpCodes(hexToBytes(data))
1 change: 1 addition & 0 deletions packages/evm/src/eof/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function verifyCode(
evm: EVM,
mode: ContainerSectionType = ContainerSectionType.RuntimeCode,
) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return validateOpcodes(container, evm, mode)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import { Hardfork } from '@ethereumjs/common'
import {
Account,
Expand Down Expand Up @@ -1191,3 +1192,4 @@ export function defaultBlock(): Block {
},
}
}
/* eslint-enable @typescript-eslint/no-use-before-define */
72 changes: 36 additions & 36 deletions packages/evm/src/opcodes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,42 @@ import type { Address } from '@ethereumjs/util'

const MASK_160 = (BIGINT_1 << BIGINT_160) - BIGINT_1

export function mod(a: bigint, b: bigint) {
let r = a % b
if (r < BIGINT_0) {
r = b + r
}
return r
}

export function fromTwos(a: bigint) {
return BigInt.asIntN(256, a)
}

export function toTwos(a: bigint) {
return BigInt.asUintN(256, a)
}

export function abs(a: bigint) {
if (a > 0) {
return a
}
return a * BIGINT_NEG1
}

const N = BigInt(115792089237316195423570985008687907853269984665640564039457584007913129639936)
export function exponentiation(bas: bigint, exp: bigint) {
let t = BIGINT_1
while (exp > BIGINT_0) {
if (exp % BIGINT_2 !== BIGINT_0) {
t = (t * bas) % N
}
bas = (bas * bas) % N
exp = exp / BIGINT_2
}
return t
}

/**
* Create an address from a stack item (256 bit integer).
* This wrapper ensures that the value is masked to 160 bits.
Expand Down Expand Up @@ -235,39 +271,3 @@ export function updateSstoreGas(
return common.param('sstoreSetGas')
}
}

export function mod(a: bigint, b: bigint) {
let r = a % b
if (r < BIGINT_0) {
r = b + r
}
return r
}

export function fromTwos(a: bigint) {
return BigInt.asIntN(256, a)
}

export function toTwos(a: bigint) {
return BigInt.asUintN(256, a)
}

export function abs(a: bigint) {
if (a > 0) {
return a
}
return a * BIGINT_NEG1
}

const N = BigInt(115792089237316195423570985008687907853269984665640564039457584007913129639936)
export function exponentiation(bas: bigint, exp: bigint) {
let t = BIGINT_1
while (exp > BIGINT_0) {
if (exp % BIGINT_2 !== BIGINT_0) {
t = (t * bas) % N
}
bas = (bas * bas) % N
exp = exp / BIGINT_2
}
return t
}
50 changes: 25 additions & 25 deletions packages/evm/src/precompiles/bls12_381/mcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ function BLS12_381_FromG1Point(input: any): Uint8Array {
return concatBytes(xBytes, yBytes)
}

// input: two 64-byte buffers
// output: a mcl Fp2 point

function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array, mcl: any): any {
// check if the coordinates are in the field
if (bytesToBigInt(fpXCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}
if (bytesToBigInt(fpYCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}

const fp_x = new mcl.Fp()
const fp_y = new mcl.Fp()

const fp2 = new mcl.Fp2()
fp_x.setStr(bytesToUnprefixedHex(fpXCoordinate.subarray(16)), 16)
fp_y.setStr(bytesToUnprefixedHex(fpYCoordinate.subarray(16)), 16)

fp2.set_a(fp_x)
fp2.set_b(fp_y)

return fp2
}

/**
* Converts an Uint8Array to a MCL G2 point. Raises errors if the point is not on the curve
* and (if activated) if the point is in the subgroup / order check.
Expand Down Expand Up @@ -175,31 +200,6 @@ function BLS12_381_ToFpPoint(fpCoordinate: Uint8Array, mcl: any): any {
return fp
}

// input: two 64-byte buffers
// output: a mcl Fp2 point

function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array, mcl: any): any {
// check if the coordinates are in the field
if (bytesToBigInt(fpXCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}
if (bytesToBigInt(fpYCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}

const fp_x = new mcl.Fp()
const fp_y = new mcl.Fp()

const fp2 = new mcl.Fp2()
fp_x.setStr(bytesToUnprefixedHex(fpXCoordinate.subarray(16)), 16)
fp_y.setStr(bytesToUnprefixedHex(fpYCoordinate.subarray(16)), 16)

fp2.set_a(fp_x)
fp2.set_b(fp_y)

return fp2
}

/**
* Implementation of the `EVMBLSInterface` using the `mcl-wasm` WASM `mcl` wrapper library,
* see https://github.com/herumi/mcl-wasm.
Expand Down
30 changes: 15 additions & 15 deletions packages/evm/src/precompiles/bls12_381/noble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ type AffinePoint<T> = {
const G1_ZERO = bls12_381.G1.ProjectivePoint.ZERO
const G2_ZERO = bls12_381.G2.ProjectivePoint.ZERO

function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array) {
// check if the coordinates are in the field
if (bytesToBigInt(fpXCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}
if (bytesToBigInt(fpYCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}

const fpBytes = concatBytes(fpXCoordinate.subarray(16), fpYCoordinate.subarray(16))

const FP = bls12_381.fields.Fp2.fromBytes(fpBytes)
return FP
}

/**
* Converts an Uint8Array to a Noble G1 point. Raises errors if the point is not on the curve
* and (if activated) if the point is in the subgroup / order check.
Expand Down Expand Up @@ -159,21 +174,6 @@ function BLS12_381_ToFpPoint(fpCoordinate: Uint8Array) {
return FP
}

function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array) {
// check if the coordinates are in the field
if (bytesToBigInt(fpXCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}
if (bytesToBigInt(fpYCoordinate) >= BLS_FIELD_MODULUS) {
throw new EvmError(ERROR.BLS_12_381_FP_NOT_IN_FIELD)
}

const fpBytes = concatBytes(fpXCoordinate.subarray(16), fpYCoordinate.subarray(16))

const FP = bls12_381.fields.Fp2.fromBytes(fpBytes)
return FP
}

/**
* Implementation of the `EVMBLSInterface` using the `ethereum-cryptography (`@noble/curves`)
* JS library, see https://github.com/ethereum/js-ethereum-cryptography.
Expand Down
28 changes: 14 additions & 14 deletions packages/evm/src/precompiles/bn254/noble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ function toFrPoint(input: Uint8Array): bigint {
return Fr
}

function toFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array) {
if (bytesToBigInt(fpXCoordinate) >= bn254.fields.Fp2.ORDER) {
throw new EvmError(ERROR.BN254_FP_NOT_IN_FIELD)
}
if (bytesToBigInt(fpYCoordinate) >= bn254.fields.Fp2.ORDER) {
throw new EvmError(ERROR.BN254_FP_NOT_IN_FIELD)
}

const fpBytes = concatBytes(fpXCoordinate, fpYCoordinate)

const FP = bn254.fields.Fp2.fromBytes(fpBytes)
return FP
}

/**
* Converts an Uint8Array to a Noble G2 point. Raises errors if the point is not on the curve
* and (if activated) if the point is in the subgroup / order check.
Expand Down Expand Up @@ -104,20 +118,6 @@ function toG2Point(input: Uint8Array) {
return pG2
}

function toFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array) {
if (bytesToBigInt(fpXCoordinate) >= bn254.fields.Fp2.ORDER) {
throw new EvmError(ERROR.BN254_FP_NOT_IN_FIELD)
}
if (bytesToBigInt(fpYCoordinate) >= bn254.fields.Fp2.ORDER) {
throw new EvmError(ERROR.BN254_FP_NOT_IN_FIELD)
}

const fpBytes = concatBytes(fpXCoordinate, fpYCoordinate)

const FP = bn254.fields.Fp2.fromBytes(fpBytes)
return FP
}

/**
* Implementation of the `EVMBN254Interface` using the `ethereum-cryptography (`@noble/curves`)
* JS library, see https://github.com/ethereum/js-ethereum-cryptography.
Expand Down
Loading

0 comments on commit f364de7

Please sign in to comment.