Skip to content

Commit

Permalink
uint256: fix ExtendSign (#162)
Browse files Browse the repository at this point in the history
This change fixes a cornercase of ExtendSign, which would return an erronous result if certain operand reuse/aliasing was used: `x.SignExtend(y, x)`, where `num` was an alias for `result`.
  • Loading branch information
AaronChen0 authored May 6, 2024
1 parent c237b53 commit 4152654
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions uint256.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,12 +1235,12 @@ func (z *Int) Exp(base, exponent *Int) *Int {
// and returns z.
func (z *Int) ExtendSign(x, byteNum *Int) *Int {
// This implementation is based on evmone. See https://github.com/ethereum/evmone/pull/390
z.Set(x)
if byteNum.GtUint64(30) {
return z
return z.Set(x)
}

e := byteNum.Uint64()
z.Set(x)
signWordIndex := e >> 3 // Index of the word with the sign bit.
signByteIndex := e & 7 // Index of the sign byte in the sign word.
signWord := z[signWordIndex]
Expand Down

0 comments on commit 4152654

Please sign in to comment.