(block pow.Block, shareDifficulty *big.Int)
| 154 | } |
| 155 | |
| 156 | func (l *Light) SolutionState(block pow.Block, shareDifficulty *big.Int) int { |
| 157 | // TODO: do ethash_quick_verify before getCache in order |
| 158 | // to prevent DOS attacks. |
| 159 | blockNum := block.NumberU64() |
| 160 | if blockNum >= epochLength*2048 { |
| 161 | log.Debug(fmt.Sprintf("block number %d too high, limit is %d", epochLength*2048)) |
| 162 | return 0 |
| 163 | } |
| 164 | |
| 165 | difficulty := block.Difficulty() |
| 166 | /* Cannot happen if block header diff is validated prior to PoW, but can |
| 167 | happen if PoW is checked first due to parallel PoW checking. |
| 168 | We could check the minimum valid difficulty but for SoC we avoid (duplicating) |
| 169 | Ethereum protocol consensus rules here which are not in scope of Ethash |
| 170 | */ |
| 171 | if difficulty.Cmp(common.Big0) == 0 || shareDifficulty.Cmp(common.Big0) == 0 { |
| 172 | log.Debug("invalid block difficulty or share difficulty") |
| 173 | return 0 |
| 174 | } |
| 175 | |
| 176 | cache := l.getCache(blockNum) |
| 177 | dagSize := C.ethash_get_datasize(C.uint64_t(blockNum)) |
| 178 | if l.test { |
| 179 | dagSize = dagSizeForTesting |
| 180 | } |
| 181 | // Recompute the hash using the cache. |
| 182 | ok, mixDigest, result := cache.compute(uint64(dagSize), block.HashNoNonce(), block.Nonce()) |
| 183 | if !ok { |
| 184 | return 0 |
| 185 | } |
| 186 | |
| 187 | // avoid mixdigest malleability as it's not included in a block's "hashNononce" |
| 188 | if block.MixDigest() != mixDigest { |
| 189 | return 0 |
| 190 | } |
| 191 | |
| 192 | // The actual check. |
| 193 | blockTarget := new(big.Int).Div(maxUint256, difficulty) |
| 194 | shareTarget := new(big.Int).Div(maxUint256, shareDifficulty) |
| 195 | if result.Big().Cmp(blockTarget) <= 0 { |
| 196 | return 2 |
| 197 | } |
| 198 | if result.Big().Cmp(shareTarget) <= 0 { |
| 199 | return 1 |
| 200 | } |
| 201 | return 0 |
| 202 | } |
| 203 | |
| 204 | // Verify checks whether the block's nonce is valid. |
| 205 | func (l *Light) Verify(block pow.Block) bool { |
no test coverage detected