From d4c5b0da105206e3e541fb5a8c69ad061ff35cd6 Mon Sep 17 00:00:00 2001 From: Kelvin Fichter Date: Fri, 9 Apr 2021 15:48:16 -0700 Subject: [PATCH] fix: Check for overflows in safety checker --- .../OVM/execution/OVM_SafetyChecker.sol | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contracts/optimistic-ethereum/OVM/execution/OVM_SafetyChecker.sol b/contracts/optimistic-ethereum/OVM/execution/OVM_SafetyChecker.sol index ff90584a6..8994f2e4f 100644 --- a/contracts/optimistic-ethereum/OVM/execution/OVM_SafetyChecker.sol +++ b/contracts/optimistic-ethereum/OVM/execution/OVM_SafetyChecker.sol @@ -57,12 +57,17 @@ contract OVM_SafetyChecker is iOVM_SafetyChecker { // PUSH opcodes uint256 opcodePushMask = ~uint256(0xffffffff000000000000000000000000); - uint256 codeLength; uint256 _pc; assembly { _pc := add(_bytecode, 0x20) } - codeLength = _pc + _bytecode.length; + uint256 codeLength = _pc + _bytecode.length; + + // Simple overflow check. + if (codeLength < _pc) { + return false; + } + do { // current opcode: 0x00...0xff uint256 opNum;