This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from OffchainLabs/fixed-memory-edge-case
Memory Edge Cases
- Loading branch information
Showing
10 changed files
with
155 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,9 @@ impl Deref for GuestPtr { | |
&self.0 | ||
} | ||
} | ||
|
||
impl GuestPtr { | ||
pub fn to_u64(self) -> u64 { | ||
self.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
;; Copyright 2023-2024, Offchain Labs, Inc. | ||
;; For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE | ||
|
||
(module | ||
(import "console" "tee_i32" (func $tee_i32 (param i32) (result i32))) | ||
(func (export "user_entrypoint") (param $args_len i32) (result i32) | ||
;; fail to grow the memory a non-zero number of pages | ||
i32.const -65537 | ||
call $tee_i32 | ||
memory.grow | ||
call $tee_i32 | ||
i32.const -1 | ||
i32.eq | ||
i32.eqz | ||
(if (then unreachable)) | ||
|
||
;; succeed growing 0 pages | ||
i32.const 0 | ||
memory.grow | ||
call $tee_i32 | ||
i32.eqz | ||
i32.eqz | ||
) | ||
(memory (export "memory") 0 0) | ||
) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;; Copyright 2023, Offchain Labs, Inc. | ||
;; For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE | ||
|
||
(module | ||
(import "vm_hooks" "pay_for_memory_grow" (func $pay_for_memory_grow (param i32))) | ||
(import "vm_hooks" "read_args" (func $read_args (param i32))) | ||
(import "vm_hooks" "write_result" (func $write_result (param i32 i32))) | ||
(import "console" "tee_i32" (func $tee_i32 (param i32) (result i32))) | ||
(func (export "user_entrypoint") (param $args_len i32) (result i32) | ||
local.get $args_len | ||
i32.eqz | ||
(if (then | ||
;; write an empty result to offset 0 | ||
(call $write_result (i32.const 0) (i32.const 0)) | ||
(return (i32.const 0)) | ||
)) | ||
|
||
;; grow 1 page so that we can read our args | ||
i32.const 1 | ||
memory.grow | ||
drop | ||
|
||
;; store the size argument at offset 0 | ||
i32.const 0 | ||
call $read_args | ||
|
||
;; read the argument and grow the remainder | ||
i32.const 0 | ||
i32.load8_u | ||
i32.const 1 | ||
i32.sub | ||
memory.grow | ||
drop | ||
|
||
;; write a result (should panic if out of bounds) | ||
i32.const 1 | ||
i32.load | ||
i32.const 5 | ||
i32.load | ||
call $write_result | ||
|
||
i32.const 0 | ||
) | ||
(memory (export "memory") 0) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters