Skip to content

Commit a0ef459

Browse files
evm: ensure modexp right-pads input data
* evm: ensure modexp right-pads input data * evm: ensure modexp right-pads input data * evm: fix modexp gas * Merge branch 'fix-precompiles-inputs' of github.com:ethereumjs/ethereumjs-monorepo into fix-precompiles-inputs * evm: remove .only test modifier
1 parent c5054eb commit a0ef459

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

packages/evm/src/precompiles/05-modexp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function expmod(a: bigint, power: bigint, modulo: bigint) {
103103
}
104104

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

108108
let adjustedELen = getAdjustedExponentLength(data)
109109
if (adjustedELen < BIGINT_1) {

packages/evm/test/precompiles/05-modexp.spec.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,31 @@ describe('Precompiles: MODEXP', () => {
1515
const addressStr = '0000000000000000000000000000000000000005'
1616
const MODEXP = getActivePrecompiles(common).get(addressStr)!
1717

18-
let n = 0
19-
for (const [input, expect] of fuzzerTests) {
20-
n++
21-
it(`MODEXP edge cases (issue 3168) - case ${n}`, async () => {
22-
const result = await MODEXP({
23-
data: hexToBytes(input),
24-
gasLimit: BigInt(0xffff),
25-
common,
26-
_EVM: evm,
18+
it('should run testdata', async () => {
19+
let n = 0
20+
for (const [input, expect] of fuzzerTests) {
21+
n++
22+
it(`MODEXP edge cases (issue 3168) - case ${n}`, async () => {
23+
const result = await MODEXP({
24+
data: hexToBytes(input),
25+
gasLimit: BigInt(0xffff),
26+
common,
27+
_EVM: evm,
28+
})
29+
const oput = bytesToHex(result.returnValue)
30+
assert.equal(oput, expect)
2731
})
28-
const oput = bytesToHex(result.returnValue)
29-
assert.equal(oput, expect)
32+
}
33+
})
34+
35+
it('should correctly right-pad data if input length is too short', async () => {
36+
const gas = BigInt(0xffff)
37+
const result = await MODEXP({
38+
data: hexToBytes('0x41'),
39+
gasLimit: gas,
40+
common,
41+
_EVM: evm,
3042
})
31-
}
43+
assert.ok(result.executionGasUsed === gas)
44+
})
3245
})

0 commit comments

Comments
 (0)