diff --git a/ethereum/contracts/core/Forum.sol b/ethereum/contracts/core/Forum.sol index 667e2c5..32e249b 100644 --- a/ethereum/contracts/core/Forum.sol +++ b/ethereum/contracts/core/Forum.sol @@ -36,6 +36,17 @@ contract Forum is Reputation { for (uint i = 0; i < citations.length; i++) { post.citations.push(citations[i]); } + int totalCitationWeightAbs; + for (uint i = 0; i < post.citations.length; i++) { + int weight = post.citations[i].weightPercent; + require(weight >= -100, "Each citation weight must be >= -100"); + require(weight <= 100, "Each citation weight must be <= 100"); + totalCitationWeightAbs += weight > 0 ? weight : -weight; + } + require( + totalCitationWeightAbs <= 100, + "Sum of absolute value of citations must be <= 100" + ); emit PostAdded(postIndex); } @@ -45,10 +56,6 @@ contract Forum is Reputation { function _propagateValue(uint postIndex, int amount) internal { Post storage post = posts[postIndex]; - int totalCitationWeight; - for (uint i = 0; i < post.citations.length; i++) { - totalCitationWeight += post.citations[i].weightPercent; - } int totalOutboundAmount; for (uint i = 0; i < post.citations.length; i++) { int share = (amount * post.citations[i].weightPercent) / 100;