Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

fix: typos #991

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/docs/features/cairo_stubs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The system works in the following way:

1. To start a Cairo Block add your Cairo code above a Solidity function with 3 forward slashes at the beginning of each line and the phrase `warp-cairo` at the top.
2. The user then uses a number of MACROS to interact with the transpiled contract.
3. The Solidity function will then be replaced with the Cario function that is above it.
3. The Solidity function will then be replaced with the Cairo function that is above it.

The following MACROS are supported:

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/getting_started/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Available Commands:
analyse [options] <file> Debug tool to analyse the AST
status [options] <tx_hash> Get the status of a transaction
compile [options] <file> Compile cairo files with warplib in the cairo-path
gen_interface [options] <file> Use native Cairo contracts in your Soldity by creating a Solidity interface and a Cairo translation contract for the target Cairo contract
gen_interface [options] <file> Use native Cairo contracts in your Solidity by creating a Solidity interface and a Cairo translation contract for the target Cairo contract
deploy [options] <file> Deploy a warped cairo contract
deploy_account [options] Deploy an account to Starknet
invoke [options] <file> Invoke a function on a warped contract using the Solidity abi
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/getting_started/inputs-and-outputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This is supported in Warp's `deploy`, `invoke` and `call` commands.
Warp takes these inputs and transcodes them into Cairo to forward them onto the desired network.

```
warp invoke <Cario Contract> --inputs \"ExampleString\",\[1,2,3,4\],-1,100.
warp invoke <Cairo Contract> --inputs \"ExampleString\",\[1,2,3,4\],-1,100.
```

### Using Cairo ABI
Expand All @@ -34,7 +34,7 @@ Note that there are some nuances that come with using the Cairo ABI:
upper 128 bits e.g `0x10000000000000000000000000000000f` as a `uint256` -> `15,1`.

```
warp invoke <Cario Contract> --use_cairo_abi --inputs 13,0x45,0x78,0x61,0x6d,0x70,0x6c,0x65,0x53,0x74,0x72,0x69,0x6e,0x67,4,1,2,3,4,255,100.
warp invoke <Cairo Contract> --use_cairo_abi --inputs 13,0x45,0x78,0x61,0x6d,0x70,0x6c,0x65,0x53,0x74,0x72,0x69,0x6e,0x67,4,1,2,3,4,255,100.
```

### Passing values of different types in both ABIs
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/solidity_equivalents/inputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Arrays can have a compile-time fixed size, or they can have a dynamic size.
`uint[3][2]` is represented as `(Uint256, Uint256, Uint256), (Uint256, Uint256, Uint256))`.
So, If you want to pass `[[12, 13, 14], [13, 14, 15]]` then you have to provide `12, 0, 13, 0, 14, 0, 13, 0, 14, 0, 15, 0` to interact with warped contracts.

- Dynamic sized arrays are repsented as `(arr_len: felt, arr: (base type in cairo)*)`, the first value represents number of elements in the array.
- Dynamic sized arrays are represented as `(arr_len: felt, arr: (base type in cairo)*)`, the first value represents number of elements in the array.

**Example**:

Expand Down
12 changes: 6 additions & 6 deletions src/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AST {
);
assert(
roots.every((sourceUnit) => sourceUnit.requiredContext === roots[0].requiredContext),
'All contexts should be the same, otherwise they are from seperate solc-typed-ast compiles and they will have no relationship to each other.',
'All contexts should be the same, otherwise they are from separate solc-typed-ast compiles and they will have no relationship to each other.',
);
this.context = roots[0].requiredContext;
this.inference = new InferType(compilerVersion);
Expand Down Expand Up @@ -119,18 +119,18 @@ export class AST {
[replacementVariable],
);
this.insertStatementBefore(node, declaration);
const replacementIdentifer = new Identifier(
const replacementIdentifier = new Identifier(
this.tempId,
node.src,
node.typeString,
newName,
replacementVariable.id,
node.raw,
);
this.replaceNode(node, replacementIdentifer);
this.replaceNode(node, replacementIdentifier);
declaration.vInitialValue = node;
this.registerChild(node, declaration);
return [replacementIdentifer, declaration];
return [replacementIdentifier, declaration];
}

getContainingRoot(node: ASTNode): SourceUnit {
Expand Down Expand Up @@ -215,7 +215,7 @@ export class AST {
}

const parent = existingStatement.parent;
// Blocks are not instances of Statements, but they satisy typescript shaped typing rules to be classed as Statements
// Blocks are not instances of Statements, but they satisfy typescript shaped typing rules to be classed as Statements
const replacementBlock = createBlock([existingStatement, newStatement], this);
this.replaceNode(existingStatement, replacementBlock, parent);
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export class AST {
}

const parent = existingStatement.parent;
// Blocks are not instances of Statements, but they satisy typescript shaped typing rules to be classed as Statements
// Blocks are not instances of Statements, but they satisfy typescript shaped typing rules to be classed as Statements
const replacementBlock = createBlock([newStatement, existingStatement], this);
this.replaceNode(existingStatement, replacementBlock, parent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/cairoNodes/cairoFunctionDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class CairoFunctionDefinition extends FunctionDefinition {
) {
assert(
!(acceptsRawDArray && acceptsUnpackedStructArray),
'A function cannot recieve both structured and raw dynamic arrays',
'A function cannot receive both structured and raw dynamic arrays',
);
super(
id,
Expand Down
2 changes: 1 addition & 1 deletion src/ast/cairoNodes/cairoGeneratedFunctionDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CairoRawStringFunctionDefinition } from './cairoRawStringFunctionDefini

export class CairoGeneratedFunctionDefinition extends CairoRawStringFunctionDefinition {
/**
* List of function defintions called by the generated function
* List of function definitions called by the generated function
*/
public functionsCalled: FunctionDefinition[];

Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/abi/abiDecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AbiDecode extends StringIndexedFuncGenWithAuxiliar {
public gen(expressions: Expression[]): FunctionCall {
assert(
expressions.length === 2,
'ABI decode must recieve two arguments: data to decode, and types to decode into',
'ABI decode must receive two arguments: data to decode, and types to decode into',
);
const [data, types] = expressions.map(
(t) => generalizeType(safeGetNodeType(t, this.ast.inference))[0],
Expand Down
6 changes: 3 additions & 3 deletions src/cairoUtilFuncGen/abi/abiEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const IMPLICITS =
'{bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt, warp_memory : DictAccess*}';

/**
* Given any data type produces the same output of solidty abi.encode
* Given any data type produces the same output of solidity abi.encode
* in the form of an array of felts where each element represents a byte
*/
export class AbiEncode extends AbiBase {
Expand Down Expand Up @@ -282,7 +282,7 @@ export class AbiEncode extends AbiBase {
if (existing !== undefined) return existing;

const elementT = getElementType(type);
const elemntTSize = CairoType.fromSol(elementT, this.ast).width;
const elementTSize = CairoType.fromSol(elementT, this.ast).width;

const [readElement, readFunc] = this.readMemory(elementT, 'elem_loc');
const [headEncodingCode, functionsCalled] = this.generateEncodingCode(
Expand All @@ -308,7 +308,7 @@ export class AbiEncode extends AbiBase {
` return (final_offset=bytes_offset);`,
` }`,
` let (index256) = felt_to_uint256(index);`,
` let (elem_loc) = wm_index_dyn(mem_ptr, index256, ${uint256(elemntTSize)});`,
` let (elem_loc) = wm_index_dyn(mem_ptr, index256, ${uint256(elementTSize)});`,
` let (elem) = ${readElement};`,
` ${headEncodingCode}`,
` return ${name}(new_bytes_index, new_bytes_offset, bytes_array, element_offset, index + 1, length, mem_ptr);`,
Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/abi/abiEncodePacked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const IMPLICITS =
'{bitwise_ptr : BitwiseBuiltin*, range_check_ptr : felt, warp_memory : DictAccess*}';

/**
* Given any data type produces the same output of solidty abi.encodePacked
* Given any data type produces the same output of solidity abi.encodePacked
* in the form of an array of felts where each element represents a byte
*/
export class AbiEncodePacked extends AbiBase {
Expand Down
4 changes: 2 additions & 2 deletions src/cairoUtilFuncGen/abi/indexEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class IndexEncode extends AbiBase {
if (existing !== undefined) return existing;

const elementT = getElementType(type);
const elemntTSize = CairoType.fromSol(elementT, this.ast).width;
const elementTSize = CairoType.fromSol(elementT, this.ast).width;

const [readElement, readFunc] = this.readMemory(elementT, 'elem_loc');
const [headEncodingCode, functionsCalled] = this.generateEncodingCode(
Expand All @@ -264,7 +264,7 @@ export class IndexEncode extends AbiBase {
` return (final_index=bytes_index);`,
` }`,
` let (index256) = felt_to_uint256(index);`,
` let (elem_loc) = wm_index_dyn(mem_ptr, index256, ${uint256(elemntTSize)});`,
` let (elem_loc) = wm_index_dyn(mem_ptr, index256, ${uint256(elementTSize)});`,
` let (elem) = ${readElement};`,
` ${headEncodingCode}`,
` return ${name}(bytes_index, bytes_array, index + 1, length, mem_ptr);`,
Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/calldata/calldataToStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class CalldataToStorageGen extends StringIndexedFuncGen {
return { name: funcName, code: code, functionsCalled: funcsCalled };
}

// TODO: Check if funcion size can be reduced for big static arrays
// TODO: Check if function size can be reduced for big static arrays
private createStaticArrayCopyFunction(arrayType: ArrayType): GeneratedFunctionInfo {
assert(arrayType.size !== undefined);

Expand Down
16 changes: 8 additions & 8 deletions src/cairoUtilFuncGen/calldata/implicitArrayConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class ImplicitArrayConversion extends StringIndexedFuncGen {
TypeConversionContext.CallDataRef,
);

const [copyInstructions, requiredFunctions] = this.createDyamicToDynamicCopyCode(
const [copyInstructions, requiredFunctions] = this.createDynamicToDynamicCopyCode(
targetType,
sourceType,
);
Expand Down Expand Up @@ -302,17 +302,17 @@ export class ImplicitArrayConversion extends StringIndexedFuncGen {
];
}
if (targetElementT.signed) {
const convertionFunc = this.requireImport(
const conversionFunc = this.requireImport(
'warplib.maths.int_conversions',
`warp_int${sourceElementT.nBits}_to_int${targetElementT.nBits}`,
);
return [
(index, offset) =>
[
` let (arg_${index}) = ${convertionFunc.name}(arg[${index}]);`,
` let (arg_${index}) = ${conversionFunc.name}(arg[${index}]);`,
` ${writeToStorage.name}(${add('storage_loc', offset)}, arg_${index});`,
].join('\n'),
[writeToStorage, convertionFunc],
[writeToStorage, conversionFunc],
];
}
const toUintFunc = this.requireImport('warplib.maths.utils', 'felt_to_uint256');
Expand Down Expand Up @@ -476,7 +476,7 @@ export class ImplicitArrayConversion extends StringIndexedFuncGen {
];
}

private createDyamicToDynamicCopyCode(
private createDynamicToDynamicCopyCode(
targetType: ArrayType,
sourceType: ArrayType,
): [() => string, CairoFunctionDefinition[]] {
Expand All @@ -487,7 +487,7 @@ export class ImplicitArrayConversion extends StringIndexedFuncGen {

if (targetElmType instanceof IntType) {
assert(sourceElmType instanceof IntType);
const convertionFunc = targetElmType.signed
const conversionFunc = targetElmType.signed
? this.requireImport(
'warplib.maths.int_conversions',
`warp_int${sourceElmType.nBits}_to_int${targetElmType.nBits}`,
Expand All @@ -497,11 +497,11 @@ export class ImplicitArrayConversion extends StringIndexedFuncGen {
() =>
[
sourceElmType.signed
? ` let (val) = ${convertionFunc.name}(ptr[0]);`
? ` let (val) = ${conversionFunc.name}(ptr[0]);`
: ` let (val) = felt_to_uint256(ptr[0]);`,
` ${writeDef.name}(storage_loc, val);`,
].join('\n'),
[writeDef, convertionFunc],
[writeDef, conversionFunc],
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/cairoUtilFuncGen/enumInputCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export class EnumInputCheck extends StringIndexedFuncGen {
assert(inputType instanceof IntType);

const key = enumDef.name + (inputType.nBits === 256 ? '256' : '');
const exisiting = this.generatedFunctionsDef.get(key);
if (exisiting !== undefined) {
return exisiting;
const existing = this.generatedFunctionsDef.get(key);
if (existing !== undefined) {
return existing;
}

const funcInfo = this.getOrCreate(inputType, enumDef);
Expand Down
10 changes: 5 additions & 5 deletions src/cairoUtilFuncGen/memory/implicitConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MemoryImplicitConversionGen extends StringIndexedFuncGen {
super(ast, sourceUnit);
}

public genIfNecesary(sourceExpression: Expression, targetType: TypeNode): [Expression, boolean] {
public genIfNecessary(sourceExpression: Expression, targetType: TypeNode): [Expression, boolean] {
const sourceType = safeGetNodeType(sourceExpression, this.ast.inference);

const generalTarget = generalizeType(targetType)[0];
Expand Down Expand Up @@ -460,10 +460,10 @@ export class MemoryImplicitConversionGen extends StringIndexedFuncGen {
}

export function getBaseType(type: TypeNode): TypeNode {
const deferencedType = generalizeType(type)[0];
return deferencedType instanceof ArrayType
? getBaseType(deferencedType.elementT)
: deferencedType;
const dereferencedType = generalizeType(type)[0];
return dereferencedType instanceof ArrayType
? getBaseType(dereferencedType.elementT)
: dereferencedType;
}

function typesToCairoTypes(
Expand Down
10 changes: 5 additions & 5 deletions src/cairoUtilFuncGen/storage/dynArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class DynArrayGen extends StringIndexedFuncGen {
const cairoType = CairoType.fromSol(type, this.ast, TypeConversionContext.StorageAllocation);

const key = cairoType.fullStringRepresentation;
const lenghtKey = key + '_LENGTH';
const lengthKey = key + '_LENGTH';
const existing = this.generatedFunctionsDef.get(key);
if (existing !== undefined) {
const exsitingLength = this.generatedFunctionsDef.get(lenghtKey);
assert(exsitingLength !== undefined);
return [existing, exsitingLength];
const existingLength = this.generatedFunctionsDef.get(lengthKey);
assert(existingLength !== undefined);
return [existing, existingLength];
}

const [arrayInfo, lengthInfo] = this.getOrCreate(cairoType);
Expand Down Expand Up @@ -70,7 +70,7 @@ export class DynArrayGen extends StringIndexedFuncGen {
);

this.generatedFunctionsDef.set(key, dynArray);
this.generatedFunctionsDef.set(lenghtKey, dynArrayLength);
this.generatedFunctionsDef.set(lengthKey, dynArrayLength);
return [dynArray, dynArrayLength];
}

Expand Down
8 changes: 4 additions & 4 deletions src/cairoUtilFuncGen/storage/mappingIndexAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CairoUtilFuncGenBase, GeneratedFunctionInfo, locationIfComplexType } fr
import { DynArrayGen } from './dynArray';

export class MappingIndexAccessGen extends CairoUtilFuncGenBase {
private indexAccesFunctions = new Map<string, CairoFunctionDefinition>();
private indexAccessFunctions = new Map<string, CairoFunctionDefinition>();
private stringHashFunctions = new Map<string, CairoFunctionDefinition>();
constructor(private dynArrayGen: DynArrayGen, ast: AST, sourceUnit: SourceUnit) {
super(ast, sourceUnit);
Expand Down Expand Up @@ -67,7 +67,7 @@ export class MappingIndexAccessGen extends CairoUtilFuncGenBase {
TypeConversionContext.StorageAllocation,
).fullStringRepresentation;
const key = indexKey + '-' + nodeKey;
const existing = this.indexAccesFunctions.get(key);
const existing = this.indexAccessFunctions.get(key);
if (existing !== undefined) {
return existing;
}
Expand All @@ -93,7 +93,7 @@ export class MappingIndexAccessGen extends CairoUtilFuncGenBase {
this.ast,
this.sourceUnit,
);
this.indexAccesFunctions.set(key, funcDef);
this.indexAccessFunctions.set(key, funcDef);
return funcDef;
}

Expand All @@ -105,7 +105,7 @@ export class MappingIndexAccessGen extends CairoUtilFuncGenBase {
TypeConversionContext.StorageAllocation,
);

const identifier = this.indexAccesFunctions.size;
const identifier = this.indexAccessFunctions.size;
const funcName = `WS_INDEX_${indexCairoType.typeName}_to_${valueCairoType.typeName}${identifier}`;
const mappingName = `WARP_MAPPING${identifier}`;
const indexTypeString = indexCairoType.toString();
Expand Down
6 changes: 3 additions & 3 deletions src/cairoUtilFuncGen/storage/storageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class StorageDeleteGen extends StringIndexedFuncGen {
// }
private creatingFunctions: Map<string, string>;

// Map to store unsolved function dependecies
// Map to store unsolved function dependencies
// of generated functions
private functionDependencies: Map<string, string[]>;

Expand Down Expand Up @@ -216,7 +216,7 @@ export class StorageDeleteGen extends StringIndexedFuncGen {
this.creatingFunctions.set(generateKey(type), funcName);

const elementT = generalizeType(type.elementT)[0];
const elementTWidht = CairoType.fromSol(
const elementTWidth = CairoType.fromSol(
elementT,
this.ast,
TypeConversionContext.StorageAllocation,
Expand All @@ -229,7 +229,7 @@ export class StorageDeleteGen extends StringIndexedFuncGen {
? [` let (elem_id) = ${storageReadFunc.name}(loc);`, ` ${auxDeleteFuncName}(elem_id);`]
: [` ${auxDeleteFuncName}(loc);`];
const length = narrowBigIntSafe(type.size);
const nextLoc = add('loc', elementTWidht);
const nextLoc = add('loc', elementTWidth);

const deleteFunc = [
`func ${funcName}_elem${IMPLICITS}(loc : felt, index : felt){`,
Expand Down
4 changes: 2 additions & 2 deletions src/cairoUtilFuncGen/storage/storageToCalldata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class StorageToCalldataGen extends StringIndexedFuncGen {
assert(structDef instanceof CairoDynArray);

const storageReadFunc = this.storageReadGen.getOrCreateFuncDef(elementT);
const sturctDynArray = this.externalDynArrayStructConstructor.getOrCreateFuncDef(arrayType);
const structDynArray = this.externalDynArrayStructConstructor.getOrCreateFuncDef(arrayType);
const [dynArray, dynArrayLength] = this.dynArrayGen.getOrCreateFuncDef(elementT);

const arrayName = dynArray.name;
Expand Down Expand Up @@ -201,7 +201,7 @@ export class StorageToCalldataGen extends StringIndexedFuncGen {
code: code,
functionsCalled: [
...importedFuncs,
sturctDynArray,
structDynArray,
dynArray,
dynArrayLength,
storageReadFunc,
Expand Down
2 changes: 1 addition & 1 deletion src/cairoUtilFuncGen/storage/storageToMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class StorageToMemoryGen extends StringIndexedFuncGen {
];
}
throw new TranspileFailedError(
`Trying to create recursive code for unsupported referency type: ${printTypeNode(
`Trying to create recursive code for unsupported reference type: ${printTypeNode(
elementT,
)}`,
);
Expand Down
Loading