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

Add Counter Example #609

Open
DavePearce opened this issue Nov 6, 2023 · 0 comments
Open

Add Counter Example #609

DavePearce opened this issue Nov 6, 2023 · 0 comments

Comments

@DavePearce
Copy link
Collaborator

DavePearce commented Nov 6, 2023

const COUNTER_CODE : seq<u8> := [
    0x60,0x00,0x54,0x60,0x01,0x01,0x80,0x61,0x00,0x10,0x57,0x60,0x00,0x60,0x00,0xfd,0x5b,0x60,0x00,0x55,0x00
]
const ENTRY_STATE : ExecutingState := EVM.Init(gas:=1000,code:=COUNTER_CODE)

method Counter(st0: ExecutingState) returns (stn:State)
// Require enough space for two stack items
requires st0 == ENTRY_STATE 
// Upon successful execution, counter increases by 1.
ensures stn.EXECUTING? ==> st0.Load(0x0) < stn.Load(0x0) {
    var st := st0;
    st := Bytecode.Push1(st,0x00);
    st := Bytecode.SLoad(st);
    st := Bytecode.Push1(st,0x01);
    st := Bytecode.Add(st);
    st := Bytecode.Dup(st,1);
    st := Bytecode.Push2(st,0x0010);
    st := Bytecode.JumpI(st);
    assert st.PC() in {0x0b,0x10};
    if st.PC() == 0x0b {
        st := Bytecode.Push1(st,0x00);
        st := Bytecode.Push1(st,0x00);
        st := Bytecode.Revert(st);
    } else {
        st := Bytecode.JumpDest(st);
        st := Bytecode.Push1(st,0x00);
        st := Bytecode.SStore(st);
        st := Bytecode.Stop(st);
    }
    return st;
}
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

No branches or pull requests

1 participant