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

Stdlibs test returning error when rebased to next #553

Closed
0xkanekiken opened this issue Nov 23, 2022 · 10 comments · Fixed by #555
Closed

Stdlibs test returning error when rebased to next #553

0xkanekiken opened this issue Nov 23, 2022 · 10 comments · Fixed by #555
Labels
bug Something isn't working

Comments

@0xkanekiken
Copy link
Contributor

On rebasing from the latest next branch, we see some issues when trying to execute some miden program which seems to be working earlier with no hiccups.

@Al-Kindi-0 highlighted this issue when he was running fri_fold2_ext2 test.
Steps to reproduce the error:

  1. Go to the following commit in Al's miden fork
  2. If you run cargo test fri_fold2_ext2, the program will get executed, but the final stack will not match as the expected stack is not what is written in the test yet. But if we uncomment the part and rerun the test, the test fails even before and returns the following error:
running 1 test
thread 'stdlib::crypto::fri::fri_fold2_ext2' panicked at 'called `Result::unwrap()` on an `Err` value: NotU32Value(BaseElement(6666087519483434683))', miden/tests/integration/helpers/mod.rs:189:36
stack backtrace:
  1. We observed a weird thing when we tried to add some redundant code(which doesn't affect the program) in the proc, e.g., push.3 drop, the program was still failing. When we inlined this procedure and used it directly in test program, the test compiled.

The following is working:

use.std::crypto::fri
 begin
          exec.fri::preprocess
          dup                         #[add_i,add_i,num_q,d,g,t_d,add_f,...]
          movdn.6                     #[add_i,num_q,d,g,t_d,add_f,add_i,...]
          mem_storew                  #[num_q,d,g,t_d,...]
          push.0.0.0
          adv_loadw                   #[0,p,e1,e0,d,g,t_d,...]
          drop                        #[p,e1,e0,d,g,t_d,...]
          dup                         #[p,p,e1,e0,d,g,t_d,...]
          movup.5                     #[g,p,p,e1,e0,d,t_d,...]
          swap                        #[p,g,p,e1,e0,d,t_d,...]
          exp.u32 
          push.4
          drop
 end

whereas the following is not:

 use.std::crypto::fri
 begin
        exec.fri::preprocess
        exec.fri::verify_fri
 end
export.verify_fri
    dup                         #[add_i,add_i,num_q,d,g,t_d,add_f,...]
    movdn.6                     #[add_i,num_q,d,g,t_d,add_f,add_i,...]
    mem_storew                  #[num_q,d,g,t_d,...]
    push.0.0.0
    adv_loadw                   #[0,p,e1,e0,d,g,t_d,...]
    drop                        #[p,e1,e0,d,g,t_d,...]
    dup                         #[p,p,e1,e0,d,g,t_d,...]
    movup.5                     #[g,p,p,e1,e0,d,t_d,...]
    swap                        #[p,g,p,e1,e0,d,t_d,...]
    exp.u32                #[poe,p,e1,e0,d,t_d,...]
    push.4
    drop        
end
@bobbinth
Copy link
Contributor

Quick question: what is the int value of BaseElement(6666087519483434683)?

@0xkanekiken
Copy link
Contributor Author

Quick question: what is the int value of BaseElement(6666087519483434683)?

15205196862421381961 is the int value

@bobbinth
Copy link
Contributor

This is not a u32 value, right? And so the error is correct?

@0xkanekiken
Copy link
Contributor Author

0xkanekiken commented Nov 23, 2022

Agreed but the following is passing:

export.verify_fri
        dup                         #[add_i,add_i,num_q,d,g,t_d,add_f,...]
        movdn.6                     #[add_i,num_q,d,g,t_d,add_f,add_i,...]
        mem_storew                  #[num_q,d,g,t_d,...]
        push.0.0.0
        adv_loadw                   #[0,p,e1,e0,d,g,t_d,...]
        drop                        #[p,e1,e0,d,g,t_d,...]
        dup                         #[p,p,e1,e0,d,g,t_d,...]
        movup.5                     #[g,p,p,e1,e0,d,t_d,...]
        swap                        #[p,g,p,e1,e0,d,t_d,...]
        exp.u32                #[poe,p,e1,e0,d,t_d,...]
end

And on adding push.2 and drop to the above proc after exp.u32, it is failing with a NotU32Value error.

export.verify_fri
        dup                         #[add_i,add_i,num_q,d,g,t_d,add_f,...]
        movdn.6                     #[add_i,num_q,d,g,t_d,add_f,add_i,...]
        mem_storew                  #[num_q,d,g,t_d,...]
        push.0.0.0
        adv_loadw                   #[0,p,e1,e0,d,g,t_d,...]
        drop                        #[p,e1,e0,d,g,t_d,...]
        dup                         #[p,p,e1,e0,d,g,t_d,...]
        movup.5                     #[g,p,p,e1,e0,d,t_d,...]
        swap                        #[p,g,p,e1,e0,d,t_d,...]
        exp.u32                #[poe,p,e1,e0,d,t_d,...]
        push.2
        drop
end

We should have this error in the first case as well

@bobbinth
Copy link
Contributor

Yep, that's definitely a bug. Could we create a small test which triggers this?

@0xkanekiken
Copy link
Contributor Author

Sure, I'll try to narrow it down to a small test.

@itzmeanjan
Copy link
Contributor

itzmeanjan commented Nov 23, 2022

I was trying to rebase my PR #495 , bringing latest work from next (upstream) branch and I'm seeings errors like below, when running ec_ext5 standard library test cases

cargo test -p miden ec_ext5

...

failures:

---- stdlib::math::ec_ext5::test_ec_ext5_gen_multiplication stdout ----
thread 'stdlib::math::ec_ext5::test_ec_ext5_gen_multiplication' panicked at 'called `Result::unwrap()` on an `Err` value: NotBinaryValue(BaseElement(658699090402360355))', miden/tests/integration/helpers/mod.rs:189:36
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    stdlib::math::ec_ext5::test_ec_ext5_gen_multiplication

Note
It seems that the way field element is expected, due to presence of if.true ... end code block ahead, can't be found on stack. Meaning it's supposed to be {0, 1} as result of previous line of instruction, but some change has made its way into Miden VM implementation s.t. it's no more the case which is exactly why tests are failing. Error is correct, but due to some bug in field element representation, value expected to be {0, 1} is not anymore {0, 1}, which is why executor is throwing such error.

How to reproduce this error ?

git clone https://github.com/itzmeanjan/miden.git

pushd miden

git remote add upstream https://github.com/maticnetwork/miden.git
git checkout next
git pull upstream next
git checkout ec-ext5-mulgen
git merge next
cargo test -p miden ec_ext5

popd

@tohrnii
Copy link
Contributor

tohrnii commented Nov 23, 2022

@itzmeanjan your issue seems to be unrelated. We made a change to mem_store and loc_store instructions recently (#500) to also drop the element from stack so the subsequent drop instruction is no longer required. I did this change to your PR for all the occurrences of loc_store and the tests seems to be passing. Can you please check if this fixes the issue for you or if it still persists?

@bobbinth bobbinth added the bug Something isn't working label Nov 23, 2022
@bobbinth bobbinth linked a pull request Nov 23, 2022 that will close this issue
@0xkanekiken
Copy link
Contributor Author

Closed by #555

@itzmeanjan
Copy link
Contributor

@itzmeanjan your issue seems to be unrelated. We made a change to mem_store and loc_store instructions recently (#500) to also drop the element from stack so the subsequent drop instruction is no longer required. I did this change to your PR for all the occurrences of loc_store and the tests seems to be passing. Can you please check if this fixes the issue for you or if it still persists?

Thanks, I didn't know that.

itzmeanjan added a commit to itzmeanjan/miden that referenced this issue Nov 25, 2022
Also resolves issue reported in 0xPolygonMiden#553 (comment)

Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants