Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 213e0c8

Browse files
committed
Implement shift opcodes
1 parent 514c28a commit 213e0c8

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

libevm/VM.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,53 @@ void VM::interpretCases()
626626
}
627627
NEXT
628628

629+
#if EVM_USE_BITSHIFT
630+
CASE(SHL)
631+
{
632+
ON_OP();
633+
updateIOGas();
634+
635+
if (m_SP[0] >= 256)
636+
m_SPP[0] = 0;
637+
else
638+
/// TODO: confirm shift >= 256 results in 0 on Boost
639+
m_SPP[0] = m_SP[1] << m_SP[0];
640+
}
641+
NEXT
642+
643+
CASE(SHR)
644+
{
645+
ON_OP();
646+
updateIOGas();
647+
648+
if (m_SP[0] >= 256)
649+
m_SPP[0] = 0;
650+
else
651+
/// TODO: confirm shift >= 256 results in 0 on Boost
652+
m_SPP[0] = m_SP[1] >> m_SP[0];
653+
}
654+
NEXT
655+
656+
CASE(SAR)
657+
{
658+
ON_OP();
659+
updateIOGas();
660+
661+
s256 value = u2s(m_SP[1]);
662+
u256 shift = m_SP[0];
663+
if (shift >= 256)
664+
{
665+
if (value >= 0)
666+
m_SPP[0] = 0;
667+
else
668+
m_SPP[0] = s2u(-1);
669+
}
670+
else
671+
m_SPP[0] = s2u(divWorkaround(value, exp256(2, shift)));
672+
}
673+
NEXT
674+
#endif
675+
629676
CASE(ADDMOD)
630677
{
631678
ON_OP();

0 commit comments

Comments
 (0)