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

Feat/interpreter returns via events #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 56 additions & 37 deletions src/bootstrap/Bootstrapper.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func deployRootDiamond{
class_hash=_class.diamond,
contract_address_salt=salt,
constructor_calldata_size=DiamondCalldata.SIZE,
constructor_calldata=new (DiamondCalldata(0, 0, _class.rootDiamondFactory, _class.feltmap)),
constructor_calldata=new (
DiamondCalldata(0, 0, _class.rootDiamondFactory, _class.feltmap)
),
deploy_from_zero=FALSE,
);
}
Expand Down Expand Up @@ -157,44 +159,61 @@ func init{
let (high, low) = split_felt(self);

let facetCut_len = 6;
tempvar facetCut: FacetCut* = cast(new (
FacetCut(_class.feltmap, FacetCutAction.Add),
FacetCut(_class.erc721, FacetCutAction.Add),
FacetCut(_class.starkshell, FacetCutAction.Add),
FacetCut(_class.diamondCut, FacetCutAction.Add),
FacetCut(_class.metadata, FacetCutAction.Add),
FacetCut(_class.flobDb, FacetCutAction.Add),
), FacetCut*);

let tmp_len = (BFRCalldata.SIZE + 2) + (ERC721Calldata.SIZE + 1) + (StarkShellCalldata.SIZE + 2) + (DiamondCutCalldata.SIZE + 1) + 12;
tempvar tmp = cast(new (
BFRCalldata.SIZE + 1,
BFRCalldata.SIZE,
BFRCalldata(
_class.feltmap,
_class.erc721,
_class.flobDb,
_class.starkshell,
_class.diamondCut,
_class.metadata,
_class.erc1155,
_class.erc20,
_class.erc5114,
tempvar facetCut: FacetCut* = cast(
new (
FacetCut(_class.feltmap, FacetCutAction.Add),
FacetCut(_class.erc721, FacetCutAction.Add),
FacetCut(_class.starkshell, FacetCutAction.Add),
FacetCut(_class.diamondCut, FacetCutAction.Add),
FacetCut(_class.metadata, FacetCutAction.Add),
FacetCut(_class.flobDb, FacetCutAction.Add),
),
FacetCut*,
);

let tmp_len = (BFRCalldata.SIZE + 2) + (ERC721Calldata.SIZE + 1) + (
StarkShellCalldata.SIZE + 2
) + (DiamondCutCalldata.SIZE + 1) + 12;
tempvar tmp = cast(
new (
BFRCalldata.SIZE + 1,
BFRCalldata.SIZE,
BFRCalldata(
_class.feltmap,
_class.erc721,
_class.flobDb,
_class.starkshell,
_class.diamondCut,
_class.metadata,
_class.erc1155,
_class.erc20,
_class.erc5114,
),
ERC721Calldata.SIZE,
ERC721Calldata(
receiver=_owner,
tokenId_len=1,
tokenId_low=low,
tokenId_high=high,
ERC721Calldata.SIZE,
ERC721Calldata(receiver=_owner, tokenId_len=1, tokenId_low=low, tokenId_high=high),
StarkShellCalldata.SIZE + 1,
2,
StarkShellCalldata(
Function(_setShellFun_selector, _setShellFun_hash, 0),
Function(_mintContract_selector, _mintContract_hash, 0),
),
StarkShellCalldata.SIZE + 1,
2,
StarkShellCalldata(Function(_setShellFun_selector, _setShellFun_hash, 0), Function(_mintContract_selector, _mintContract_hash, 0)),
DiamondCutCalldata.SIZE,
DiamondCutCalldata(0),
11, 0, 0, 0, 4, 184555836509371486644856095017587421344261193474617388276263770152936827443, 203998027954878725543997547266317984232748597657159516903365148909254028897, 202244606418614541364902086132942206699045874315590809968639424267107263609, 10754949894223100254076072945295018243026244912222009195, FALSE, 0, 0, // https://m4chgvnjpozvm7p7jeo7vj3susfrkuencv6j5bf3u6mokcshjmeq.arweave.net/ZwRzVal7s1Z9_0kd-qdypIsVUI0VfJ6Eu6eY5QpHSwk
), felt*);
DiamondCutCalldata.SIZE,
DiamondCutCalldata(0),
11,
0,
0,
0,
4,
184555836509371486644856095017587421344261193474617388276263770152936827443,
203998027954878725543997547266317984232748597657159516903365148909254028897,
202244606418614541364902086132942206699045874315590809968639424267107263609,
10754949894223100254076072945295018243026244912222009195,
FALSE,
0,
0,
),
felt*,
);

let (local calldata: felt*) = alloc();

Expand Down
14 changes: 14 additions & 0 deletions src/common/table.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from starkware.cairo.common.memcpy import memcpy

namespace Table {
// @return New length of _table
func add_row(_table_len: felt, _table: felt*, _row_len: felt, _row: felt*) -> felt {
assert _table[_table_len] = _row_len;
let _table_len = _table_len + 1;

memcpy(_table + _table_len, _row, _row_len);
let _table_len = _table_len + _row_len;

return _table_len;
Comment on lines +5 to +12
Copy link

Choose a reason for hiding this comment

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

use case for this function is kind of confusing to me atm.
it actually merges two felt arrays using memcpy but i see two other options here:

  1. using another struct to aggregate data
  2. use recursion instead of memcpy
    add_row(_table_len + 1, _table + 1, _row_len - 1, _row + 1)

moreover, the name could rather be add_rows or something like append_felts.

}
}
25 changes: 7 additions & 18 deletions src/starkshell/interpreteInstruction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,17 @@ func interpreteInstruction() -> (res_len: felt, res: felt*) {
input1=NULLvar,
input2=NULLvar,
output=NULLvar,
);
);

// res = exec(_program, _memory)
tempvar instruction1 = Instruction(
primitive=Primitive(0, exec_keyword),
input1=Calldata,
input2=NULLvar,
output=ResultVar,
);
primitive=Primitive(0, exec_keyword), input1=Calldata, input2=NULLvar, output=ResultVar
);

// return res
tempvar instruction2 = Instruction(
primitive=Primitive(0, return_keyword),
input1=ResultVar,
input2=NULLvar,
output=NULLvar,
);
primitive=Primitive(0, return_keyword), input1=ResultVar, input2=NULLvar, output=NULLvar
);

