From 0bfcdaf794d1192e180378a6e15f24e7b3c9e411 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Sun, 9 Apr 2023 16:00:26 +0200 Subject: [PATCH] feat: change generation of bytecode for pushes with zero-value --- libevmasm/Assembly.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 3475bdafe..e86103416 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -560,11 +560,18 @@ LinkerObject const& Assembly::assemble() const break; case Push: { - unsigned b = max(1, numberEncodingSize(i.data())); + unsigned b = numberEncodingSize(i.data()); + if (b == 0 && !m_evmVersion.hasPush0()) + { + b = 1; + } ret.bytecode.push_back(static_cast(pushInstruction(b))); - ret.bytecode.resize(ret.bytecode.size() + b); - bytesRef byr(&ret.bytecode.back() + 1 - b, b); - toBigEndian(i.data(), byr); + if (b > 0) + { + ret.bytecode.resize(ret.bytecode.size() + b); + bytesRef byr(&ret.bytecode.back() + 1 - b, b); + toBigEndian(i.data(), byr); + } break; } case PushTag: