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

evm: ensure modexp right-pads input data #3206

Merged
merged 5 commits into from
Dec 19, 2023
Merged
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
2 changes: 1 addition & 1 deletion packages/evm/src/precompiles/05-modexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function expmod(a: bigint, power: bigint, modulo: bigint) {
}

export function precompile05(opts: PrecompileInput): ExecResult {
const data = opts.data
const data = opts.data.length < 96 ? setLengthRight(opts.data, 96) : opts.data

let adjustedELen = getAdjustedExponentLength(data)
if (adjustedELen < BIGINT_1) {
Expand Down
37 changes: 25 additions & 12 deletions packages/evm/test/precompiles/05-modexp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@ describe('Precompiles: MODEXP', () => {
const addressStr = '0000000000000000000000000000000000000005'
const MODEXP = getActivePrecompiles(common).get(addressStr)!

let n = 0
for (const [input, expect] of fuzzerTests) {
n++
it(`MODEXP edge cases (issue 3168) - case ${n}`, async () => {
const result = await MODEXP({
data: hexToBytes(input),
gasLimit: BigInt(0xffff),
common,
_EVM: evm,
it('should run testdata', async () => {
let n = 0
for (const [input, expect] of fuzzerTests) {
n++
it(`MODEXP edge cases (issue 3168) - case ${n}`, async () => {
const result = await MODEXP({
data: hexToBytes(input),
gasLimit: BigInt(0xffff),
common,
_EVM: evm,
})
const oput = bytesToHex(result.returnValue)
assert.equal(oput, expect)
})
const oput = bytesToHex(result.returnValue)
assert.equal(oput, expect)
}
})

it('should correctly right-pad data if input length is too short', async () => {
const gas = BigInt(0xffff)
const result = await MODEXP({
data: hexToBytes('0x41'),
gasLimit: gas,
common,
_EVM: evm,
})
}
assert.ok(result.executionGasUsed === gas)
})
})
Loading