From 6a881a2baa18960f686dbf22e120abe209c5016a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 26 Oct 2020 18:26:04 +0300 Subject: [PATCH] Set max amount for `Withdraw` and `Deposit` methods These methods initiate `transfer` call on internal balance method that have Fixed12 precision. With this limit it will not overflow JSON integer bound 2**53-1 Actual limit is 9007, but it was floored. Signed-off-by: Alex Vanin --- neofs_contract.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/neofs_contract.go b/neofs_contract.go index be528bc..43efec7 100644 --- a/neofs_contract.go +++ b/neofs_contract.go @@ -81,6 +81,8 @@ const ( blockDiff = 20 // change base on performance evaluation publicKeySize = 33 minInnerRingSize = 3 + + maxBalanceAmount = 9000 // Max integer of Fixed12 in JSON bound (2**53-1) ) var ( @@ -199,6 +201,10 @@ func Deposit(from []byte, amount int, rcv []byte) bool { panic("deposit: you should be the owner of the wallet") } + if amount > maxBalanceAmount { + panic("deposit: out of max amount limit") + } + if amount <= 0 { return false } @@ -233,6 +239,10 @@ func Withdraw(user []byte, amount int) bool { panic("withdraw: non positive amount number") } + if amount > maxBalanceAmount { + panic("withdraw: out of max amount limit") + } + amount = amount * 100000000 tx := runtime.GetScriptContainer()