Skip to content

Support memory(bytes) in ABI and dispatch#367

Merged
mbenke merged 7 commits into
argotorg:mainfrom
axic:abi-bytes
May 6, 2026
Merged

Support memory(bytes) in ABI and dispatch#367
mbenke merged 7 commits into
argotorg:mainfrom
axic:abi-bytes

Conversation

@axic

@axic axic commented May 1, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread std/std.solc Outdated
}
}

// TODO: this is a copy of memory(string)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No idea how to deduplicate this, beyond having some helper pulled out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was updated.

Comment thread std/std.solc
forall reader. reader : WordReader =>
instance ABIDecoder(memory(bytes), reader):ABIDecode(memory(bytes))
{
function decode(ptr:ABIDecoder(memory(bytes), reader), currentHeadOffset:word) -> memory(bytes) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one I'm not sure how to deduplicate.

@mbenke mbenke May 5, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about

forall a ptrtype reader. reader:WordReader =>
function blockDecode(ptr:ABIDecoder(memory(a), reader), currentHeadOffset:word) -> memory(a) {
        let tmp:word;
        let headRdr = WordReader.advance(ptr, currentHeadOffset);
        let tailPtr : word = WordReader.read(headRdr);

        let src = WordReader.advance(ptr, tailPtr);
        let srcRdr = getReader(src);
        let length = WordReader.read(src);
        let total = Add.add(length, 32);
	    let rounded = round_up_to_mul_of_32(total);
        let resultPtr : word = allocate_memory(rounded)	;
        WordReader.copyToMem(srcRdr, resultPtr, total);
        return memory(resultPtr);
}

forall reader. reader : WordReader =>
instance ABIDecoder(memory(bytes), reader):ABIDecode(memory(bytes))
{
    function decode(ptr:ABIDecoder(memory(bytes), reader), currentHeadOffset:word) -> memory(bytes) {
      return blockDecode(ptr, currentHeadOffset);
    }
}   

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mbenke thanks updated.

@mbenke mbenke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a test, for example by adding to test/examples/dispatch/basic.solc

    function idbytes(b:memory(bytes)) -> (memory(bytes)) {
        return b;
    }

and to basic.json

      {
        "input": {
	  "text-calldata": "idbytes(bytes)(bytes)",
          "calldata":"0xc886fb8000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000",
          "value": "0"
        },
        "kind": "call",
        "output": {
          "returndata":"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000",
          "status": "success"
        }
      },

@axic axic requested a review from mbenke May 6, 2026 10:04
@axic

axic commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@mbenke added tests

@mbenke mbenke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, looks good now.

@mbenke mbenke merged commit 2f16e6c into argotorg:main May 6, 2026
4 checks passed
@axic axic deleted the abi-bytes branch May 6, 2026 14:46
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.

3 participants