From 5cffb8f5560ec3c8fa149de6921d57eda8475936 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Wed, 10 Apr 2024 16:40:12 -0500 Subject: [PATCH] enforce constrants on citation weights --- ethereum/contracts/core/Forum.sol | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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;