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

load_elf: change maximum memory address to SYSTEM.start() #878

Merged
merged 7 commits into from
Sep 18, 2023

Conversation

SchmErik
Copy link
Contributor

load_elf takes a max_mem parameter before this change, MEM_SIZE was used as the
parameter. Any memory region about SYSTEM.start() is intended for use by the
zkVM and is not to be used by the ELF. Rather than have maximum memory as a
parameter, use a hard-coded constant, GUEST_MAX_MEM as the upper bound for
memory during elf load. This PR also restricts the loader to no load above GUEST_MAX_MEM

load_elf takes a max_mem parameter before this change, MEM_SIZE was used as the
parameter. Any memory region about `SYSTEM.start()` is intended for use by the
zkVM and is not to be used by the ELF. Rather than have maximum memory as a
parameter, use a hard-coded constant, GUEST_MAX_MEM as the upper bound for
memory during elf load.
@flaub
Copy link
Member

flaub commented Sep 14, 2023

I'd prefer to use a parameter, so that we can use this same code for newer circuit versions that have a different max memory bound.

@SchmErik
Copy link
Contributor Author

SchmErik commented Sep 14, 2023

I'd prefer to use a parameter, so that we can use this same code for newer circuit versions that have a different max memory bound.

Ah, that's a good point. Will fix tomorrow

…MEM_SIZE in risc0-zkvm

MEM_SIZE indicates the size of the total memory in the zkVM. This information
is not very useful because what users are actually concerned about are the
maximum memory that guest programs can use. As of this writing anything between
0x400 and SYSTEM.start can be used for the guest. Anything between SYSTEM.start
to MEM_SIZE should not be used by guests or it could result in unintended
behavior in the guest program. Users call the load_elf function to create an
instances of valid `Program` structs. Using MEM_SIZE as a parameter to this
function allows load_elf to write between invalid regions for guest programs
but it also enables this function to write between SYSTEM.start and MEM_SIZE
which results in undesirable behavior. Prevent this by passing GUEST_MAX_MEM
instead of MEM_SIZE to load_elf.

Thinking about the usecase of MEM_SIZE, I didn't find that this is a useful
value for the zkVM to export becasue users are actually interested in
GUEST_MAX_MEM rather than MEM_SIZE. I've removed the re-export for MEM_SIZE
from risc0-zkvm.
@github-actions
Copy link

Benchmark for Linux-cuda 76556c2

Click to hide benchmark
Test Base PR %
fib/100/execute 5.1±0.10ms 5.1±0.13ms 0.00%
fib/100/prove 834.3±21.36ms 696.4±5.66ms -16.53%
fib/100/total 823.2±10.34ms 700.3±4.91ms -14.93%
fib/1000/execute 5.7±0.13ms 5.6±0.12ms -1.75%
fib/1000/prove 851.2±11.10ms 728.7±3.68ms -14.39%
fib/1000/total 847.1±11.79ms 737.5±2.80ms -12.94%
fib/10000/execute 11.3±0.14ms 11.3±0.14ms 0.00%
fib/10000/prove 3.3±0.01s 2.9±0.01s -12.12%
fib/10000/total 3.3±0.02s 2.9±0.01s -12.12%

Benchmark for Linux-default

    <details open>
      <summary>Click to hide benchmark</summary>
      Benchmarks have changed between the two branches, unable to diff.
    </details>

Benchmark for macOS-default 76556c2

Click to hide benchmark
Test Base PR %
fib/100/execute 2.8±0.14ms 2.7±0.11ms -3.57%
fib/100/prove 3.7±0.06s 3.6±0.05s -2.70%
fib/100/total 3.6±0.05s 3.6±0.06s 0.00%
fib/1000/execute 3.1±0.08ms 3.0±0.08ms -3.23%
fib/1000/prove 3.7±0.07s 3.6±0.08s -2.70%
fib/1000/total 3.7±0.07s 3.7±0.08s 0.00%
fib/10000/execute 6.0±0.08ms 5.8±0.08ms -3.33%
fib/10000/prove 15.1±0.08s 15.0±0.11s -0.66%
fib/10000/total 15.1±0.09s 15.0±0.09s -0.66%

Benchmark for macOS-metal 76556c2

Click to hide benchmark
Test Base PR %
fib/100/execute 2.8±0.10ms 2.8±0.11ms 0.00%
fib/100/prove 801.9±3.28ms 793.0±5.89ms -1.11%
fib/100/total 826.2±5.10ms 817.2±4.05ms -1.09%
fib/1000/execute 3.1±0.09ms 3.0±0.05ms -3.23%
fib/1000/prove 820.8±3.56ms 819.8±5.26ms -0.12%
fib/1000/total 843.2±6.31ms 838.1±6.25ms -0.60%
fib/10000/execute 5.8±0.12ms 5.8±0.20ms 0.00%
fib/10000/prove 3.1±0.02s 3.1±0.01s 0.00%
fib/10000/total 3.1±0.01s 3.1±0.01s 0.00%

@SchmErik SchmErik requested a review from flaub September 14, 2023 23:12
@github-actions
Copy link

Benchmark for Linux-cuda

    <details open>
      <summary>Click to hide benchmark</summary>
      Benchmarks have changed between the two branches, unable to diff.
    </details>

Benchmark for Linux-default 359b16d

