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

Check size is not greater than 8 for RV32A and RV63A #103

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

mininny
Copy link
Collaborator

@mininny mininny commented Dec 11, 2024

Description

The RV63A and RV32A operations are supported by the VM implementations.
The corresponding instructions encode the size in the funct3 field.

The Solidity implementation ensures that the size is correct by checking that it is not lower than 4 and not greater than 8.

        // 0b010 == RV32A W variants
        // 0b011 == RV64A D variants
        let size := shl64(funct3, toU64(1))
        if or(lt64(size, toU64(4)), gt64(size, toU64(8))) { revertWithCode(0xbada70) } // bad AMO size

However, the Go slow and fast implementations only check that the size is not lower than 4.
There is no check to ensure it is not greater than 8.

	// 0b010 == RV32A W variants
	// 0b011 == RV64A D variants
	size := shl64(funct3, toU64(1))
	if lt64(size, toU64(4)) != 0 {
		revertWithCode(riscv.ErrBadAMOSize, fmt.Errorf("bad AMO size: %d", size))
	}

The Go implementations (slow and fast) should ensure that the size is not greater than 8.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 61.89%. Comparing base (8ff9318) to head (36b7895).

Files with missing lines Patch % Lines
rvgo/fast/vm.go 0.00% 0 Missing and 1 partial ⚠️
rvgo/slow/vm.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #103   +/-   ##
=======================================
  Coverage   61.89%   61.89%           
=======================================
  Files          27       27           
  Lines        4091     4091           
=======================================
  Hits         2532     2532           
  Misses       1427     1427           
  Partials      132      132           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mininny mininny requested review from clabby and ImTei December 13, 2024 06:51
@BlocksOnAChain BlocksOnAChain added the Audit finding grouping for our audit findings label Dec 16, 2024
@mininny mininny added this pull request to the merge queue Jan 8, 2025
Merged via the queue into master with commit cdddf9e Jan 8, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Audit finding grouping for our audit findings
Development

Successfully merging this pull request may close these issues.

4 participants