tempvar memory_layout = (ResultVar);

Expand All @@ -57,13 +51,8 @@ func interpreteInstruction() -> (res_len: felt, res: felt*) {
let felt_code_len = total_len + 1;

tempvar felt_code: felt* = new (
total_len,
instruction_len,
instruction0,
instruction1,
instruction2,
memory_layout,
);
total_len, instruction_len, instruction0, instruction1, instruction2, memory_layout
);

return (felt_code_len, felt_code);
}
36 changes: 10 additions & 26 deletions src/starkshell/invertBoolean.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,30 @@ func invertBoolean() -> (res_len: felt, res: felt*) {
Variable(var0_identifier, 0, 0, 0),
Variable(sentinel_selector, 0, 0, 0),
NULLvar,
);
);

tempvar instruction1 = Instruction(
Primitive(0, return_keyword),
Variable(false_identifier, 0, 0, 0),
NULLvar,
NULLvar,
);
Primitive(0, return_keyword), Variable(false_identifier, 0, 0, 0), NULLvar, NULLvar
);

tempvar instruction2 = Instruction(
Primitive(0, return_keyword),
Variable(true_identifier, 0, 0, 0),
NULLvar,
NULLvar,
);
Primitive(0, return_keyword), Variable(true_identifier, 0, 0, 0), NULLvar, NULLvar
);

tempvar sentinel_var = Variable(
selector=sentinel_selector,
protected=FALSE,
type=0,
data_len=2,
);
selector=sentinel_selector, protected=FALSE, type=0, data_len=2
);

tempvar memory_layout = (
sentinel_var, 1, 2,
);
tempvar memory_layout = (sentinel_var, 1, 2);

let instruction_len = 3 * Instruction.SIZE;
let memory_layout_len = 1 * Variable.SIZE + sentinel_var.data_len;
let total_len = instruction_len + memory_layout_len + 1;
let felt_code_len = total_len + 1;

tempvar felt_code: felt* = new (
total_len,
instruction_len,
instruction0,
instruction1,
instruction2,
memory_layout,
);
total_len, instruction_len, instruction0, instruction1, instruction2, memory_layout
);

return (felt_code_len, felt_code);
}
Loading