From c965145bd2c32b24997ca06fc4ee766b75361e46 Mon Sep 17 00:00:00 2001 From: "Daniel A. Nagy" Date: Thu, 21 Jul 2022 15:36:21 +0200 Subject: [PATCH 1/2] BUGIFX: deletion of a key-value pair when the value is not unique Moving the last key to the "hole" left by the deleted key was reflected incorrectly in keyMap. --- contracts/HitchensOrderStatisticsTreeLib.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/HitchensOrderStatisticsTreeLib.sol b/contracts/HitchensOrderStatisticsTreeLib.sol index bded16f..1793d90 100644 --- a/contracts/HitchensOrderStatisticsTreeLib.sol +++ b/contracts/HitchensOrderStatisticsTreeLib.sol @@ -236,8 +236,9 @@ library HitchensOrderStatisticsTreeLib { require(keyExists(self,key,value), "OrderStatisticsTree(408) - Value to delete does not exist."); Node storage nValue = self.nodes[value]; uint rowToDelete = nValue.keyMap[key]; - nValue.keys[rowToDelete] = nValue.keys[nValue.keys.length - uint(1)]; - nValue.keyMap[key]=rowToDelete; + uint last = nValue.keys[nValue.keys.length - uint(1)]; + nValue.keys[rowToDelete] = last; + nValue.keyMap[last] = rowToDelete; nValue.keys.length--; uint probe; uint cursor; From ae75cb9a6295ce13abfe5ba4d8165f8d8d799f74 Mon Sep 17 00:00:00 2001 From: "Daniel A. Nagy" Date: Thu, 21 Jul 2022 16:07:20 +0200 Subject: [PATCH 2/2] typofix --- contracts/HitchensOrderStatisticsTreeLib.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/HitchensOrderStatisticsTreeLib.sol b/contracts/HitchensOrderStatisticsTreeLib.sol index 1793d90..91188b6 100644 --- a/contracts/HitchensOrderStatisticsTreeLib.sol +++ b/contracts/HitchensOrderStatisticsTreeLib.sol @@ -236,7 +236,7 @@ library HitchensOrderStatisticsTreeLib { require(keyExists(self,key,value), "OrderStatisticsTree(408) - Value to delete does not exist."); Node storage nValue = self.nodes[value]; uint rowToDelete = nValue.keyMap[key]; - uint last = nValue.keys[nValue.keys.length - uint(1)]; + bytes32 last = nValue.keys[nValue.keys.length - uint(1)]; nValue.keys[rowToDelete] = last; nValue.keyMap[last] = rowToDelete; nValue.keys.length--;