| 224 | } |
| 225 | |
| 226 | func (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. |