From a75e051b7b23589f07b7a916bd4b349cb4ac3577 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 23 Jan 2015 15:17:34 +0100 Subject: [PATCH 1/3] fix gasPrice*gasLimit + value overflow --- libethereum/Executive.cpp | 6 +++--- test/stSpecialTestFiller.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index dc2e62824..8fe348e00 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -72,7 +72,7 @@ bool Executive::setup(bytesConstRef _rlp) BOOST_THROW_EXCEPTION(OutOfGas() << RequirementError((bigint)gasCost, (bigint)m_t.gas())); } - u256 cost = m_t.value() + m_t.gas() * m_t.gasPrice(); + bigint cost = m_t.value() + (bigint)m_t.gas() * m_t.gasPrice(); // Avoid unaffordable transactions. if (m_s.balance(m_t.sender()) < cost) @@ -82,7 +82,7 @@ bool Executive::setup(bytesConstRef _rlp) } u256 startGasUsed = m_s.gasUsed(); - if (startGasUsed + m_t.gas() > m_s.m_currentBlock.gasLimit) + if (startGasUsed + (bigint)m_t.gas() > m_s.m_currentBlock.gasLimit) { clog(StateDetail) << "Too much gas used in this block: Require <" << (m_s.m_currentBlock.gasLimit - startGasUsed) << " Got" << m_t.gas(); BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((bigint)(m_s.m_currentBlock.gasLimit - startGasUsed), (bigint)m_t.gas())); @@ -92,7 +92,7 @@ bool Executive::setup(bytesConstRef _rlp) m_s.noteSending(m_t.sender()); // Pay... - clog(StateDetail) << "Paying" << formatBalance(cost) << "from sender (includes" << m_t.gas() << "gas at" << formatBalance(m_t.gasPrice()) << ")"; + clog(StateDetail) << "Paying" << formatBalance(u256(cost)) << "from sender (includes" << m_t.gas() << "gas at" << formatBalance(m_t.gasPrice()) << ")"; m_s.subBalance(m_t.sender(), cost); if (m_t.isCreation()) diff --git a/test/stSpecialTestFiller.json b/test/stSpecialTestFiller.json index fcb1d74a6..9aaf94f92 100644 --- a/test/stSpecialTestFiller.json +++ b/test/stSpecialTestFiller.json @@ -37,5 +37,38 @@ "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "data" : "" } + }, + + "OverflowGasMakeMoney" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "45678256", + "currentGasLimit" : "(2**256)-1", + "currentGasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentNumber" : "0", + "currentTimestamp" : 1, + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "pre" : { + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "1000", + "code" : "", + "nonce" : "0", + "storage" : { + } + } + }, + "transaction" : + { + "data" : "", + "gasLimit" : "2**200", + "gasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639435", + "gasPrice" : "1", + "gasPrice" : "1", + "nonce" : "0", + "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "value" : "501" + } } } From 71427d6af784ba586da2be55f43d684adff10260 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 23 Jan 2015 15:27:32 +0100 Subject: [PATCH 2/3] correct test --- test/stSpecialTestFiller.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/stSpecialTestFiller.json b/test/stSpecialTestFiller.json index 9aaf94f92..3691df80f 100644 --- a/test/stSpecialTestFiller.json +++ b/test/stSpecialTestFiller.json @@ -61,10 +61,8 @@ "transaction" : { "data" : "", - "gasLimit" : "2**200", "gasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639435", "gasPrice" : "1", - "gasPrice" : "1", "nonce" : "0", "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b", From f3cc46e8b7ace8916b2a0de896f34c934691839d Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 23 Jan 2015 18:23:00 +0100 Subject: [PATCH 3/3] bigint cast of bigint not neccessary --- libethereum/Executive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 8fe348e00..cea7d21f4 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -78,7 +78,7 @@ bool Executive::setup(bytesConstRef _rlp) if (m_s.balance(m_t.sender()) < cost) { clog(StateDetail) << "Not enough cash: Require >" << cost << " Got" << m_s.balance(m_t.sender()); - BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError((bigint)cost, (bigint)m_s.balance(m_t.sender()))); + BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError(cost, (bigint)m_s.balance(m_t.sender()))); } u256 startGasUsed = m_s.gasUsed();