|
12 | 12 | @Slf4j |
13 | 13 | public class AllowTvmOsakaTest extends VMTestBase { |
14 | 14 |
|
| 15 | + private static final PrecompiledContracts.PrecompiledContract modExp = |
| 16 | + new PrecompiledContracts.ModExp(); |
| 17 | + |
| 18 | + private static byte[] toLenBytes(int value) { |
| 19 | + byte[] b = new byte[32]; |
| 20 | + b[28] = (byte) ((value >> 24) & 0xFF); |
| 21 | + b[29] = (byte) ((value >> 16) & 0xFF); |
| 22 | + b[30] = (byte) ((value >> 8) & 0xFF); |
| 23 | + b[31] = (byte) (value & 0xFF); |
| 24 | + return b; |
| 25 | + } |
| 26 | + |
15 | 27 | @Test |
16 | 28 | public void testEIP7823() { |
17 | 29 | ConfigLoader.disable = true; |
18 | 30 | VMConfig.initAllowTvmOsaka(1); |
19 | 31 |
|
20 | 32 | try { |
21 | | - byte[] baseLen = new byte[32]; |
22 | | - byte[] expLen = new byte[32]; |
23 | | - byte[] modLen = new byte[32]; |
24 | | - |
25 | | - PrecompiledContracts.PrecompiledContract modExp = new PrecompiledContracts.ModExp(); |
| 33 | + // all-zero lengths: should succeed |
| 34 | + Pair<Boolean, byte[]> result = modExp.execute( |
| 35 | + ByteUtil.merge(toLenBytes(0), toLenBytes(0), toLenBytes(0))); |
| 36 | + Assert.assertTrue(result.getLeft()); |
26 | 37 |
|
27 | | - // Valid lens: all zeros (0 <= 1024) |
28 | | - Pair<Boolean, byte[]> result = modExp.execute(ByteUtil.merge(baseLen, expLen, modLen)); |
| 38 | + // baseLen == 1024: boundary, should succeed |
| 39 | + result = modExp.execute( |
| 40 | + ByteUtil.merge(toLenBytes(1024), toLenBytes(0), toLenBytes(0))); |
29 | 41 | Assert.assertTrue(result.getLeft()); |
30 | 42 |
|
31 | | - // Invalid lens: baseLen = 0x01000000... = 16777216 > 1024 |
32 | | - baseLen[0] = 0x01; |
33 | | - result = modExp.execute(ByteUtil.merge(baseLen, expLen, modLen)); |
| 43 | + // baseLen == 1025: just over the limit, should fail |
| 44 | + result = modExp.execute( |
| 45 | + ByteUtil.merge(toLenBytes(1025), toLenBytes(0), toLenBytes(0))); |
| 46 | + Assert.assertFalse(result.getLeft()); |
| 47 | + |
| 48 | + // oversized expLen only: should fail |
| 49 | + result = modExp.execute( |
| 50 | + ByteUtil.merge(toLenBytes(0), toLenBytes(1025), toLenBytes(0))); |
| 51 | + Assert.assertFalse(result.getLeft()); |
| 52 | + |
| 53 | + // oversized modLen only: should fail |
| 54 | + result = modExp.execute( |
| 55 | + ByteUtil.merge(toLenBytes(0), toLenBytes(0), toLenBytes(1025))); |
34 | 56 | Assert.assertFalse(result.getLeft()); |
35 | 57 | } finally { |
36 | 58 | VMConfig.initAllowTvmOsaka(0); |
37 | 59 | ConfigLoader.disable = false; |
38 | 60 | } |
39 | 61 | } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testEIP7823DisabledShouldPass() { |
| 65 | + ConfigLoader.disable = true; |
| 66 | + VMConfig.initAllowTvmOsaka(0); |
| 67 | + |
| 68 | + try { |
| 69 | + // all limits exceeded while osaka is disabled: should succeed (no restriction) |
| 70 | + Pair<Boolean, byte[]> result = modExp.execute( |
| 71 | + ByteUtil.merge(toLenBytes(2048), toLenBytes(2048), toLenBytes(2048))); |
| 72 | + Assert.assertTrue(result.getLeft()); |
| 73 | + } finally { |
| 74 | + ConfigLoader.disable = false; |
| 75 | + } |
| 76 | + } |
40 | 77 | } |
0 commit comments