Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contract math overflow #1276

Merged
merged 11 commits into from
Jun 18, 2024
2 changes: 1 addition & 1 deletion contracts/captcha/src/captcha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x83f401b921b4731d5d80dd1bd0b9a934ee5be23d46a09236778c91c5a070aad8",
"hash": "0x0a7caded5b4f4b90b86f3248ee758fbecd10378ac9fbe077a668530561fad8c3",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/captcha/src/contract-info/captcha.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/common/src/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xbaa3d3ecfc5df9fa44b6872eff9d8e5ddc2c307eabbcdfd2225316d9d2247a96",
"hash": "0x7360597979c9167094605a1a0303ddc422e2ed0271cc6877f7f83a71493b5213",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/src/contract-info/common.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/proxy/src/contract-info/proxy.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/proxy/src/proxy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xbd3e89711ba2a4ee3f5f336ce0a82b71641f86ef26219beeab66177a86fd5176",
"hash": "0x61640a97946c5efea5d3f9e989d8d7bfe361723784dcd3eea7ce84939f2d361f",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
5 changes: 2 additions & 3 deletions protocol/contracts/captcha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ features = [ "test-dependency" ]
[lib]
path = "src/lib.rs"

[profile.release]
overflow-checks = false

[features]
default = [ "std" ]
std = [ "ink/std", "scale/std", "scale-info/std" ]
ink-as-dependency = [ ]

[profile.release]
overflow-checks = false
20 changes: 10 additions & 10 deletions protocol/contracts/captcha/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ pub mod captcha {
};

// update the balance
new_provider.balance += self.env().transferred_value();
new_provider.balance = Math::add(new_provider.balance, self.env().transferred_value())?;

// if the provider is
// not deactivating
Expand Down Expand Up @@ -702,7 +702,7 @@ pub mod captcha {
};

// update the dapp funds
new_dapp.balance += self.env().transferred_value();
new_dapp.balance = Math::add(new_dapp.balance, self.env().transferred_value())?;

// update the dapp status
new_dapp.status =
Expand Down Expand Up @@ -880,9 +880,9 @@ pub mod captcha {
for hash in history.iter() {
let result = self.commits.get(hash).unwrap();
if result.status == CaptchaStatus::Approved {
summary.correct += 1;
summary.correct = Math::add(summary.correct, 1)?;
} else if result.status == CaptchaStatus::Disapproved {
summary.incorrect += 1;
summary.incorrect = Math::add(summary.incorrect, 1)?;
} else {
return Err(Error::InvalidCaptchaStatus);
}
Expand Down Expand Up @@ -971,12 +971,12 @@ pub mod captcha {
if provider.fee != 0 {
let fee = Balance::from(provider.fee);
if provider.payee == Payee::Provider {
dapp.balance -= fee;
provider.balance += fee;
dapp.balance = Math::sub(dapp.balance, fee)?;
provider.balance = Math::add(provider.balance, fee)?;
}
if provider.payee == Payee::Dapp {
provider.balance -= fee;
dapp.balance += fee;
provider.balance = Math::sub(provider.balance, fee)?;
dapp.balance = Math::add(dapp.balance, fee)?;
}
self.providers.insert(provider_account, &provider);
self.dapps.insert(dapp_contract, &dapp);
Expand Down Expand Up @@ -1145,7 +1145,7 @@ pub mod captcha {
.unwrap_or_default();

// The max length of the active providers is the sum of the two
max += active_providers_secondary.len();
max = Math::add(max, active_providers_secondary.len())?;

// If the max is 0, then there are no active providers
if max == 0 {
Expand All @@ -1163,7 +1163,7 @@ pub mod captcha {
if index < active_providers_initial.len() as u128 {
active_providers = active_providers_initial;
} else {
index -= active_providers_initial.len() as u128;
index = Math::add(index, active_providers_initial.len() as u128)?;
active_providers = active_providers_secondary;
}
} else {
Expand Down
5 changes: 2 additions & 3 deletions protocol/contracts/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ optional = true
[lib]
path = "src/lib.rs"

[profile.release]
overflow-checks = false

[features]
default = [ "std" ]
std = [ "ink/std", "scale/std", "scale-info/std" ]
ink-as-dependency = [ "scale-info/derive" ]
test-dependency = [ ]

[profile.release]
overflow-checks = false
4 changes: 2 additions & 2 deletions protocol/contracts/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub mod common {
/// Get the git commit id from when this contract was built
pub fn get_git_commit_id() -> [u8; 20] {
let env_git_commit_id: [u8; 20] = [
148, 112, 176, 141, 96, 230, 225, 185, 11, 95, 64, 246, 146, 195, 86, 36, 128, 94,
217, 240,
187, 109, 144, 134, 147, 209, 197, 106, 179, 138, 95, 104, 98, 12, 114, 89, 157,
29, 31, 81,
];
env_git_commit_id
}
Expand Down
5 changes: 2 additions & 3 deletions protocol/contracts/proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ features = [ "test-dependency" ]
[lib]
path = "src/lib.rs"

[profile.release]
overflow-checks = false

[features]
default = [ "std" ]
std = [ "ink/std", "scale/std", "scale-info/std" ]
ink-as-dependency = [ ]

[profile.release]
overflow-checks = false
Loading