Optimal malicious agreement protocol for cluster-based wireless sensor networks