Click to hide benchmark
Test Base PR %
fib/100/execute 5.0±0.42ms 4.7±0.07ms -6.00%
fib/100/prove 3.8±1.32s 2.6±0.33s -31.58%
fib/100/total 2.3±0.23s 2.0±0.12s -13.04%
fib/1000/execute 5.4±0.21ms 5.3±0.08ms -1.85%
fib/1000/prove 2.5±0.22s 2.4±0.46s -4.00%
fib/1000/total 2.8±0.74s 2.5±0.44s -10.71%
fib/10000/execute 10.0±0.11ms 9.9±0.14ms -1.00%
fib/10000/prove 7.4±0.39s 6.9±0.31s -6.76%
fib/10000/total 7.9±0.93s 7.4±0.63s -6.33%

Benchmark for macOS-default 359b16d

Click to hide benchmark
Test Base PR %
fib/100/execute 2.8±0.12ms 2.7±0.12ms -3.57%
fib/100/prove 3.6±0.05s 3.6±0.05s 0.00%
fib/100/total 3.6±0.06s 3.6±0.07s 0.00%
fib/1000/execute 3.1±0.11ms 3.0±0.06ms -3.23%
fib/1000/prove 3.7±0.04s 3.6±0.06s -2.70%
fib/1000/total 3.7±0.08s 3.7±0.06s 0.00%
fib/10000/execute 5.9±0.08ms 5.8±0.04ms -1.69%
fib/10000/prove 15.0±0.10s 14.9±0.14s -0.67%
fib/10000/total 15.0±0.07s 14.9±0.11s -0.67%

Benchmark for macOS-metal 359b16d

Click to hide benchmark
Test Base PR %
fib/100/execute 2.8±0.09ms 2.7±0.12ms -3.57%
fib/100/prove 799.4±3.39ms 796.9±5.38ms -0.31%
fib/100/total 821.8±5.98ms 818.6±6.68ms -0.39%
fib/1000/execute 3.0±0.17ms 3.0±0.14ms 0.00%
fib/1000/prove 818.3±5.14ms 817.7±5.70ms -0.07%
fib/1000/total 843.4±7.77ms 837.4±4.67ms -0.71%
fib/10000/execute 5.8±0.07ms 5.8±0.08ms 0.00%
fib/10000/prove 3.1±0.01s 3.1±0.01s 0.00%
fib/10000/total 3.1±0.01s 3.1±0.01s 0.00%

@flaub flaub requested a review from nategraf September 15, 2023 21:28
@SchmErik SchmErik enabled auto-merge (squash) September 18, 2023 17:04
@github-actions
Copy link

Benchmark for Linux-cuda 3e39786

Click to hide benchmark
Test Base PR %
fib/100/execute 5.1±0.09ms 5.0±0.11ms -1.96%
fib/100/prove 702.1±4.53ms 702.0±3.88ms -0.01%
fib/100/total 706.6±4.70ms 705.8±4.86ms -0.11%
fib/1000/execute 5.7±0.11ms 5.6±0.11ms -1.75%
fib/1000/prove 735.7±5.96ms 734.9±5.70ms -0.11%
fib/1000/total 743.7±6.75ms 741.0±5.26ms -0.36%
fib/10000/execute 11.4±0.12ms 11.3±0.10ms -0.88%
fib/10000/prove 2.9±0.02s 2.8±0.01s -3.45%
fib/10000/total 2.9±0.02s 2.8±0.01s -3.45%

Benchmark for Linux-default

    <details open>
      <summary>Click to hide benchmark</summary>
      Benchmarks have changed between the two branches, unable to diff.
    </details>

Benchmark for macOS-default 3e39786

Click to hide benchmark
Test Base PR %
fib/100/execute 2.8±0.15ms 2.7±0.12ms -3.57%
fib/100/prove 3.6±0.04s 3.6±0.05s 0.00%
fib/100/total 3.6±0.05s 3.6±0.08s 0.00%
fib/1000/execute 3.1±0.06ms 2.9±0.10ms -6.45%
fib/1000/prove 3.7±0.06s 3.6±0.08s -2.70%
fib/1000/total 3.7±0.06s 3.6±0.10s -2.70%
fib/10000/execute 6.0±0.13ms 5.8±0.09ms -3.33%
fib/10000/prove 15.0±0.14s 15.0±0.11s 0.00%
fib/10000/total 15.1±0.17s 15.1±0.21s 0.00%

Benchmark for macOS-metal 3e39786

Click to hide benchmark
Test Base PR %
fib/100/execute 2.8±0.13ms 2.6±0.17ms -7.14%
fib/100/prove 801.0±2.16ms 800.0±3.88ms -0.12%
fib/100/total 823.0±5.03ms 821.4±7.81ms -0.19%
fib/1000/execute 3.1±0.12ms 3.1±0.05ms 0.00%
fib/1000/prove 819.5±3.25ms 817.9±3.73ms -0.20%
fib/1000/total 842.0±7.00ms 841.5±5.30ms -0.06%
fib/10000/execute 5.8±0.10ms 5.8±0.09ms 0.00%
fib/10000/prove 3.1±0.01s 3.1±0.01s 0.00%
fib/10000/total 3.1±0.01s 3.1±0.01s 0.00%

@SchmErik SchmErik merged commit b7ac357 into main Sep 18, 2023
20 checks passed
@SchmErik SchmErik deleted the erik/hexens-rsc0-6 branch September 18, 2023 17:40
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.

None yet

2 participants