Skip to content

Comments

Fix some issues in sysio.roa contract#214

Open
heifner wants to merge 1 commit intomasterfrom
feature/misc-contract-fixes
Open

Fix some issues in sysio.roa contract#214
heifner wants to merge 1 commit intomasterfrom
feature/misc-contract-fixes

Conversation

@heifner
Copy link
Contributor

@heifner heifner commented Feb 20, 2026

  • Fix reducepolicy RAM doubling: the reslimit modify lambda was computing row.ram_bytes += (old - reclaim), which doubled RAM instead of decreasing it. Simplified to row.ram_bytes -= reclaim.

  • Fix increase_reslimit negative RAM handling: casting negative int64_t to uint64_t silently wrapped. Now explicitly branches on sign and adds an underflow guard.

  • Fix reducepolicy unlimited NET/CPU underflow: when get_resource_limits returns -1 (unlimited), subtracting the weight produced a large negative value. Now preserves -1 for unlimited limits and clamps finite limits to zero.

Add ROA contract tests covering addpolicy, expandpolicy, reducepolicy, extendpolicy validation paths, multi-issuer policy interactions, and newuser edge cases.

Also small fix in sysio.bios.

  • Fix BLS key hash in setfinalizer: g1_hash was using std::hash<const char*> which hashed the pointer address, not the key content.

sysio.bios - Fix BLS key hash in setfinalizer: g1_hash was using
std::hash<const char*> which hashed the pointer address, not the key content.

sysio.roa - Fix reducepolicy RAM doubling: the reslimit modify lambda
was computing row.ram_bytes += (old - reclaim), which doubled RAM
instead of decreasing it. Simplified to row.ram_bytes -= reclaim.

sysio.roa - Fix increase_reslimit negative RAM handling: casting
negative int64_t to uint64_t silently wrapped. Now explicitly branches
on sign and adds an underflow guard.

sysio.roa - Fix reducepolicy unlimited NET/CPU underflow: when
get_resource_limits returns -1 (unlimited), subtracting the weight
produced a large negative value. Now preserves -1 for unlimited limits
and clamps finite limits to zero.

Add ROA contract tests covering addpolicy, expandpolicy,
reducepolicy, extendpolicy validation paths, multi-issuer policy
interactions, and newuser edge cases.
@heifner heifner requested a review from dtaghavi February 20, 2026 16:04
row.ram_bytes += (uint64_t)ram_bytes;
if (ram_bytes >= 0) {
row.ram_bytes += static_cast<uint64_t>(ram_bytes);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not allow for reduction of resources. It's used in addpolicy / expandpolicy which both check for only positive values. So if it somehow reached here it should reject.

Policies have a time_block which is meant to prevent a policy from being reduced until that block number is passed. Which reducepolicy is correctly enforcing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants