Skip to content

Commit d681f20

Browse files
[mlir][Sol] Fix ABI tuple decoding for narrow integer array elements
During ABI tuple decoding of array elements, values narrower than 256 bits were written to memory without proper extension. In this case narrow integers are placed in the high bits of the slot, which is incorrect. Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
1 parent 3e19f49 commit d681f20

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mlir/lib/Conversion/SolToStandard/EVMUtil.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,18 @@ Value evm::Builder::genABITupleDecoding(Type ty, Value addr, bool fromMem,
858858
genABITupleDecoding(arrTy.getEltType(), offsetFromSrcArr,
859859
fromMem, tupleStart, tupleEnd, loc));
860860
} else {
861-
b.create<yul::MStoreOp>(
862-
loc, iDstAddr,
861+
auto elemVal =
863862
genABITupleDecoding(arrTy.getEltType(), iSrcAddr, fromMem,
864-
tupleStart, tupleEnd, loc));
863+
tupleStart, tupleEnd, loc);
864+
auto intTy = dyn_cast<IntegerType>(elemVal.getType());
865+
866+
// If the element type is an integer smaller than 256 bits, we need
867+
// to extend it. In case we don't do that, store will place the
868+
// value in the higher bits, which is incorrect.
869+
if (intTy && intTy.getWidth() < 256)
870+
elemVal =
871+
bExt.genIntCast(/*width=*/256, intTy.isSigned(), elemVal);
872+
b.create<yul::MStoreOp>(loc, iDstAddr, elemVal);
865873
}
866874

867875
Value srcStride =

0 commit comments

Comments
 (0)