Skip to content

Commit d8ada03

Browse files
authored
core/vm: return copy of input slice in identity precompile, avoid returndata copy (#25183)
* core/vm: return copy of input slice in identity precompile. don't deep copy return data slice upon call completion * make use of common.CopyBytes
1 parent 18a001f commit d8ada03

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

core/vm/contracts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (c *dataCopy) RequiredGas(input []byte) uint64 {
235235
return uint64(len(input)+31)/32*params.IdentityPerWordGas + params.IdentityBaseGas
236236
}
237237
func (c *dataCopy) Run(in []byte) ([]byte, error) {
238-
return in, nil
238+
return common.CopyBytes(in), nil
239239
}
240240

241241
// bigModExp implements a native big integer exponential modular operation.

core/vm/instructions.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
697697
}
698698
stack.push(&temp)
699699
if err == nil || err == ErrExecutionReverted {
700-
ret = common.CopyBytes(ret)
701700
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
702701
}
703702
scope.Contract.Gas += returnGas
@@ -733,7 +732,6 @@ func opCallCode(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
733732
}
734733
stack.push(&temp)
735734
if err == nil || err == ErrExecutionReverted {
736-
ret = common.CopyBytes(ret)
737735
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
738736
}
739737
scope.Contract.Gas += returnGas
@@ -762,7 +760,6 @@ func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
762760
}
763761
stack.push(&temp)
764762
if err == nil || err == ErrExecutionReverted {
765-
ret = common.CopyBytes(ret)
766763
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
767764
}
768765
scope.Contract.Gas += returnGas
@@ -791,7 +788,6 @@ func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
791788
}
792789
stack.push(&temp)
793790
if err == nil || err == ErrExecutionReverted {
794-
ret = common.CopyBytes(ret)
795791
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
796792
}
797793
scope.Contract.Gas += returnGas

0 commit comments

Comments
 (0)