MCPcopy Create free account
hub / github.com/CPChain/chain / Run

Method Run

core/vm/contracts.go:226–252  ·  view source on GitHub ↗
(input []byte)

Source from the content-addressed store, hash-verified

224}
225
226func (c *bigModExp) Run(input []byte) ([]byte, error) {
227 var (
228 baseLen = new(big.Int).SetBytes(getData(input, 0, 32)).Uint64()
229 expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64()
230 modLen = new(big.Int).SetBytes(getData(input, 64, 32)).Uint64()
231 )
232 if len(input) > 96 {
233 input = input[96:]
234 } else {
235 input = input[:0]
236 }
237 // Handle a special case when both the base and mod length is zero
238 if baseLen == 0 && modLen == 0 {
239 return []byte{}, nil
240 }
241 // Retrieve the operands and execute the exponentiation
242 var (
243 base = new(big.Int).SetBytes(getData(input, 0, baseLen))
244 exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
245 mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
246 )
247 if mod.BitLen() == 0 {
248 // Modulo 0 is undefined, return zero
249 return common.LeftPadBytes([]byte{}, int(modLen)), nil
250 }
251 return common.LeftPadBytes(base.Exp(base, exp, mod).Bytes(), int(modLen)), nil
252}
253
254// newCurvePoint unmarshals a binary blob into a bn256 elliptic curve point,
255// returning it, or an error if the point is invalid.

Callers

nothing calls this directly

Calls 4

getDataFunction · 0.85
Uint64Method · 0.80
SetBytesMethod · 0.80
BytesMethod · 0.65

Tested by

no test coverage detected