From 6dc60bdd41ec138f71b99c802177f3f7a4c6c3fe Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 11 Nov 2016 09:58:24 +0100 Subject: [PATCH] Limit code size (EIP170). --- libethereum/Executive.cpp | 4 +++- libevmcore/EVMSchedule.h | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index aff2592b943..a3a1436b69b 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -352,7 +352,9 @@ bool Executive::go(OnOpFunc const& _onOp) m_res->gasForDeposit = m_gas; m_res->depositSize = out.size(); } - if (out.size() * m_ext->evmSchedule().createDataGas <= m_gas) + if (out.size() > m_ext->evmSchedule().maxCodeSize) + BOOST_THROW_EXCEPTION(OutOfGas()); + else if (out.size() * m_ext->evmSchedule().createDataGas <= m_gas) { if (m_res) m_res->codeDeposit = CodeDeposit::Success; diff --git a/libevmcore/EVMSchedule.h b/libevmcore/EVMSchedule.h index 3ef49348460..7c582d1eb43 100644 --- a/libevmcore/EVMSchedule.h +++ b/libevmcore/EVMSchedule.h @@ -24,6 +24,8 @@ #include +#include + namespace dev { namespace eth @@ -69,6 +71,7 @@ struct EVMSchedule unsigned extcodecopyGas = 20; unsigned balanceGas = 20; unsigned suicideGas = 0; + unsigned maxCodeSize = unsigned(-1); bool staticCallDepthLimit() const { return !eip150Mode; } bool suicideChargesNewAccountGas() const { return eip150Mode; } @@ -89,6 +92,7 @@ static const EVMSchedule EIP150Schedule = [] schedule.sloadGas = 200; schedule.callGas = 700; schedule.suicideGas = 5000; + schedule.maxCodeSize = 23999; return schedule; }();