diff --git a/arbos/programs/native.go b/arbos/programs/native.go index d53901e7c..436e94bdb 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -256,13 +256,7 @@ func accountBalanceImpl(api usize, address bytes20, cost *u64) bytes32 { func accountCodeImpl(api usize, output *rustBytes, address bytes20, offset u32, size u32, cost *u64) { closures := getApi(api) code, gas := closures.accountCode(address.toAddress(), uint32(offset), uint32(size), uint64(*cost)) - if int(offset) < len(code) { - end := int(offset + size) - if len(code) < end { - end = len(code) - } - output.setBytes(code[offset:end]) - } + output.setBytes(code) *cost = u64(gas) } diff --git a/util/arbmath/bits.go b/util/arbmath/bits.go index 14aa1cc03..2cc109588 100644 --- a/util/arbmath/bits.go +++ b/util/arbmath/bits.go @@ -89,9 +89,9 @@ func NonNilSlice[T any](slice []T) []T { } // Equivalent to slice[start:offset], but truncates when out of bounds rather than panicking. -func SliceWithRunoff[S any, I Integer](slice []S, start I, end I) []S { +func SliceWithRunoff[S any, I Integer](slice []S, start, end I) []S { len := I(len(slice)) - start = MinInt(start, 0) + start = MaxInt(start, 0) end = MaxInt(start, end) if slice == nil || start >= len { diff --git a/util/arbmath/math_test.go b/util/arbmath/math_test.go index 51da5b23f..2e2f14795 100644 --- a/util/arbmath/math_test.go +++ b/util/arbmath/math_test.go @@ -9,6 +9,7 @@ import ( "math/rand" "testing" + "github.com/ethereum/go-ethereum/common" "github.com/offchainlabs/nitro/util/testhelpers" ) @@ -100,7 +101,7 @@ func TestSlices(t *testing.T) { assert_eq := func(left, right []uint8) { t.Helper() if !bytes.Equal(left, right) { - Fail(t) + Fail(t, common.Bytes2Hex(left), " ", common.Bytes2Hex(right)) } }